MartijnVisser commented on code in PR #259:
URL:
https://github.com/apache/flink-connector-jdbc/pull/259#discussion_r4773114161
##########
flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/sink/committer/JdbcCommitter.java:
##########
@@ -64,16 +75,54 @@ public void
commit(Collection<CommitRequest<JdbcCommitable>> committables)
if (DeliveryGuarantee.EXACTLY_ONCE != this.deliveryGuarantee &&
!committables.isEmpty()) {
throw new FlinkRuntimeException("Non XA sink with commitables");
}
+ if (!committables.isEmpty() && !opened) {
+ try {
+ xaConnectionProvider.open();
+ } catch (Exception e) {
+ // close() skips the provider, so release what open() got
before it failed
+ try {
+ xaConnectionProvider.close();
+ } catch (Exception closeException) {
+ e.addSuppressed(closeException);
+ }
+ ExceptionUtils.rethrowIOException(e);
+ }
+ opened = true;
+ }
for (CommitRequest<JdbcCommitable> request : committables) {
-
request.getCommittable().getTransaction().orElse(this.jdbcTransaction).commitTx();
+ Xid xid = request.getCommittable().getXid();
+ try {
+ xaConnectionProvider.commit(xid, isRestored(xid));
+ } catch (TransientXaException e) {
+ if (request.getNumberOfRetries() + 1 >= maxCommitAttempts) {
+ request.signalFailedWithUnknownReason(e);
+ } else {
+ LOG.warn("failed to commit transaction {} (retrying)",
xid, e);
+ request.retryLater();
Review Comment:
Reopening on a `TransientXaException` covers MySQL and a connection reset on
PostgreSQL, but pgjdbc reports a connection the server closed
(`idle_session_timeout`, `pg_terminate_backend`, a restart) as `XAER_RMERR`,
which isn't retried, and a blackholed connection hangs the commit before any
retry. So `commit()` now validates the connection and reconnects if it was
dropped, and a retry goes through that check too. I dropped the committer's
connection between two checkpoints with an idle timeout, a killed session, a
restart, a reset and a blackhole through Toxiproxy on PostgreSQL 16 and MySQL
9.0, and each time the next commit went through without a failover.
`testReconnectIfTheConnectionWasDropped` and
`testReconnectIfThePooledConnectionWasDropped` fail without it. A network that
stops answering during the commit itself still blocks it, since no connection
of the connector has a socket timeout by default: FLINK-41785. fc830881
--
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]