22

We in the process of migrating from MySql to MariaDB due to licensing/commercial usage reasons.

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.

All our applications run perfectly for about 8-12 hours after which we see the following exception:


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.

From what I have debugged so far MariaDB server is closing the client connections for some reason. I initially suspected of idle connections but we are using Hibernate configurations like 'testOnBorrow' so it shouldn't be the case.

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?

I've even run our applications by increasing the value of the param 'interactive_timeout' in the MariaDB server but it did not help.

Btw, we are using Spring-Hibernate and pooling our connections using Commons-pool jar.

Any kind of help will be deeply appreciated.

4

7 回答 7

7

由于参数组合不正确,我们最近遇到了同样的问题。此错误是由您的 Web 实例尝试使用不再有效的连接引起的。

这可以通过确保以下参数正确来解决:

  1. 您为数据库连接配置了一个验证查询。即validationQuery="SELECT 1"在mariadb 的情况下,在服务器配置中。
  2. 您将 wait_timeout 设置为合理的值。8小时keepAlive好像有点乐观,我们现在用wait_timeout=180
  3. 确保validationInterval(您也可以在服务器配置中设置(如果是tomcat 设置,则为server.xml))设置为低于wait_timeout 值的值。在一种情况下,我将 wait_timeout 减少到 15 秒,validationInterval 值高于此值,这导致错误有时仍然出现。现在它设置为validationInterval=60,与wait_timeout=180which 应及时捕获任何断开的连接相结合。
于 2015-10-23T16:55:05.093 回答
1

您可以尝试增加“wait_timeout”而不是“interactive_timeout”。8-12 小时直到错误与 wait_timeout 的默认值(10 小时)非常相关。JDBC 驱动程序在连接时未设置交互式客户端标志,因此更改为“interactive_timeout”可能无效。我还回复了 Maria KB 中的交叉帖子;)

于 2013-09-16T08:38:43.540 回答
1

我也有这样的错误Could not connect to localhost:3306: unexpected end of stream, read 0 bytes from 4

我的架构是一个将数据插入 MariaDB 的 Tomcat 网络应用程序。

我使用的是连接器版本 1.5.1RC!我切换到1.3.1 连接器版本,现在运行良好!

于 2017-01-13T14:54:32.513 回答
1

我也遇到过这个问题。降低 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.
于 2018-08-28T07:30:07.393 回答
0

根据本文中的发现,您可以有两种选择:

  1. 您应该尝试innodb_file_per_table关闭

    或者...

  2. $ ulimit -n如果您在高规格机器上运行,增加打开文件限制,这会告诉您机器上的当前值

于 2015-10-22T20:30:32.947 回答
0

我认为问题出在 MariaDB Connector/J 上。尝试使用像MariaDB Connector/J 1.2.3这样的稳定​​版本。此外,当autoReconnect设置为 true 或 Standard 故障转移时,使用基本故障转移研究故障转移行为。

于 2015-10-23T15:12:28.390 回答
0

看着

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

比较两个系统之间的 my.cnf 值;您可能会看到上述情况有所不同。如果问题仍然不明显,请提供这些值以供进一步讨论。

于 2015-10-20T17:20:26.273 回答