Description:
We have a topology structure of three MySQL instances: A -> B -> C. Writeset is enabled on all instances. When performing write workloads with XA transactions on instance A, replication lag can be observed on instance C. However, if we replace these XA workloads with normal transactions, no replication lag is observed on instance C. Upon analyzing the binlog generated by instance B, we discovered that the degree of parallelism is significantly reduced under XA workloads. Further investigation revealed that the writeset history is cleared if the writeset cannot be used during dependency tracking. This applies to all commands that do not generate any writeset but have a non-empty binlog cache. XA COMMIT and XA ROLLBACK are two such commands. However, in my opinion, this restriction is unnecessary for XA COMMIT/ROLLBACK.
For example, let's consider two transactions: trxA and trxB, where trxA is an XA transaction and trxB is not. In the binlog, the two transactions are as follows:
GTID -------> last commit=10, sequence number=11
XA START 'trxA'
xxx
XA END 'trxA'
XA PREPARE 'trxA'
GTID -------> last commit=11, sequence number=12
XA COMMIT 'trxA'
GTID(trxB) -------> last commit=12, sequence number=13
BEGIN
xxx
COMMIT
Due to the writeset history being cleared by XA COMMIT during dependency tracking, trxB's commit parent is 12 and should not proceed ahead of 'XA COMMIT trxA' on replica.
Assuming the writeset history has a sufficiently large capacity and only InnoDB is used, let's see what happens if the writeset history is not cleared by XA COMMIT. There are two conditions:
1. trx B has no conflict with trx A, and its commit parent could be 10 or more less.
2. trx B has a conflict with trx A, and its commit parent is 11. On the replica, trxB could be scheduled without waiting for 'XA COMMIT trxA' to finish, but it will be blocked by the row locks held by trxA. When 'XA COMMIT trxA' is finished, the locks are released, and trxB is notified to continue.
In both situations, everything proceeds smoothly. Therefore, for XA COMMIT/ROLLBACK commands, not clearing the writeset history may help increase the performance of the writeset.
How to repeat:
no