问题描述
我正在开发中的Rails 4.0.2测试这款出色的宝石八达通.
I'm testing this great gem Octopus with Rails 4.0.2 in development.
我创建了一个从数据库,并按如下配置了章鱼(config> shards.yml):
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
它工作得很好,可以从Slave读取并写入Master,但是,如果My Slave服务器关闭,我希望它重定向到Master db并获取内容,但是经过一段时间的尝试,它将抛出错误:
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:
如果从属服务器关闭,该如何使章鱼寻找我的主数据库?
What can I do to make octopus look for my Master db if the Slave server is shutdown?
提前谢谢!
推荐答案
我在中阅读此博客文章断电或没有响应的从服务器可能会导致应用程序失败,因为八达通的默认行为是将所有数据写入主服务器,并从从服务器读取所有数据(因为写入主服务器的数据将被复制到所有主机).已连接的从站).如 Octopus Wiki所述,多奴隶"部分在多奴隶环境中读取是使用循环机制完成,因此默认情况下始终总是从从属设备检索数据.
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.
也摘自上述博客:作为一种后备机制,如果没有可用的从节点或尚未将数据完全复制到从节点,则应直接从主节点读取数据(使用.using(:master)
).也可以选择按应用程序缓存更改/结果,以防止重复读取数据库节点.
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.
这篇关于Rails Octopus Gem-从属服务器关闭时的主从复制连接行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!