Bug #98288 xa commit crash lead mysql replication error
Submitted: 20 Jan 2020 0:57 Modified: 13 Feb 2020 8:23
Reporter: phoenix Zhang (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: XA transactions Severity:S3 (Non-critical)
Version:5.7.26 OS:Any
Assigned to: CPU Architecture:Any
Tags: replication, xa

[20 Jan 2020 0:57] phoenix Zhang
Description:
Consider an mysql replication, master-A and slave-B.

In master-A, execute below:
XA START '1';
INSERT INTO t1 VALUES (1);
XA END '1';
XA PREPARE '1';
XA COMMIT '1';

Now, mysqld server crash when do XA COMMIT, one case is, the binlog already write and send to slave-B, while it does not commit in engine.

Cause slave-B receive the binlog event, the trx finally commit in slave-B. However, when master-A restart, it will not auto commit this trx, it still in prepared state. Then, master and slave share data inconsistent. If master-A do XA COMMIT '1' again, then the slave thread will broken in slave-B.

How to repeat:
according the description. kill -9 master-A mysqld server process when do xa commit, it will repeat. 

Suggested fix:
When master-A restart, if external xa transaction being prepared state, and it can find that xid in binlog event, do auto commit when recover.
[20 Jan 2020 1:01] phoenix Zhang
Here is my patch to do auto recover when mysqld restart. Do commit when engine prepared, and write XA COMMIT event in binlog

Attachment: xa_commit_recover.diff (text/x-patch), 9.55 KiB.

[24 Jan 2020 13:19] MySQL Verification Team
Hi,

Thanks for the report. This one was easy to reproduce, I appreciate the test case.

If you did not already signed OCA:

In order to submit contributions you must first sign the Oracle Contribution Agreement (OCA).
For additional information please check http://www.oracle.com/technetwork/community/oca-486395.html.
If you have any questions, please contact the MySQL community team. 

much appreciated
Bogdan
[12 Feb 2020 13:00] Ståle Deraas
Posted by developer:
 
This is a duplicate to the effect that "XA statements are not atomic in the server (engine + binlog)".
[13 Feb 2020 8:23] Erlend Dahl
Duplicate of

Bug#76233 XA prepare is logged ahead of engine prepare