Rails Octopus Gem - Master-Slave Replication connection behaviour when slave is down
Asked Answered
C

1

6

I'm testing this great gem Octopus with Rails 4.0.2 in development.

I created a Slave db and configured octopus as follows (config>shards.yml):

octopus:
  environments:
    - development
  replicated: true
  fully_replicated: true 
  verify_connection: true
  development:
    slave1:
      host: 192.168.1.12
      adapter: mysql2
      username: slave_reader
      password: my_password
      database: my_server_development
      reconnect: true

It works very nice, reading from the Slave and writing to the Master, however if My Slave server is down, I would expect it to redirect to the Master db and get the content, but after some time trying, it throws the error:

Can't connect to MySQL server on '192.168.1.12' (113)

What can I do to make octopus look for my Master db if the Slave server is shutdown?

Thanks in advance!

Chincapin answered 10/12, 2013 at 19:35 Comment(2)
I don't know about Octopus but Makara has slave failover github.com/taskrabbit/makaraSoubriquet
@Mauricio - can you answer my question here #29445995Routinize
E
3

As I read in this blog post a powered-off or unresponsive slave may cause application failures because Octopus' default behavior is to write all data to the Master and read all data from the Slaves (as data written to the Master is than replicated to all connected Slaves). As stated on the Octopus wiki, "Multiple slaves" section reading in a multiple slave environment is done using round robin so it's always retrieving data from a slave per default.

Also taken from above mentioned blog: as a fallback mechanism you should read data from the Master directly (using .using(:master)) if none of the Slave nodes is available or data has not been fully replicated to the slaves yet. It may also be an option to cache changes/results application-wise to prevent repeated reads from the database nodes.

Eblis answered 5/3, 2014 at 7:31 Comment(2)
So the conclusion is that there's no configuration for the gem to do this automatically? Any substitute gem you have used has this slave failover feature?Chincapin
I haven't used it yet but SDP, Seamless Database Pooling, seems to be exactly what you should be looking into. This blog post compares Octopus to SDP and as a bottom line you will read that SDP was created because of the lack of failover functionality in Octopus. Thanks for accepting my answer!Eblis

© 2022 - 2024 — McMap. All rights reserved.