1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-30423 Deadlock on Replica during BACKUP STAGE BLOCK_COMMIT on XA transactions

The user XA commit execution branch was caught not have been covered
with MDEV-21953 fixes.

The XA involved deadlock is resolved now to apply the former fixes
pattern.
Along the fixes the following changes have been implemented.
- MDL lock attribute correction
- dissociation of the externally completed XA from the current
  thread's xid_state in the error branches
- cleanup_context() preseves the prepared XA
- wait_for_prior_commit() is relocated to satisfy both
  the binlog ON (log-slave-updates and skip-log-bin)
  and OFF slave execution branches.
This commit is contained in:
Andrei
2023-01-19 19:42:24 +02:00
parent 647a7232ff
commit dc646c2389
17 changed files with 786 additions and 37 deletions

View File

@ -7,6 +7,8 @@ include/master-slave.inc
connection master;
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE = innodb;
connection slave;
call mtr.add_suppression("Deadlock found when trying to get lock");
call mtr.add_suppression("Commit failed due to failure of an earlier commit");
include/stop_slave.inc
SET @old_parallel_threads= @@GLOBAL.slave_parallel_threads;
SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode;
@ -30,6 +32,167 @@ connection backup_slave;
BACKUP STAGE END;
connection slave;
include/diff_tables.inc [master:t1,slave:t1]
# MDEV-30423: dealock XA COMMIT vs BACKUP
#
# Normal XA COMMIT
connection slave;
include/stop_slave.inc
connection master;
connection aux_slave;
BEGIN;
INSERT INTO t1 VALUES (4);
connection master;
XA START '1';
INSERT INTO t1 VALUES (3);
XA END '1';
XA PREPARE '1';
connection master1;
INSERT INTO t1 VALUES (4);
connection master;
XA COMMIT '1';
include/save_master_gtid.inc
connection slave;
include/start_slave.inc
connection aux_slave;
# Xid '1' must be in the output:
XA RECOVER;
formatID gtrid_length bqual_length data
1 1 0 1
connection backup_slave;
BACKUP STAGE START;
BACKUP STAGE BLOCK_COMMIT;
connection aux_slave;
ROLLBACK;
connection backup_slave;
BACKUP STAGE END;
connection slave;
include/sync_with_master_gtid.inc
include/stop_slave.inc
#
# Normal XA ROLLBACK
connection slave;
include/stop_slave.inc
Warnings:
Note 1255 Slave already has been stopped
connection master;
connection aux_slave;
BEGIN;
INSERT INTO t1 VALUES (6);
connection master;
XA START '1';
INSERT INTO t1 VALUES (5);
XA END '1';
XA PREPARE '1';
connection master1;
INSERT INTO t1 VALUES (6);
connection master;
XA ROLLBACK '1';
include/save_master_gtid.inc
connection slave;
include/start_slave.inc
connection aux_slave;
# Xid '1' must be in the output:
XA RECOVER;
formatID gtrid_length bqual_length data
1 1 0 1
connection backup_slave;
BACKUP STAGE START;
BACKUP STAGE BLOCK_COMMIT;
connection aux_slave;
ROLLBACK;
connection backup_slave;
BACKUP STAGE END;
connection slave;
include/sync_with_master_gtid.inc
include/stop_slave.inc
#
# Errored out XA COMMIT
connection slave;
include/stop_slave.inc
Warnings:
Note 1255 Slave already has been stopped
connection master;
connection aux_slave;
BEGIN;
INSERT INTO t1 VALUES (8);
connection master;
XA START '1';
INSERT INTO t1 VALUES (7);
XA END '1';
XA PREPARE '1';
connection master1;
INSERT INTO t1 VALUES (8);
connection master;
XA COMMIT '1';
include/save_master_gtid.inc
connection slave;
SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout;
SET @sav_slave_transaction_retries = @@global.slave_transaction_retries;
SET @@global.innodb_lock_wait_timeout =1;
SET @@global.slave_transaction_retries=0;
include/start_slave.inc
connection aux_slave;
# Xid '1' must be in the output:
XA RECOVER;
formatID gtrid_length bqual_length data
1 1 0 1
connection backup_slave;
BACKUP STAGE START;
BACKUP STAGE BLOCK_COMMIT;
connection aux_slave;
ROLLBACK;
connection backup_slave;
BACKUP STAGE END;
connection slave;
include/stop_slave.inc
SET @@global.innodb_lock_wait_timeout = @sav_innodb_lock_wait_timeout;
SET @@global.slave_transaction_retries= @sav_slave_transaction_retries;
connection slave;
include/start_slave.inc
include/sync_with_master_gtid.inc
#
# Errored out XA ROLLBACK
connection slave;
include/stop_slave.inc
connection master;
connection aux_slave;
BEGIN;
INSERT INTO t1 VALUES (10);
connection master;
XA START '1';
INSERT INTO t1 VALUES (9);
XA END '1';
XA PREPARE '1';
connection master1;
INSERT INTO t1 VALUES (10);
connection master;
XA ROLLBACK '1';
include/save_master_gtid.inc
connection slave;
SET @sav_innodb_lock_wait_timeout = @@global.innodb_lock_wait_timeout;
SET @sav_slave_transaction_retries = @@global.slave_transaction_retries;
SET @@global.innodb_lock_wait_timeout =1;
SET @@global.slave_transaction_retries=0;
include/start_slave.inc
connection aux_slave;
# Xid '1' must be in the output:
XA RECOVER;
formatID gtrid_length bqual_length data
1 1 0 1
connection backup_slave;
BACKUP STAGE START;
BACKUP STAGE BLOCK_COMMIT;
connection aux_slave;
ROLLBACK;
connection backup_slave;
BACKUP STAGE END;
connection slave;
include/stop_slave.inc
SET @@global.innodb_lock_wait_timeout = @sav_innodb_lock_wait_timeout;
SET @@global.slave_transaction_retries= @sav_slave_transaction_retries;
connection slave;
include/start_slave.inc
include/sync_with_master_gtid.inc
connection slave;
include/stop_slave.inc
SET @@global.slave_parallel_threads= @old_parallel_threads;