ClickHouse server version 21.12.2
驱动版本:0.2.4
flink任务读取kafka消息,处理,JDBC方式写入到clickhouse。开始运行时可以写入个几万条,过30分钟左右报错。
Caused by: ru.yandex.clickhouse.except.ClickHouseUnknownException: ClickHouse exception, code: 1002, host: 192.168.66.66, port: 8123; 192.168.66.66:8123 failed to respond
Cause: ru.yandex.clickhouse.except.ClickHouseUnknownException: ClickHouse exception, code: 1002, host: 192.168.66.66, port: 8123; 192.168.66.66:8123 failed to respond
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:153) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86) ~[sale-1.0-SNAPSHOT.jar:?]
at com.sun.proxy.$Proxy34.insert(Unknown Source) ~[?:?]
at com.tanjiu.realtime.common.func.ClickhouseSink.invoke(ClickhouseSink.java:52) ~[sale-1.0-SNAPSHOT.jar:?]
at com.tanjiu.realtime.common.func.ClickhouseSink.invoke(ClickhouseSink.java:18) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.StreamSink.processElement(StreamSink.java:56) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:71) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:46) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:26) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.CountingOutput.collect(CountingOutput.java:52) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.CountingOutput.collect(CountingOutput.java:30) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.StreamMap.processElement(StreamMap.java:41) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.pushToOperator(CopyingChainingOutput.java:71) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:46) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.CopyingChainingOutput.collect(CopyingChainingOutput.java:26) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.TimestampedCollector.collect(TimestampedCollector.java:53) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.async.queue.StreamRecordQueueEntry.emitResult(StreamRecordQueueEntry.java:65) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.async.queue.UnorderedStreamElementQueue$Segment.emitCompleted(UnorderedStreamElementQueue.java:263) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.async.queue.UnorderedStreamElementQueue.emitCompletedElement(UnorderedStreamElementQueue.java:150) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.async.AsyncWaitOperator.outputCompletedElement(AsyncWaitOperator.java:280) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.async.AsyncWaitOperator.access$100(AsyncWaitOperator.java:78) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.async.AsyncWaitOperator$ResultHandler.processResults(AsyncWaitOperator.java:352) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.api.operators.async.AsyncWaitOperator$ResultHandler.lambda$processInMailbox$0(AsyncWaitOperator.java:337) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.StreamTaskActionExecutor$1.runThrowing(StreamTaskActionExecutor.java:47) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.mailbox.Mail.run(Mail.java:78) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.mailbox.MailboxProcessor.processMail(MailboxProcessor.java:283) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.mailbox.MailboxProcessor.runMailboxLoop(MailboxProcessor.java:184) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.StreamTask.runMailboxLoop(StreamTask.java:575) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:539) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.runtime.taskmanager.Task.doRun(Task.java:722) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:547) ~[sale-1.0-SNAPSHOT.jar:?]
at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_181]
Caused by: ru.yandex.clickhouse.except.ClickHouseUnknownException: ClickHouse exception, code: 1002, host: 192.168.66.66, port: 8123; 192.168.66.66:8123 failed to respond
at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.getException(ClickHouseExceptionSpecifier.java:91) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:55) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.except.ClickHouseExceptionSpecifier.specify(ClickHouseExceptionSpecifier.java:24) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.getInputStream(ClickHouseStatementImpl.java:633) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:117) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:100) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:95) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:90) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.execute(ClickHouseStatementImpl.java:226) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHousePreparedStatementImpl.execute(ClickHousePreparedStatementImpl.java:105) ~[sale-1.0-SNAPSHOT.jar:?]
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) ~[sale-1.0-SNAPSHOT.jar:?]
... 36 more
Caused by: org.apache.http.NoHttpResponseException: 192.168.66.66:8123 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.getInputStream(ClickHouseStatementImpl.java:614) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:117) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:100) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:95) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.executeQuery(ClickHouseStatementImpl.java:90) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHouseStatementImpl.execute(ClickHouseStatementImpl.java:226) ~[sale-1.0-SNAPSHOT.jar:?]
at ru.yandex.clickhouse.ClickHousePreparedStatementImpl.execute(ClickHousePreparedStatementImpl.java:105) ~[sale-1.0-SNAPSHOT.jar:?]
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) ~[sale-1.0-SNAPSHOT.jar:?]
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) ~[sale-1.0-SNAPSHOT.jar:?]
... 36 more
搜索发现有几个相关的已经是closed状态的bug,那应该是可以通过改配置或包的方式解决。
<dependency>
<groupId>ru.yandex.clickhousegroupId>
<artifactId>clickhouse-jdbcartifactId>
<version>0.3.1-patchversion>
dependency>
改完后报错仍旧出现,看来和驱动包相关性不大
这里我用druid连的clickhouse,尝试调整一下参数
DruidDataSource druidDataSource = new DruidDataSource();
//Setting up driver
druidDataSource.setDriverClassName("ru.yandex.clickhouse.ClickHouseDriver");
druidDataSource.setUrl(url);
druidDataSource.setUsername(user);
druidDataSource.setPassword(password);
// 解决 failed to respond 问题
druidDataSource.setInitialSize(1);
druidDataSource.setMaxActive(2);
druidDataSource.setMaxWait(6000);
druidDataSource.setMinIdle(12);
druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
druidDataSource.setValidationQuery("select 1");
druidDataSource.setMinEvictableIdleTimeMillis(300000);
druidDataSource.setMaxEvictableIdleTimeMillis(900000);
druidDataSource.setTestWhileIdle(true);
druidDataSource.setTestOnBorrow(false);
druidDataSource.setTestOnReturn(false);
druidDataSource.setKeepAlive(true);
druidDataSource.setPoolPreparedStatements(true);
druidDataSource.setMaxOpenPreparedStatements(20);
druidDataSource.setAsyncInit(true);
依旧报错
# pwd
/etc/clickhouse-server
# ls
config.d config.xml metrika.xml users.d users.xml
# vim config.xml
查看连接超时时间的配置,发现配置是3
查看 官方文档 发现官方默认参数是10,这里修改为30
修改完目前已经可以正常写入,3天未出现报错,问题基本解决。
当前获取连接的流程
找资料的时候偶然看到这位大佬的话
突然想到自己获取连接的方式,可能需要处理一下。或许可以尝试每次都获取新连接,用完后则立刻关闭,不再缓存。
官方文档
Clickhouse错误问题汇总
ClickHouse到底该写本地表还是分布式表