flink-connector-jdbc icon indicating copy to clipboard operation
flink-connector-jdbc copied to clipboard

[FLINK-30371][Connector/JDBC] Fix the problem of JdbcOutputFormat database connection leak

Open EchoLee5 opened this issue 2 years ago • 10 comments

Fix the problem of JdbcOutputFormat database connection leak

EchoLee5 avatar Dec 13 '22 01:12 EchoLee5

Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html)

boring-cyborg[bot] avatar Dec 13 '22 01:12 boring-cyborg[bot]

@EchoLee5 Thanks for the PR, is it possible to add a test for this?

@MartijnVisser I have added test cases, please help me review the code again, thank you.

EchoLee5 avatar Dec 15 '22 05:12 EchoLee5

@EchoLee5 Can you please rebase and use the new testing setup?

MartijnVisser avatar May 24 '23 18:05 MartijnVisser

@MartijnVisser is there any update on this PR? I can also open a new PR with the fixes from @EchoLee5.

KevDi avatar Jul 27 '23 12:07 KevDi

connectionProvider is configured as final and is AutoClossable which can be used in try(connectionProvider) which handles the closeConnection automatically.

tamirsagi avatar Dec 03 '24 11:12 tamirsagi

@tamirsagi Is this fix still needed? Or the one i send in? #75 ?

KevDi avatar Dec 03 '24 18:12 KevDi

@tamirsagi Is this fix still needed? Or the one i send in? #75 ?

if you are asking whether its still relevant, then yes. yours is similar. yet, I'd wrap connectionProvider with try after calling #flush because it's cleaner & safer. + I don't see any reason to store an exception to flushException during #close.

tamirsagi avatar Dec 03 '24 18:12 tamirsagi

@tamirsagi it is basicly the same fix i asked on the Jira Board and they said i should open up a new PR thats why there are two :) what exactly do you mean by wrapping it? Do you have some example code?

KevDi avatar Dec 03 '24 18:12 KevDi

@tamirsagi it is basicly the same fix i asked on the Jira Board and they said i should open up a new PR thats why there are two :) what exactly do you mean by wrapping it? Do you have some example code?

JdbcOutputFormat#close method add it there

try (connectionProvider) {
  if (jdbcStatementExecutor != null) {
       jdbcStatementExecutor.closeStatements();
    }
  } catch (SQLException e) {
     LOG.warn("Close JDBC writer failed.", e);
  }

tamirsagi avatar Dec 03 '24 20:12 tamirsagi

Would that get eventually released in the x.y.z-1.19 series ?

After a database reboot, our Flink job took several minutes to recover from the dead connection. I think this could fix it.

Flink 1.20 has also been out for a while, will we have a -1.20 matching serie ? Would it be safe to run the -1.19 jdbc connector serie against Flink 1.20 ? For now we're staying on 1.19

simon-paradis-jive avatar Dec 05 '24 14:12 simon-paradis-jive