具有MySQL故障转移的Hibernate Web应用程序 [英] Hibernate web application with MySQL failover

查看:88
本文介绍了具有MySQL故障转移的Hibernate Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个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&amp;loadBalanceBlacklistTimeout=7000&amp;autoReconnect=true&amp;failOverReadOnly=false&amp;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.

推荐答案

对我来说是同样的问题:

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?

这篇关于具有MySQL故障转移的Hibernate Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆