flume-ng-sql-source读取数据库延迟8小时以上报错

https://github.com/keedio/flume-ng-sql-source这个项目读取数据库的时候run.query.delay设置的时间过长,导致java.sql.SQLRecoverableException报错,

MySql默认一个connection(连接)空闲超过8小时自动断开,而程序认为这个连接还是可用的,这个时候用这个过时connection去连接MySql时就会报这个错误,oracle也有这个问题,

SQL Error: 17002, SQLState: 08006
2019/07/30 10:28:57,095
IO Error: Connection timed out
2019/07/30 10:28:57,095
[c3p0] A PooledConnection that has already signalled a Connection error is still in use!
2019/07/30 10:28:57,095
[c3p0] Another error has occurred [ java.sql.SQLRecoverableException: Closed Connection ] which will not be reported to listeners!
java.sql.SQLRecoverableException: Closed Connection
        at oracle.jdbc.driver.PhysicalConnection.getAutoCommit(PhysicalConnection.java:1828)
        at com.mchange.v2.c3p0.impl.NewProxyConnection.getAutoCommit(NewProxyConnection.java:938)
        at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.isAutoCommit(LogicalConnectionImpl.java:322)
        at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.afterNonTransactionalQuery(TransactionCoordinatorImpl.java:199)
        at org.hibernate.internal.SessionImpl.afterOperation(SessionImpl.java:503)
        at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1916)
        at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)
        at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)
        at org.keedio.flume.source.HibernateHelper.executeQuery(HibernateHelper.java:122)
        at org.keedio.flume.source.DBSQLSource.process(DBSQLSource.java:102)
        at org.apache.flume.source.PollableSourceRunner$PollingRunner.run(PollableSourceRunner.java:129)
        at java.lang.Thread.run(Thread.java:748)
2019/07/30 10:28:57,096
SQL Error: 17008, SQLState: 08003
2019/07/30 10:28:57,096
Closed Connection
2019/07/30 10:28:57,096
Exception thrown, resetting connection.
org.hibernate.exception.JDBCConnectionException: could not inspect JDBC autocommit mode
        at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
        at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.isAutoCommit(LogicalConnectionImpl.java:325)
        at 

问题一:这么解决?

c3p0里有一个配置maxIdleTime默认是0将这个配置设置的比数据库里自动断开连接的时间短就好了。


<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime">60</property>

问题二:这个项目里用的hibernate-c3p0没有提供那个设置的入口

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>4.3.10.Final</version>
        </dependency>
agent.sources.sqlSource.hibernate.connection.provider_class = org.hibernate.connection.C3P0ConnectionProvider

 hibernate配置如下

#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.idle_test_period 3000
#hibernate.c3p0.acquire_increment 2
#hibernate.c3p0.validate false

 配置里指定了C3P0ConnectionProvider 这个类那就只能看这个代码了,在这个位置

第113行发现hibernate是用timeout这个参数替换了c3p0的maxIdleTime这个名字,所以设置下hibernate.c3p0.timeout的值就好了。

 

在网上发现很多人都说hibernate.c3p0.timeout这个是获得连接的超时时间,如果超过这个时间,会抛出异常,单位秒,是错误的

最后竟然发现百度百科里错了 https://baike.baidu.com/item/c3p0/3719378?fr=aladdin

在官方文档里找到了,准确的信息 https://www.mchange.com/projects/c3p0/index.html#hibernate-specific

这两个是对应的 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值