Hibernate web application with MySQL failover

浪子不回头ぞ 提交于 2019-12-14 01:26:36

问题


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.

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:

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&amp;loadBalanceBlacklistTimeout=7000&amp;autoReconnect=true&amp;failOverReadOnly=false&amp;roundRobinLoadBalance=true</property>

While looking at the MySQL connector documentation, I've tried many properties configurations, but cannot figure out how to obtain a reliable failover.


回答1:


Same issue for me : https://dba.stackexchange.com/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 :

  • Failover on MySQL JDBC connections?
  • How to use database as backup/failover in hibernate?


来源:https://stackoverflow.com/questions/12385079/hibernate-web-application-with-mysql-failover

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