Debian Codegraph @

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

raw
1 #
2 # wl#9383 INNODB: ADD AN OPTION TO TURN OFF/ON DEADLOCK CHECKER
3 #
4
5 --source include/have_innodb.inc
6 --source include/count_sessions.inc
7
8 --disable_query_log
9 call mtr.add_suppression("InnoDB: Transaction was aborted due to ");
10 --enable_query_log
11
12 let $have_deadlock=`select @@GLOBAL.innodb_deadlock_detect`;
13
14 connection default;
15
16 CREATE TABLE t1(
17 id INT,
18 PRIMARY KEY(id)
19 ) ENGINE=InnoDB;
20
21 CREATE TABLE dl(
22 id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
23 cnt INT UNSIGNED
24 ) ENGINE=InnoDB;
25
26 INSERT INTO t1 VALUES(1), (2), (3);
27 # Preserve the initial value of the deadlock counter
28 INSERT INTO dl(cnt) SELECT variable_value FROM information_schema.global_status WHERE variable_name LIKE 'Innodb_deadlocks';
29
30 # We are not interested query results, only errors
31 --disable_result_log
32 BEGIN;
33
34 SELECT * FROM t1 WHERE id = 1 LOCK IN SHARE MODE;
35
36 connect (con1,localhost,root,,);
37 BEGIN;
38 SELECT * FROM t1 WHERE id = 2 LOCK IN SHARE MODE;
39
40 connect (con2,localhost,root,,);
41 BEGIN;
42 SELECT * FROM t1 WHERE id = 2 LOCK IN SHARE MODE;
43
44 send SELECT * FROM t1 WHERE id = 1 FOR UPDATE;
45
46 connection default;
47 send SELECT * FROM t1 WHERE id = 2 FOR UPDATE;
48
49 connection con2;
50 if (!$have_deadlock) {
51 --error ER_LOCK_WAIT_TIMEOUT
52 reap;
53 disconnect con1;
54 }
55 if ($have_deadlock) {
56 connection con1;
57 COMMIT;
58 disconnect con1;
59 connection con2;
60 --error 0,ER_LOCK_DEADLOCK,ER_LOCK_WAIT_TIMEOUT
61 reap;
62 }
63 ROLLBACK;
64 disconnect con2;
65
66 #
67 # Note here that con1 is the older transaction as it
68 # query started wait first. Thus, con1 gets lock
69 # wait timeout first. There is possibility that
70 # default connection gets lock timeout also or
71 # as con1 is rolled back it gets the locks it waited
72 # and does the update.
73 #
74 connection default;
75 --let $valid_deadlock_cnt= 1
76 if (!$have_deadlock) {
77 --error 0,ER_LOCK_WAIT_TIMEOUT
78 reap;
79 }
80 if ($have_deadlock) {
81 --error 0,ER_LOCK_DEADLOCK
82 reap;
83 --disable_query_log
84 INSERT INTO dl(cnt) SELECT variable_value FROM information_schema.global_status WHERE variable_name LIKE 'Innodb_deadlocks';
85 set @init_deadlock_cnt = (SELECT min(k.cnt) FROM dl k);
86 --let $valid_deadlock_cnt= `SELECT (max(t.cnt-@init_deadlock_cnt) = 1) FROM dl t`
87 --enable_query_log
88 }
89 # Indicates that the deadlock counter works well.
90 # Use the default =1 where is no deadlock detection,
91 # to enable unconditional check.
92 --echo 'Deadlock counter is valid';
93 --echo $valid_deadlock_cnt
94
95 ROLLBACK;
96
97 --enable_result_log
98 DROP TABLE t1;
99 DROP TABLE dl;
100 --source include/wait_until_count_sessions.inc