我开发了一个Java Web应用程序,使用Hibernate 3.3.2作为持久性框架,并使用Apache Tomcat 7.0.27作为服务器. 该应用程序已成功设置为使用MySQL 5.5 Replication Server:1个主服务器,1个从属服务器.只读查询将在后者上进行,而其他查询将在主实例上进行.
I developed a Java web application, using Hibernate 3.3.2 as persistence framework and Apache Tomcat 7.0.27 as server. This application was successfully set up to use MySQL 5.5 Replication Servers: 1 master, 1 slave. Read-only queries go on the latter and the others on the master instance.
问题就来了:我想测试数据库故障转移,即在某个时候停止MySQL的从属实例,并看到应用程序在只读查询中仍然可以正常工作.据我从以下文章中了解到使用Connector/J 的MySQL故障转移,应该无需更改代码即可.首先,我对第二种情况感兴趣:通信异常(SQL State以"08"开头). 不幸的是,这不会发生,如果我停止了从服务器,有时需要很长时间才能从服务器获得响应,有时没有返回,并且HTTP连接被卡住.在Tomcat日志中,只需获得以下行:
And here comes the problem: I would like to test DB failover, i.e. at some time stop the slave MySQL instance and see the application still work well with read-only queries. As far as I understood from the following article MySQL Failover with Connector/J, this should be possible with no changes to the code. To start I am interested in the 2nd case: A communication exception (SQL State starting with "08"). Unfortunately this does not happen, if I stop the slave, sometimes it takes a very long time to get a response from the server, sometimes none comes back and the HTTP connection becomes stuck. In the Tomcat log just get the following line:
从服务器成功接收到的最后一个数据包是在N毫秒前.成功发送到服务器的最后一个数据包是在0毫秒前.
The last packet successfully received from the server was N milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
以下是休眠配置的代码段:
Here is a snippet of hibernate configuration:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.ReplicationDriver</property> <property name="hibernate.connection.url">jdbc:mysql://masterIP,slaveIP/mydb?loadBalancePingTimeout=1500&loadBalanceBlacklistTimeout=7000&autoReconnect=true&failOverReadOnly=false&roundRobinLoadBalance=true</property>在查看MySQL连接器文档时,我尝试了许多属性配置,但无法弄清楚如何获得可靠的故障转移.
While looking at the MySQL connector documentation, I've tried many properties configurations, but cannot figure out how to obtain a reliable failover.
推荐答案对我来说是同样的问题: dba.stackexchange/questions/19453/jboss-dont-fail-over-mysql-slave-using-datasource .
Same issue for me : dba.stackexchange/questions/19453/jboss-dont-fail-over-mysql-slave-using-datasource.
它应该可以正常工作...但是我不知道如何...
It should work correctly ... but I don't know how ...
似乎很多人使用一些外部代理或负载平衡器:
It seems that many pepole use some externals proxies or load balancers :
- MySQL JDBC连接上的故障转移吗?
- 如何在休眠状态下将数据库用作备份/故障转移?
- Failover on MySQL JDBC connections?
- How to use database as backup/failover in hibernate?
更多推荐
具有MySQL故障转移的Hibernate Web应用程序
发布评论