MartijnVisser commented on code in PR #259:
URL:
https://github.com/apache/flink-connector-jdbc/pull/259#discussion_r4773113355
##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/sink/writer/JdbcWriter.java:
##########
@@ -127,7 +122,24 @@ public JdbcWriter(
() ->
JdbcBatchStatementExecutor.simple(
queryStatement.query(),
queryStatement::statement));
- this.jdbcOutput.open(outputSerializer);
+ try {
+ if (jdbcTransaction != null) {
+ this.jdbcTransaction.open(state);
+ this.jdbcTransaction.rollbackPreparedTxs(lastCheckpointId);
+ this.jdbcTransaction.createTx(lastCheckpointId);
+ }
+ this.jdbcOutput.open(outputSerializer);
+ } catch (IOException | RuntimeException e) {
Review Comment:
Filed FLINK-41793. I reproduced it on Derby, where `prepareStatement()`
fails for a missing table. PostgreSQL and MySQL prepare on execute by default,
so they fail later, in a writer that gets closed. `JdbcOutputFormat.close()` is
safe on a half-open format though: it skips the null executor and closes the
connection. The `JdbcWriter` of #254 already releases the connection when
`open()` fails, so I've left it out of this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]