Debian Codegraph @

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

raw
1 --source include/have_debug_sync.inc
2 --source include/have_innodb_16k.inc
3 --source include/count_sessions.inc
4
5 # Save the original settings, to be restored at the end of test
6 SET @innodb_lock_wait_timeout_saved = @@global.innodb_lock_wait_timeout;
7
8 # Make sure that transactions will not finish prematurely
9 SET @@global.innodb_lock_wait_timeout = 20;
10
11 --source ../include/prepare_show_locks.inc
12
13 # Scenario in which a WAITING lock struct is first "cleared" because locks
14 # are moved to a different heap_no, and then "reused" for another GRANTED
15 # lock on a different heap_no, potentially leading to a violation of invariant
16 # that GRANTED locks should be in front of WAITING locks.
17
18 # 1. con1 gets GRANTED GAP+REC S lock on row id=3
19 # 2. con2 gets WAITING II lock on row id=3
20 # 3. con3 gets GRANTED X lock on row id=2000
21 # 4. con4 gets WAITING GAP+REC S lock on row id=2000
22 # 5. con3 inserts so many rows before row id=2000 that the page has to be split,
23 # and the old lock struct of con4 is "cleared" and new WAITING lock for con4
24 # is created on the new page
25 # 6. con3 commits releasing the lock on row id=2000, so con4 can continue now
26 # con4 gets GRANTED GAP+REC S lock on row id=3 (and reuses the previously
27 # "cleared" struct to achieve that)
28 #
29 # The queue for row id=3 contains:
30 # <con1,GRANTED,GAP+REC S>, <con2,WAITING,II>, <con3,GRANTED,GAP_REC S>
31 # so to bring back the invariant that GRANTED are before WAITING, we need to
32 # move con3's lock to front.
33
34 # The CHAR(200) is just to make records large, so page split comes sooner.
35 CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY, val CHAR(200));
36 INSERT INTO t1 (id,val) VALUES (1, "a"), (3, "c"), (1998,"x"), (2000, "z");
37
38 --connect (con1, localhost, root,,)
39 CALL register_connection("con1");
40 BEGIN;
41 SELECT * FROM t1 WHERE id<=3 FOR SHARE;
42
43 --connect (con2, localhost, root,,)
44 CALL register_connection("con2");
45 BEGIN;
46 SET DEBUG_SYNC='lock_wait_will_wait SIGNAL con2_will_wait';
47 --send INSERT INTO t1 VALUES (2,"b")
48
49 --connect (con3, localhost, root,,)
50 SET DEBUG_SYNC='now WAIT_FOR con2_will_wait';
51 CALL register_connection("con3");
52 BEGIN;
53 SELECT * FROM t1 WHERE id=2000 FOR UPDATE;
54
55 --connect (con4, localhost, root,,)
56 CALL register_connection("con4");
57 BEGIN;
58 SET DEBUG_SYNC='lock_wait_will_wait SIGNAL con4_will_wait';
59 --send SELECT * FROM t1 WHERE 1999<=id FOR SHARE
60
61 --connection default
62 SET DEBUG_SYNC='now WAIT_FOR con4_will_wait';
63 CALL show_locks();
64
65
66 --connection con3
67 --let i=10
68 # 16k page, each record > 200 bytes, so 80 rows should be enough
69 while($i<100){
70 --eval INSERT INTO t1 (id,val) VALUES ($i,"x")
71 --inc $i
72 }
73
74 --connection default
75 CALL show_locks();
76
77 --connection con3
78 COMMIT;
79
80 --connection con4
81 --reap
82 SELECT * FROM t1 WHERE id<=3 FOR SHARE;
83
84 --connection default
85 CALL show_locks();
86
87 --connection con1
88 COMMIT;
89
90 --connection con4
91 COMMIT;
92
93 --connection con2
94 --reap
95 COMMIT;
96
97 --connection default
98 --disconnect con1
99 --disconnect con2
100 --disconnect con3
101 --disconnect con4
102
103 DROP TABLE t1;
104 --source ../include/cleanup_show_locks.inc
105
106 # Restore saved settings
107 SET @@global.innodb_lock_wait_timeout = @innodb_lock_wait_timeout_saved ;
108 --source include/wait_until_count_sessions.inc