mariadb/mysql-test/suite/innodb/r/trx_deadlock.result
mariadb-DebarunBanerjee 7f77041b0a MDEV-37141 DML committed within XA transaction block after deadlock error and implicit rollback
Issue: When XA transaction is implicitly rolled back, we keep XA state
XA_ACTIVE and set rm_error to ER_LOCK_DEADLOCK. Other than XA command
we don't check for rm_error and DML and query are executed with a new
transaction.

Fix: One way to fix this issue is to set the XA state to XA_ROLLBACK_ONLY
which is checked while opening table open_tables() and ER_XAER_RMFAIL is
returned for any DML or Query.
2025-07-10 13:37:03 +05:30

82 lines
2.1 KiB
Text

#
# MDEV-36959 Deadlock does not rollback transaction fully
#
CREATE TABLE t1(col1 INT PRIMARY KEY, col2 INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 1), (2, 2);
SELECT * FROM t1;
col1 col2
1 1
2 2
connect con1,localhost,root,,;
START TRANSACTION;
# Trx-1: Lock 1st record
UPDATE t1 SET col2=10 where col1=1;
connection default;
START TRANSACTION;
# Trx-2: Lock 2nd record
UPDATE t1 SET col2=100 where col1=2;
connection con1;
# Trx-1: Try locking 1st record : Wait
UPDATE t1 SET col2=10 where col1=2;
connection default;
# Wait for Trx-1 to get into lock wait stage
# Trx-2: Try locking 2nd record : Deadlock
UPDATE t1 SET col2=100 where col1=1;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
connection con1;
ROLLBACK;
connection default;
SELECT @@in_transaction;
@@in_transaction
0
UPDATE t1 SET col2=10 where col1=1;
UPDATE t1 SET col2=100 where col1=2;
SELECT @@in_transaction;
@@in_transaction
0
ROLLBACK;
SELECT * FROM t1;
col1 col2
1 10
2 100
DROP TABLE t1;
#
# MDEV-37141 DML committed within XA transaction block after deadlock error and implicit rollback
#
CREATE TABLE t1(col1 INT PRIMARY KEY, col2 INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 1), (2, 2);
SELECT * FROM t1;
col1 col2
1 1
2 2
connection con1;
XA BEGIN 'x1';
# XA Trx-1: Lock 1st record
UPDATE t1 SET col2=10 where col1=1;
connection default;
XA BEGIN 'x2';
# XA Trx-2: Lock 2nd record
UPDATE t1 SET col2=100 where col1=2;
connection con1;
# XA Trx-1: Try locking 1st record : Wait
UPDATE t1 SET col2=10 where col1=2;
connection default;
# Wait for XA Trx-1 to get into lock wait stage
# XA Trx-2: Try locking 2nd record : Deadlock
UPDATE t1 SET col2=100 where col1=1;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
INSERT INTO t1 VALUES (3, 3), (4, 4);
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the ROLLBACK ONLY state
XA END 'x2';
ERROR XAE07: XAER_RMFAIL: The command cannot be executed when global transaction is in the ROLLBACK ONLY state
XA ROLLBACK 'x2';
connection con1;
XA END 'x1';
XA ROLLBACK 'x1';
connection default;
SELECT * FROM t1;
col1 col2
1 1
2 2
DROP TABLE t1;
disconnect con1;