Commit 91ffa115 authored by Kristian Nielsen's avatar Kristian Nielsen

Hacky testcase to demonstrate the problem with stray deadlock kill leaking to...

Hacky testcase to demonstrate the problem with stray deadlock kill leaking to cause record_gtid() to fail
Signed-off-by: default avatarKristian Nielsen <knielsen@knielsen-hq.org>
parent 8513f726
include/master-slave.inc
[connection master]
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,0), (2,0), (3,0), (4,0), (5,0);
connection slave;
include/stop_slave.inc
SET @old_parallel_threads = @@GLOBAL.slave_parallel_threads;
SET @@global.slave_parallel_threads = 2;
SET @old_slave_domain_parallel_threads = @@GLOBAL.slave_domain_parallel_threads;
SET @@global.slave_domain_parallel_threads = 1;
SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode;
SET @@global.slave_parallel_mode ='optimistic';
CHANGE MASTER TO master_use_gtid= slave_pos;
SET @old_dbug= @@GLOBAL.debug_dbug;
SET GLOBAL debug_dbug= "+d,xa_prepare_stray_deadlock_kill";
connection slave1;
BEGIN;
SELECT * FROM t1 WHERE a=1 FOR UPDATE;
a b
1 0
connect con1,localhost,root,,;
SET SESSION gtid_domain_id=1;
XA START 't1';
UPDATE t1 SET b=1 WHERE a=1;
UPDATE t1 SET b=1 WHERE a=2;
XA END 't1';
XA PREPARE 't1';
XA COMMIT 't1';
connection master1;
XA START 't2';
UPDATE t1 SET b=2 WHERE a=2;
XA END 't2';
XA PREPARE 't2';
XA COMMIT 't2';
connection master;
include/save_master_gtid.inc
connection slave;
include/start_slave.inc
connection slave1;
ROLLBACK;
connection slave;
include/sync_with_master_gtid.inc
SET GLOBAL debug_dbug= @old_dbug;
SELECT * FROM t1 ORDER BY a;
a b
1 1
2 1
3 0
4 0
5 0
connection master;
DROP TABLE t1;
connection slave;
include/stop_slave.inc
SET @@global.slave_parallel_mode = @old_parallel_mode;
SET @@global.slave_parallel_threads = @old_parallel_threads;
SET @@global.slave_domain_parallel_threads = @old_slave_domain_parallel_threads;
include/start_slave.inc
include/rpl_end.inc
--source include/have_debug.inc
--source include/have_innodb.inc
--source include/have_binlog_format_mixed.inc
--source include/master-slave.inc
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,0), (2,0), (3,0), (4,0), (5,0);
--sync_slave_with_master
--source include/stop_slave.inc
SET @old_parallel_threads = @@GLOBAL.slave_parallel_threads;
SET @@global.slave_parallel_threads = 2;
SET @old_slave_domain_parallel_threads = @@GLOBAL.slave_domain_parallel_threads;
SET @@global.slave_domain_parallel_threads = 1;
SET @old_parallel_mode = @@GLOBAL.slave_parallel_mode;
SET @@global.slave_parallel_mode ='optimistic';
CHANGE MASTER TO master_use_gtid= slave_pos;
SET @old_dbug= @@GLOBAL.debug_dbug;
SET GLOBAL debug_dbug= "+d,xa_prepare_stray_deadlock_kill";
--connection slave1
BEGIN;
SELECT * FROM t1 WHERE a=1 FOR UPDATE;
--connect(con1,localhost,root,,)
SET SESSION gtid_domain_id=1;
XA START 't1';
UPDATE t1 SET b=1 WHERE a=1;
UPDATE t1 SET b=1 WHERE a=2;
XA END 't1';
XA PREPARE 't1';
XA COMMIT 't1';
--connection master1
XA START 't2';
UPDATE t1 SET b=2 WHERE a=2;
XA END 't2';
XA PREPARE 't2';
XA COMMIT 't2';
--connection master
--source include/save_master_gtid.inc
--connection slave
--source include/start_slave.inc
# Wait until trx t2 is prepared (t3 will be waiting)
--sleep 1
--connection slave1
ROLLBACK;
# Now at time 1s, t2 will decide to deadlock kill t1, but sleep
# At time 2s, t1 will clear kill status and sleep again
# At time 3s, t2 will deadlock kill t1
# At time 4s, t1 will wakeup and try to update gtid_slave_pos, fail due to kill
--connection slave
--let $slave_timeout= 20
--source include/sync_with_master_gtid.inc
SET GLOBAL debug_dbug= @old_dbug;
SELECT * FROM t1 ORDER BY a;
--connection master
DROP TABLE t1;
--connection slave
--source include/stop_slave.inc
SET @@global.slave_parallel_mode = @old_parallel_mode;
SET @@global.slave_parallel_threads = @old_parallel_threads;
SET @@global.slave_domain_parallel_threads = @old_slave_domain_parallel_threads;
--source include/start_slave.inc
--source include/rpl_end.inc
......@@ -4452,6 +4452,7 @@ int Xid_apply_log_event::do_apply_event(rpl_group_info *rgi)
*/
wait_for_pending_deadlock_kill(thd, thd->rgi_slave);
thd->reset_killed();
DBUG_EXECUTE_IF("xa_prepare_stray_deadlock_kill", my_sleep(2000000););
}
if ((err= do_record_gtid(thd, rgi, false, &hton, true)))
......
......@@ -5426,6 +5426,7 @@ thd_rpl_deadlock_check(MYSQL_THD thd, MYSQL_THD other_thd)
return 0;
}
DBUG_EXECUTE_IF("xa_prepare_stray_deadlock_kill", my_sleep(2000000););
/*
This transaction is about to wait for another transaction that is required
by replication binlog order to commit after. This would cause a deadlock.
......
......@@ -1157,6 +1157,7 @@ static bool slave_applier_reset_xa_trans(THD *thd)
}
thd->transaction->all.ha_list= 0;
DBUG_EXECUTE_IF("xa_prepare_stray_deadlock_kill", my_sleep(2000000););
ha_close_connection(thd);
thd->transaction->cleanup();
thd->transaction->all.reset();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment