From cd109592ca50e881f49208b8bb01e18ee7e3f925 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Mon, 12 Mar 2018 08:30:08 +0400 Subject: [PATCH] MDEV-15217 Assertion `thd->transaction.xid_state.xid.is_null()' failed in trans_xa_start. THD.transaction.xid_state.xid.rm_error should be cleaned as the thread ends. --- mysql-test/r/xa.result | 22 ++++++++++++++++++++++ mysql-test/t/xa.test | 37 ++++++++++++++++++++++++++++++++++++- sql/sql_class.cc | 1 + 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/xa.result b/mysql-test/r/xa.result index 0470c284a29..782be3834d1 100644 --- a/mysql-test/r/xa.result +++ b/mysql-test/r/xa.result @@ -270,3 +270,25 @@ XA ROLLBACK 'xid1'; connection default; DROP TABLE t1, t2; disconnect con2; +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB; +CREATE TABLE t2 (pk INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1),(2); +CREATE TABLE t3 (i INT) ENGINE=InnoDB; +XA BEGIN 'xid1'; +REPLACE INTO t1 SELECT * FROM t2; +connect con1,localhost,root,,test; +XA BEGIN 'xid2'; +INSERT INTO t1 SELECT * FROM t2; +connection default; +REPLACE INTO t2 SELECT * FROM t2; +connection con1; +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +disconnect con1; +connect con2,localhost,root,,test; +INSERT INTO t3 VALUES (1); +XA BEGIN 'xid3'; +disconnect con2; +connection default; +XA END 'xid1'; +XA ROLLBACK 'xid1'; +DROP TABLE t1, t2, t3; diff --git a/mysql-test/t/xa.test b/mysql-test/t/xa.test index 7303030921d..85a792822dd 100644 --- a/mysql-test/t/xa.test +++ b/mysql-test/t/xa.test @@ -394,6 +394,41 @@ DROP TABLE t1, t2; disconnect con2; -# Wait till all disconnects are completed +# +# MDEV 15217 Assertion `thd->transaction.xid_state.xid.is_null()' failed in trans_xa_start. +# +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB; +CREATE TABLE t2 (pk INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t2 VALUES (1),(2); +CREATE TABLE t3 (i INT) ENGINE=InnoDB; + +XA BEGIN 'xid1'; +REPLACE INTO t1 SELECT * FROM t2; + +--connect (con1,localhost,root,,test) +XA BEGIN 'xid2'; +--send +INSERT INTO t1 SELECT * FROM t2; + +--connection default +REPLACE INTO t2 SELECT * FROM t2; + +--connection con1 +--error ER_LOCK_DEADLOCK +--reap +--disconnect con1 + +--connect (con2,localhost,root,,test) +INSERT INTO t3 VALUES (1); +XA BEGIN 'xid3'; + + +#Cleanup +--disconnect con2 +--connection default +XA END 'xid1'; +XA ROLLBACK 'xid1'; +DROP TABLE t1, t2, t3; + --source include/wait_until_count_sessions.inc diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1e07849db16..d854d6de110 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1462,6 +1462,7 @@ void THD::cleanup(void) close_temporary_tables(); transaction.xid_state.xa_state= XA_NOTR; + transaction.xid_state.rm_error= 0; trans_rollback(this); xid_cache_delete(this, &transaction.xid_state);