Skip to content

Commit f1276aa

Browse files
committed
MDEV-26652: xa transactions binlogged in wrong order
Disclaimer: This report was fixed in a previous commit with MDEV-21117, this patch only adds a test to show the presence of the fix. Prior to MDEV-21117, the ordering of the handlers in a transaction's ha_info list solely determined the order in which the handlertons commit. The binlog is supposed to commit first, and is normally placed first in the ha_list to do so; however, in multi-engine 2-phase XA transactions, the binlog can be placed second. This allowed a race-condition for other concurrent transactions to commit and binlog before the prior XA COMMIT would be written to binlog. MDEV-21117 fixed this so the binlog is specially considered to commit first, before traversing the ha_list (see commit_one_phase_2() in sql/hander.cc for this specific change in 6c39eae).
1 parent 066e8d6 commit f1276aa

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
include/master-slave.inc
2+
[connection master]
3+
connection master;
4+
create table t1 (a int primary key, b int) engine=innodb;
5+
insert t1 values (1,1),(3,3),(5,5),(7,7);
6+
create table t2 (m int) engine=aria;
7+
# Create multi-engine, two-phase XA transaction (T1)
8+
xa start '1';
9+
insert t2 values (1);
10+
update t1 set b=50 where b=5;
11+
xa end '1';
12+
xa prepare '1';
13+
# Create T2
14+
connection server_1;
15+
update t1 set b=10 where a=5;
16+
connection master;
17+
xa commit '1';
18+
connection server_1;
19+
include/save_master_gtid.inc
20+
# This would hang prior to MDEV-21117
21+
connection slave;
22+
include/sync_with_master_gtid.inc
23+
connection master;
24+
drop table t1, t2;
25+
include/rpl_end.inc
26+
# End of rpl_xa_2pc_multi_engine.test
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# This test ensures binlog order is correct for multi-engine, two-phase XA
3+
# transactions. MDEV-26652 exposed a race condition which would allow
4+
# concurrent transactions which modify the same table record to binlog in
5+
# the "opposite" order, i.e. what _should_ be:
6+
# T1 XA PREPARE
7+
# T1 XA COMMIT
8+
# T2
9+
#
10+
# was binlogged as
11+
# T1 XA PREPARE
12+
# T2
13+
# T1 XA COMMIT
14+
#
15+
# which would break replication.
16+
#
17+
# Note that the actual fix for this issue was done with MDEV-21117.
18+
#
19+
# References:
20+
# MDEV-26652: xa transactions binlogged in wrong order
21+
# MDEV-21117: refine the server binlog-based recovery for semisync
22+
#
23+
source include/have_binlog_format_row.inc;
24+
source include/have_innodb.inc;
25+
source include/master-slave.inc;
26+
27+
--connection master
28+
create table t1 (a int primary key, b int) engine=innodb;
29+
insert t1 values (1,1),(3,3),(5,5),(7,7);
30+
create table t2 (m int) engine=aria;
31+
32+
33+
--echo # Create multi-engine, two-phase XA transaction (T1)
34+
xa start '1';
35+
insert t2 values (1);
36+
update t1 set b=50 where b=5;
37+
xa end '1';
38+
39+
# Aria doesn't support XA PREPARE, so disable warnings
40+
--disable_warnings
41+
xa prepare '1';
42+
--enable_warnings
43+
44+
--echo # Create T2
45+
--connection server_1
46+
--send update t1 set b=10 where a=5
47+
48+
--connection master
49+
xa commit '1';
50+
51+
--connection server_1
52+
--reap
53+
--source include/save_master_gtid.inc
54+
55+
--echo # This would hang prior to MDEV-21117
56+
--connection slave
57+
--source include/sync_with_master_gtid.inc
58+
59+
--connection master
60+
drop table t1, t2;
61+
62+
--source include/rpl_end.inc
63+
--echo # End of rpl_xa_2pc_multi_engine.test

0 commit comments

Comments
 (0)