MartijnVisser commented on code in PR #259:
URL: 
https://github.com/apache/flink-connector-jdbc/pull/259#discussion_r4773114908


##########
docs/content/docs/connectors/datastream/jdbc.md:
##########
@@ -448,12 +448,26 @@ JdbcExactlyOnceOptions.builder()
     .build();
 ```
 
-This will make Flink use a separate connection for every XA transaction. This 
may require adjusting connection limits.
-For PostgreSQL and MySQL, this can be done by increasing `max_connections`.
+This will make Flink start every XA transaction on a connection from a pool, 
and return the connection once its transaction is prepared, so each sink 
subtask writes on one connection at a time.
 
 Furthermore, XA needs to be enabled and/or configured in some databases.
-For PostgreSQL, you should set `max_prepared_transactions` to some value 
greater than zero.
-For MySQL v8+, you should grant `XA_RECOVER_ADMIN` to Flink DB user.
+For PostgreSQL, you should set `max_prepared_transactions` to at least twice 
the sink parallelism: every sink subtask keeps its transaction prepared until 
the checkpoint completes, and can prepare the next one before the previous one 
is committed. Each failed or concurrent checkpoint in between adds one more per 
sink subtask.
+For MySQL v8+, you should grant `XA_RECOVER_ADMIN` to Flink DB user. On 
Oracle, grant `SELECT` on `DBA_PENDING_TRANSACTIONS` and `EXECUTE` on 
`SYS.DBMS_XA`. The sink lists the prepared transactions at every start, and 
fails if it can't.
+
+The sink commits a prepared XA transaction once the checkpoint completes, on a 
different connection than the one that prepared it.
+For MySQL, this requires `xa_detach_on_prepare` to be `ON`, which is the 
default since MySQL 8.0.29.
+
+Records become visible once the checkpoint completes. A single committer 
subtask commits the transactions of all sink subtasks, one after another, which 
takes about one database round trip per sink subtask.
+A prepared transaction keeps its locks until it is committed, so a record that 
touches a row of the previous checkpoint waits until that commit.

Review Comment:
   Added. I reproduced it on PostgreSQL with an expired second checkpoint: 
without `lock_timeout` the writer was still waiting on the prepared transaction 
for 40 s, and with `lock_timeout` at 3 s the job failed over and finished with 
the right result, on 2.1.3, 2.2.1 and 2.3.0. d0e8f51d
   



-- 
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]

Reply via email to