Debian Codegraph @

mysql-test/suite/innodb/t/hp_deadlock.test

raw
1 # Scenario:
2 # We have just 3 transactions, T1, T2, T3 which should commit in the order: T1, T2, T3.
3 # Now suppose that
4 # T1 is waiting for a lock held by T3
5 # T3 is waiting for a lock held by T2
6 # T2 is waiting for T1 to commit
7 # InnoDB informs Coordinator about T1->T3 edge, which is bad as 1<3, and
8 # coordinator decides to abort T3.
9 # But T3 sits in the waiting slot, and is immune to killing.
10 # T2 can't proceed, as it waits for T1.
11 # T1 can't proceed as it waits for T3.
12 # T3 can't proceed as it waits for T2.
13 # Deadlock
14
15 # It's also important that in case T2 is a regular (not HP) transaction, then T3 should
16 # keep waiting for T2. OTOH T1 can timeout while waiting for T3 as both are HP.
17
18 # In $scenario = 1 all transactions are HP
19 # IN $scenario = 2 transaction T2 is not HP
20
21 --source include/have_debug_sync.inc
22 --source include/have_debug.inc
23 --source include/count_sessions.inc
24 SET @old_innodb_lock_wait_timeout= @@GLOBAL.innodb_lock_wait_timeout;
25 SET GLOBAL innodb_lock_wait_timeout= 4;
26
27
28 --let $scenario = 1
29
30 while($scenario <= 2){
31 --echo # SCENARIO $scenario
32
33 CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
34 INSERT INTO t1 VALUES (0);
35 CREATE TABLE t2 (c1 INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
36 INSERT INTO t2 VALUES (0);
37
38 if($scenario == 2){
39 --connect(con0,localhost,root,,test)
40 CREATE TABLE t3 (c1 INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
41 INSERT INTO t3 VALUES (0);
42 BEGIN;
43 SELECT * FROM t3 FOR UPDATE;
44 }
45 --connect(con1,localhost,root,,test)
46 --connect(con2,localhost,root,,test)
47 --connect(con3,localhost,root,,test)
48
49 --connection con2
50 if($scenario == 1) {
51 --source include/start_transaction_high_prio.inc
52 }
53 if($scenario == 2){
54 BEGIN;
55 }
56 DELETE FROM t2;
57 if($scenario == 2){
58 # We want to see how con3 handles timeing out while waiting for a lock held by con2.
59 # In $scenario == 2 con3 might try to "kill" con2 in some way.
60 # To prevent con2 from being rolled back and releasing locks too soon we make it wait for con0,
61 # so that con3 will force a fake deadlock error on con2, and then we pause con2 before rollback.
62 SET DEBUG_SYNC='lock_wait_has_finished_waiting WAIT_FOR con2_can_rollback';
63 SET DEBUG_SYNC='lock_wait_will_wait SIGNAL con2_will_wait';
64 --send SELECT * FROM t3 FOR UPDATE
65 }
66
67 --connection con3
68 if($scenario == 2){
69 SET DEBUG_SYNC='now WAIT_FOR con2_will_wait';
70 }
71 --source include/start_transaction_high_prio.inc
72 DELETE FROM t1;
73 SET DEBUG_SYNC='lock_wait_will_wait SIGNAL con3_will_wait';
74 --send DELETE FROM t2; COMMIT
75
76 --connection con1
77 SET DEBUG_SYNC='now WAIT_FOR con3_will_wait';
78 --source include/start_transaction_high_prio.inc
79 SET DEBUG_SYNC='lock_wait_will_wait SIGNAL con1_will_wait';
80 --send DELETE FROM t1; COMMIT
81
82 # Now let's try to commit all of them in the order con1, con2, con3
83 # In $scenario = 1, we accept timeouts and deadlock as a valid outcomes.
84 # What we don't accept is undetected deadlocks which make whole test fail.
85 # In $scenario = 2, we additionally care that con3 should succeed.
86 # This implies that con1 (which waits for con3 but commits first) must fail.
87
88 --connection con1
89 if($scenario == 1){
90 --error 0,ER_LOCK_DEADLOCK,ER_LOCK_WAIT_TIMEOUT
91 --reap
92 }
93 if($scenario == 2){
94 --error ER_LOCK_DEADLOCK,ER_LOCK_WAIT_TIMEOUT
95 --reap
96 SET DEBUG_SYNC='now SIGNAL con2_can_rollback';
97 }
98
99 --connection con2
100 if($scenario == 1){
101 COMMIT;
102 }
103 if($scenario == 2){
104 --error ER_LOCK_DEADLOCK
105 --reap
106 }
107
108 --connection con3
109 if($scenario == 1){
110 --error 0,ER_LOCK_DEADLOCK,ER_LOCK_WAIT_TIMEOUT
111 --reap
112 }
113 if($scenario == 2){
114 --reap
115 }
116
117
118 --connection default
119 --disconnect con1
120 --disconnect con2
121 --disconnect con3
122 if($scenario == 2){
123 --disconnect con0
124 DROP TABLE t3;
125 }
126
127 DROP TABLE t1;
128 DROP TABLE t2;
129
130 --inc $scenario
131 }
132
133 SET GLOBAL innodb_lock_wait_timeout= @old_innodb_lock_wait_timeout;
134 --source include/wait_until_count_sessions.inc