Skip to content

Commit 90e5e2f

Browse files
sjaakolaNirbhay Choubey
authored andcommitted
- added mtr test case for this issue - not a perfect one, depends on some sleeps instead of checking if sync points are met
1 parent 2cdcde9 commit 90e5e2f

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1));
2+
CREATE TABLE t2 (f1 INTEGER PRIMARY KEY, f2 CHAR(1));
3+
INSERT INTO t1 VALUES (1, 'a');
4+
INSERT INTO t1 VALUES (2, 'a');
5+
SET AUTOCOMMIT=ON;
6+
START TRANSACTION;
7+
UPDATE t1 SET f2 = 'b' WHERE f1 = 1;
8+
LOCK TABLE t2 WRITE;
9+
SET GLOBAL DEBUG = "d,sync.wsrep_before_mdl_wait";
10+
SELECT * FROM t2;;
11+
SET GLOBAL DEBUG = "d,sync.wsrep_after_BF_victim_lock";
12+
UPDATE t1 SET f2 = 'c' WHERE f1 = 1;
13+
SET GLOBAL DEBUG = "";
14+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_before_mdl_wait";
15+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_after_BF_victim_lock";
16+
UNLOCK TABLES;
17+
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
18+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a';
19+
COUNT(*) = 1
20+
1
21+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c';
22+
COUNT(*) = 1
23+
1
24+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a';
25+
COUNT(*) = 1
26+
1
27+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c';
28+
COUNT(*) = 1
29+
1
30+
DROP TABLE t1;
31+
DROP TABLE t2;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#
2+
# This test tests a potential race condition in MDL locking
3+
#
4+
5+
--source include/galera_cluster.inc
6+
--source include/have_innodb.inc
7+
--source include/have_debug_sync.inc
8+
9+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY, f2 CHAR(1));
10+
CREATE TABLE t2 (f1 INTEGER PRIMARY KEY, f2 CHAR(1));
11+
INSERT INTO t1 VALUES (1, 'a');
12+
INSERT INTO t1 VALUES (2, 'a');
13+
14+
--connection node_1
15+
SET AUTOCOMMIT=ON;
16+
START TRANSACTION;
17+
18+
UPDATE t1 SET f2 = 'b' WHERE f1 = 1;
19+
20+
# block access to t2
21+
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
22+
--connection node_1a
23+
LOCK TABLE t2 WRITE;
24+
25+
# Block before MLD lock wait
26+
--connection node_1
27+
SET GLOBAL DEBUG = "d,sync.wsrep_before_mdl_wait";
28+
--send SELECT * FROM t2;
29+
30+
# Wait for SELECT to be blocked
31+
--connection node_1a
32+
#--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIS WHERE STATE = 'System lock';
33+
#--source include/wait_condition.inc
34+
#--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE STATE = 'init' AND INFO = 'COMMIT';
35+
#--source include/wait_condition.inc
36+
37+
# block applier to wait after BF victim is locked
38+
SET GLOBAL DEBUG = "d,sync.wsrep_after_BF_victim_lock";
39+
40+
# Issue a conflicting update on node #2
41+
--connection node_2
42+
UPDATE t1 SET f2 = 'c' WHERE f1 = 1;
43+
44+
--sleep 3
45+
46+
# Unblock the SELECT, to enter wsrep_thd_is_BF
47+
--connection node_1a
48+
SET GLOBAL DEBUG = "";
49+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_before_mdl_wait";
50+
51+
--sleep 3
52+
53+
# unblock applier to try to BF the SELECT
54+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_after_BF_victim_lock";
55+
56+
57+
# table lock is not needed anymore
58+
--sleep 3
59+
UNLOCK TABLES;
60+
61+
# SELECT succeeds
62+
--connection node_1
63+
64+
--error ER_LOCK_DEADLOCK
65+
--reap
66+
67+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a';
68+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c';
69+
70+
--connection node_2
71+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'a';
72+
SELECT COUNT(*) = 1 FROM t1 WHERE f2 = 'c';
73+
74+
DROP TABLE t1;
75+
DROP TABLE t2;

0 commit comments

Comments
 (0)