Bug #97966 XA COMMIT in another session will not write binlog event
Submitted: 12 Dec 2019 11:59 Modified: 14 Dec 2019 9:46
Reporter: lujun wang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: XA transactions Severity:S3 (Non-critical)
Version:5.7, 5.7.28 OS:Any
Assigned to: CPU Architecture:Any
Tags: binlog event, XA COMMIT

[12 Dec 2019 11:59] lujun wang
Description:
When XA COMMIT statement executed in another session(thd), mysql will not write XA COMMIT binlog event.
For example, in master-slave cluster, consider the following operations:
Step 1:  connect to master
Step 2: execute XA START 'my_xid';
Step 3: execute some dml
Step 4: execute XA END 'my_xid';
Step 5: execute XA PREPARE 'my_xid';
Step 6: connect to slave
Step 7: execute XA COMMIT 'my_xid';

In Step 7, this will commit the transaction in storage engine but do not write binlog event in binlog. That leaves the master a pending xa transaction and inconsistency between master and slave.

How to repeat:
in master-slave cluster, consider the following operations:
Step 1:  connect to master
Step 2: execute XA START 'my_xid';
Step 3: execute some dml
Step 4: execute XA END 'my_xid';
Step 5: execute XA PREPARE 'my_xid';
Step 6: connect to slave
Step 7: execute XA COMMIT 'my_xid';
[13 Dec 2019 2:59] lujun wang
The root cause is as follow:
In function MYSQL_BIN_LOG::commit, there is a bypass execution: if no cache manager(means nothing to log), just commit this transaction in storage engines.
[14 Dec 2019 9:46] MySQL Verification Team
Hello lujun wang,

Thank you for the report.

regards,
Umesh