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!
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.