Master slave replication jdbc url
We have a MySQL setup with one master and two slaves we use Spring 3.0 to connect to the DBs and mysql-connector-java-5.1.13.jar. We also use commons dbcp 1.4 for connection pooling.
We use the following jdbc url string:
jdbc:mysql:replication://[master_ip]:23306,[slave1_ip]:23306,[slave2_ip]:23306/wm_admin?autoReconnectForPools=true&roundRobinLoadBalance=true&loadBalanceBlacklistTimeout=5000&loadBalanceStrategy=random
The problem is that the application will not start if one of the slaves is down, or would halt if it's running and one of the slaves is down. Is there a problem with the url string, should it be setup differently 开发者_StackOverflow社区?
I noticed a similar problem when all slaves were dead. It may be solved with mysql-connector-5.1.38
And next parameters in url: jdbc:mysql:replication://[master_ip]:23306,[slave1_ip]:23306,[slave2_ip]:23306?connectTimeout=5000&socketTimeout=5000&retriesAllDown=3&allowMasterDownConnections=true&allowSlaveDownConnections=true&loadBalanceBlacklistTimeout=10000&readFromMasterWhenNoSlaves=true
Also, if you don't afraid readonly queries on master - you can add master to slaves list: jdbc:mysql:replication://[master_ip]:23306,[master_ip]:23306,[slave1_ip]:23306,[slave2_ip]:23306
So you won't meet case with "all slaves dead".
Maybe a solution from the documentation :
if you want to allow connection to a master when no slaves are available, set the property readFromMasterWhenNoSlaves to “true.”
精彩评论