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

…衆ロ難τιáo~ 提交于 2019-12-07 02:35:47

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/20503612/rails-octopus-gem-master-slave-replication-connection-behaviour-when-slave-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!