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!

Mauricio Moraes
  • 7,255
  • 5
  • 39
  • 59
  • 1
    I don't know about Octopus but Makara has slave failover https://github.com/taskrabbit/makara – Sam Dec 10 '13 at 19:42
  • @Mauricio - can you answer my question here http://stackoverflow.com/questions/29445495/rails-how-to-split-write-read-query-across-master-slave-database?noredirect=1#comment47064893_29445495 – Sanjay Salunkhe Apr 11 '15 at 06:05

1 Answers1

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.

SaschaM78
  • 4,376
  • 4
  • 33
  • 42
  • 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? – Mauricio Moraes Mar 05 '14 at 12:21
  • 2
    I haven't used it yet but SDP, [Seamless Database Pooling](https://github.com/wbharding/seamless_database_pool), seems to be exactly what you should be looking into. [This blog post](http://www.williambharding.com/blog/rails/rails-3-slave-database-options-there-are-two/) 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! – SaschaM78 Mar 05 '14 at 12:43