简体   繁体   English

从MySql迁移:MariaDB服务器意外关闭客户端连接

[英]Migrating from MySql: MariaDB server closing client connections unexpectedly

We in the process of migrating from MySql to MariaDB due to licensing/commercial usage reasons. 由于许可/商业使用原因,我们正在从MySql迁移到MariaDB。

We have successfully replaced the MySql connector jar with MariaDB client jar (first change) and are now trying to replace MySql server with MariaDB server without changing the data files. 我们已经成功地用MariaDB客户端jar替换了MySql连接器jar(第一次更改),现在尝试用MariaDB服务器替换MySql服务器而不更改数据文件。

All our applications run perfectly for about 8-12 hours after which we see the following exception: 我们所有的应用程序运行完美约8-12小时,之后我们看到以下异常:


org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection
Caused by:
org.hibernate.exception.JDBCConnectionException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:494)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:315)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:257)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
        at $Proxy4.getMessageCountByStatus(Unknown Source)
        at com.onmobile.cmfweb.monitoring.CmfMessagesMonitor.getMessageCounts(CmfMessagesMonitor.java:56)
        at sun.reflect.GeneratedMethodAccessor625.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:270)
        at com.onmobile.cmfshare.MethodInvockingBean.invoke(MethodInvockingBean.java:28)
        at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:212)
        at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:79)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to localhost:3306: unexpected end of stream, read 0bytes from 4
        at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
        at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
        at org.mariadb.jdbc.Driver.connect(Driver.java:114)
        at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
        at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
        at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
        at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:544)
        at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
        ... 21 more
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not connect to localhost:3306: unexpected end of stream, read 0bytes from 4
        at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:509)
        at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:669)
        at org.mariadb.jdbc.internal.mysql.MySQLProtocol.<init>(MySQLProtocol.java:264)
        at org.mariadb.jdbc.Driver.connect(Driver.java:110)
        ... 28 more
Caused by: java.io.EOFException: unexpected end of stream, read 0bytes from 4
        at org.mariadb.jdbc.internal.common.packet.buffer.ReadUtil.readFully(ReadUtil.java:84)
        at org.mariadb.jdbc.internal.common.packet.buffer.ReadUtil.readFully(ReadUtil.java:92)
        at org.mariadb.jdbc.internal.common.packet.RawPacket.nextPacket(RawPacket.java:77)
        at org.mariadb.jdbc.internal.common.packet.SyncPacketFetcher.getRawPacket(SyncPacketFetcher.java:67)
        at org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:467)
        ... 31 more

The exceptions disappear if MySql server is used again. 如果再次使用MySql服务器,则异常消失。

From what I have debugged so far MariaDB server is closing the client connections for some reason. 从我调试到目前为止,MariaDB服务器由于某种原因正在关闭客户端连接。 I initially suspected of idle connections but we are using Hibernate configurations like 'testOnBorrow' so it shouldn't be the case. 我最初怀疑是空闲连接但我们正在使用像'testOnBorrow'这样的Hibernate配置,所以不应该这样。

Can anyone help us to find out the cause for this and help us fix the problem? 任何人都可以帮助我们找出原因并帮助我们解决问题吗? Is there any specific configuration in MariaDB that I should be doing? 我应该在MariaDB中进行任何特定配置吗?

I've even run our applications by increasing the value of the param 'interactive_timeout' in the MariaDB server but it did not help. 我甚至通过增加MariaDB服务器中param'interactive_timeout'的值来运行我们的应用程序,但它没有帮助。

Btw, we are using Spring-Hibernate and pooling our connections using Commons-pool jar. 顺便说一句,我们正在使用Spring-Hibernate并使用Commons-pool jar汇集我们的连接。

Any kind of help will be deeply appreciated. 任何形式的帮助将深表感谢。

We encountered the same problem recently, due to a combination of incorrect parameters. 由于参数不正确,我们最近遇到了同样的问题。 This error is caused by your web instance trying to use a connection that is no longer a valid one. 此错误是由您的Web实例尝试使用不再有效的连接引起的。

This can be resolved by making sure the following parameters are correct: 这可以通过确保以下参数正确来解决:

  1. You have a validationQuery configured for your database connection. 您已为数据库连接配置了validationQuery。 ie validationQuery="SELECT 1" in case of mariadb, in the server configuration. 即,在mariadb的情况下,在服务器配置中, validationQuery="SELECT 1"
  2. You have the wait_timeout set to a reasonable value. 您将wait_timeout设置为合理的值。 8 hours keepAlive seems a bit optimistic, we are now using wait_timeout=180 8小时keepAlive似乎有点乐观,我们现在使用wait_timeout=180
  3. Make sure the validationInterval, which you can also set in the server configuration (server.xml in case of a tomcat setup), is set to a value that is lower than the wait_timeout value. 确保您还可以在服务器配置中设置的validationInterval(在tomcat设置的情况下为server.xml)设置为低于wait_timeout值的值。 I reduced the wait_timeout to 15s in one case, with the validationInterval value being higher than that, which caused the error to still appear at times. 在一种情况下,我将wait_timeout减少到15秒,其中validationInterval值高于该值,这导致错误仍然有时出现。 Now it is set to validationInterval=60 , combined with the wait_timeout=180 which should catch any broken connections in time. 现在将它设置为validationInterval=60 ,并结合wait_timeout=180 ,它应该及时捕获任何断开的连接。

You can try to increase 'wait_timeout' instead of 'interactive_timeout'. 您可以尝试增加'wait_timeout'而不是'interactive_timeout'。 8-12 hours until error correlates quite well with the default value of wait_timeout which is 10 hours. 8-12小时,直到错误与wait_timeout的默认值10小时相关。 JDBC driver does not set interactive client flag when connecting, so change to 'interactive_timeout' might have no effect. JDBC驱动程序在连接时不设置交互式客户端标志,因此更改为“interactive_timeout”可能无效。 I also replied to the cross-post in Maria KB ;) 我还回复了Maria KB的交叉帖子;)

I also had an error like this one Could not connect to localhost:3306: unexpected end of stream, read 0 bytes from 4 我也有一个像这样的错误Could not connect to localhost:3306: unexpected end of stream, read 0 bytes from 4

My architecture was an webapp of Tomcat that was inserting data into MariaDB. 我的架构是Tomcat的webapp,它将数据插入MariaDB。

I was using the connector version 1.5.1RC ! 我使用的是连接器版本1.5.1RC I switched to the 1.3.1 connector version and now runs fine! 我切换到1.3.1连接器版本 ,现在运行正常!

I also faced this issue. 我也遇到过这个问题。 The issue goes away with lowering the wait_timeout. 问题随着降低wait_timeout而消失。

SHOW SESSION VARIABLES LIKE 'wait_timeout'; ->> would be 8 hours. which is huge.
SET session wait_timeout=300; ->> this should fix the issue.

Look at 看着

SHOW VARIABLES LIKE 'max_connections';
SHOW GLOBAL STATUS LIKE '%connect%';

Compare the my.cnf values between the two systems; 比较两个系统之间的my.cnf值; you may see a difference in things like above that make a difference. 你可能会发现像上面这样的东西有所不同。 If the problem is still not obvious, please provide those values for further discussion. 如果问题仍然不明显,请提供这些值以供进一步讨论。

According to the findings in this article you could get away with two options: 根据本文的调查结果,您可以选择两种方法:

  1. You should try turning innodb_file_per_table off 您应该尝试关闭innodb_file_per_table

    or... 要么...

  2. Increasing the open file limits, this tells you the current value on yout machine $ ulimit -n , should you be running on high spec machines 增加打开文件限制,如果你在高规格机器上运行,这会告诉你机器$ ulimit -n上的当前值

I think that the problem is with MariaDB Connector/J. 我认为问题出在MariaDB Connector / J上。 Try to use a stable one like MariaDB Connector/J 1.2.3 for example. 尝试使用像MariaDB Connector / J 1.2.3这样的稳定​​版本。 Also, study Failover behaviour with Basic failover when autoReconnect is set to true or Standard failover. 此外,当autoReconnect设置为true或标准故障转移时,请研究使用基本故障转移的故障转移行为

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM