flink-cdc
flink-cdc copied to clipboard
[mysql]Fix jdbc connections not be closed when job was cancelled (#1347)
[mysql]Fix jdbc connections not be closed when job was cancelled (#1347)
@leonardBang Hi leonard I don't konw why mysql cdc connector use a connection pool, other connector's connection are created through the DriverManger, can you tell me why? Thanks.
In this issue we can't close connection pool directly, the JdbcConnectionPools
is a constant, it's used by all jobs in current jvm, I think we can put the pools
to a ThreadLocal
we can close the connection pool used by current Thread. And the connection poll not only used by MySqlSourceEnumerator
,other place like JdbcRowDataInputFormat
, JdbcOutputFormat
, MySqlValidator
use it as well.
Thank you for your reply, I understand, will someone solve this, or should I try to solve it and resubmit this pr? @Matrix42
I'am not the Maintainer of this repository , I think you can ask the opinion of leonardBang @xuexiaowengh
Hello,Matrix42,I just tested it and found that this statement may not be true:
“the JdbcConnectionPools is a constant, it's used by all jobs in current jvm”
When I started two FlinkCDC jobs to read the same table, and then cancelled the two jobs in turn, I found that pools were not the same:
so I think pools are not shared by all jobs in the JVM, or do you have another way to test the problem? @Matrix42
Hi xuexiaowengh, the JdbcConnectionPools
is singleton instance and thread safe, if in the same jvm it'll only have one instance, so if your job run with same taskmanger it must use the same JdbcConnectionPools
.
I'v tested it using a simple way, tow thread in the same jvm get the JdbcConnectionPools
,i got the same hash code.
Two slots in a taskmanger just like two thread in a jvm
@xuexiaowengh
Thx, Matrix42, I can see why there are two different pools in my test result because I used datastream API and included flink-connector-mysql-cdc when packing job jar. This results in a separate JdbcConnectionPools for each job; When I put flink-connector-mysql-cdc into FLINK_HOME/lib/ to test again, I can see that the two job closures are the same pools. Thank you for your previous reply. @Matrix42
@xuexiaowengh I close the PR after read your discussion.
谢谢,Matrix42,我明明为什么我的测试结果中有两个不同的池,因为我在打包作业jar时使用了数据流API并包含了flink-connector-mysql-cdc 。这导致每个作业都有一个单独的JdbcConnectionPools;当我将flink-connector-mysql-cdc放入FLINK_HOME/lib/ 再次测试时,可以看到这两个工作屏蔽包是同一个池。谢谢您之前的回复。@Matrix42
你好,我试了把flink-connector-mysql-cdc放入FLINK_HOME/lib/ ,但是JdbcConnectionPools不同的作业还不不共享,是需要注意什么吗