Debian Codegraph @

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

raw
1 --source include/have_debug_sync.inc
2 --source include/count_sessions.inc
3
4 # Scenario:
5 # C1 obtains implicit lock
6 # C2 notices the implicit lock and decides to do impl-to-expl conversion
7 # C1 starts commit and pauses after removing itself from rw-list, but before
8 # (old code) changing state to TRX_STATE_COMMITED_IN_MEMORY
9 # (new code) removing explicit locks
10 # C3 ignores C1 (as it is no longer in rw-list) and adds own exclusive lock on
11 # the record
12 # C2 finishes impl-to-explicit conversion
13 # (at this point we have two X locks on the same row)
14
15 CREATE TABLE t1(id INT PRIMARY KEY) ENGINE=InnoDB;
16 INSERT INTO t1 (id) VALUES (1),(3);
17
18 --connect(C1,localhost,root,,test)
19 --connect(C2,localhost,root,,test)
20 --connect(C3,localhost,root,,test)
21
22 --connection C1
23 BEGIN;
24 INSERT INTO t1 (id) VALUES (2);
25
26 --connection C2
27 BEGIN;
28 SET DEBUG_SYNC = "before_lock_rec_convert_impl_to_expl_for_trx
29 SIGNAL c2_decided
30 WAIT_FOR c2_can_convert";
31 SET DEBUG_SYNC = "lock_wait_will_wait SIGNAL c2_will_wait";
32 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE
33
34 --connection C1
35 SET DEBUG_SYNC = "now WAIT_FOR c2_decided";
36 SET DEBUG_SYNC = "before_lock_trx_release_locks
37 SIGNAL c1_will_commit
38 WAIT_FOR c1_can_commit";
39 --send COMMIT
40
41 --connection C3
42 BEGIN;
43 SET DEBUG_SYNC = "now WAIT_FOR c1_will_commit";
44 SELECT * FROM t1 WHERE id=2 FOR UPDATE;
45 SET DEBUG_SYNC = "now SIGNAL c2_can_convert";
46 SET DEBUG_SYNC = "now WAIT_FOR c2_will_wait";
47 SET DEBUG_SYNC = "now SIGNAL c1_can_commit";
48 COMMIT;
49
50 --connection C1
51 --reap
52
53 --connection C2
54 --reap
55 COMMIT;
56
57 --connection default
58 --disconnect C1
59 --disconnect C2
60 --disconnect C3
61
62 DROP TABLE t1;
63
64
65 # Scenario:
66 # C1 obtains implicit lock
67 # C2 notices the implicit lock and decides to do impl-to-expl conversion
68 # C1 XA Prepares
69 # C1 starts commit and pauses after removing itself from rw-list, but before
70 # (old code) changing state to TRX_STATE_COMMITED_IN_MEMORY
71 # (new code) removing explicit locks
72 # C3 ignores C1 (as it is no longer in rw-list) and adds own exclusive lock on
73 # the record
74 # C2 finishes impl-to-explicit conversion
75 # (at this point we have two X locks on the same row)
76
77 CREATE TABLE t1(id INT PRIMARY KEY) ENGINE=InnoDB;
78 INSERT INTO t1 (id) VALUES (1),(3);
79
80 --connect(C1,localhost,root,,test)
81 --connect(C2,localhost,root,,test)
82 --connect(C3,localhost,root,,test)
83
84 --connection C1
85 XA START "xid0";
86 INSERT INTO t1 (id) VALUES (2);
87
88 --connection C2
89 BEGIN;
90 SET DEBUG_SYNC = "before_lock_rec_convert_impl_to_expl_for_trx
91 SIGNAL c2_decided
92 WAIT_FOR c2_can_convert";
93 SET DEBUG_SYNC = "lock_wait_will_wait SIGNAL c2_will_wait";
94 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE
95
96 --connection C1
97 SET DEBUG_SYNC = "now WAIT_FOR c2_decided";
98 SET DEBUG_SYNC = "before_lock_trx_release_locks
99 SIGNAL c1_will_commit
100 WAIT_FOR c1_can_commit";
101 XA END "xid0";
102 XA PREPARE "xid0";
103 --send XA COMMIT "xid0"
104
105 --connection C3
106 BEGIN;
107 SET DEBUG_SYNC = "now WAIT_FOR c1_will_commit";
108 SELECT * FROM t1 WHERE id=2 FOR UPDATE;
109 SET DEBUG_SYNC = "now SIGNAL c2_can_convert";
110 SET DEBUG_SYNC = "now WAIT_FOR c2_will_wait";
111 SET DEBUG_SYNC = "now SIGNAL c1_can_commit";
112 COMMIT;
113
114 --connection C1
115 --reap
116
117 --connection C2
118 --reap
119 COMMIT;
120
121 --connection default
122 --disconnect C1
123 --disconnect C2
124 --disconnect C3
125
126 DROP TABLE t1;
127
128
129 # Scenario:
130 # C1 obtains implicit lock
131 # C2 notices the implicit lock and decides to do impl-to-expl conversion
132 # C1 starts commit and pauses after removing itself from rw-list, but before
133 # (old code) changing state to TRX_STATE_COMMITED_IN_MEMORY
134 # (new code) removing explicit locks
135 # C3 ignores C1 (as it is no longer in rw-list) and decides to add its own
136 # exclusive lock on the record
137 # C2 finishes impl-to-explicit conversion
138 # C3 proceeds to add its own lock
139 # C1 finishes commit
140 # C2 gets the lock granted and commits
141 # C3 gets the lock granted and commits
142
143
144 CREATE TABLE t1(id INT PRIMARY KEY) ENGINE=InnoDB;
145 INSERT INTO t1 (id) VALUES (1),(3);
146
147 --connect(C1,localhost,root,,test)
148 --connect(C2,localhost,root,,test)
149 --connect(C3,localhost,root,,test)
150
151 --connection C1
152 BEGIN;
153 INSERT INTO t1 (id) VALUES (2);
154
155 --connection C2
156 BEGIN;
157 SET DEBUG_SYNC = "before_lock_rec_convert_impl_to_expl_for_trx
158 SIGNAL c2_decided
159 WAIT_FOR c2_can_convert";
160 SET DEBUG_SYNC = "after_lock_rec_convert_impl_to_expl_for_trx
161 SIGNAL c2_done_conversion";
162 SET DEBUG_SYNC = "after_lock_clust_rec_read_check_and_lock
163 SIGNAL c2_done_locking";
164 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE
165
166 --connection C1
167 SET DEBUG_SYNC = "now WAIT_FOR c2_decided";
168 SET DEBUG_SYNC = "before_lock_trx_release_locks
169 SIGNAL c1_will_commit
170 WAIT_FOR c1_can_commit";
171 --send COMMIT
172
173 --connection C3
174 BEGIN;
175 SET DEBUG_SYNC = "now WAIT_FOR c1_will_commit";
176 SET DEBUG_SYNC = "lock_wait_will_wait SIGNAL c3_will_wait";
177 SET DEBUG_SYNC = "after_lock_clust_rec_read_check_and_lock_impl_to_expl
178 SIGNAL c3_will_lock
179 WAIT_FOR c3_can_lock";
180 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE
181
182 --connection default
183 SET DEBUG_SYNC = "now WAIT_FOR c3_will_lock";
184 SET DEBUG_SYNC = "now SIGNAL c2_can_convert";
185 SET DEBUG_SYNC = "now WAIT_FOR c2_done_conversion";
186 SET DEBUG_SYNC = "now WAIT_FOR c2_done_locking";
187 SET DEBUG_SYNC = "now SIGNAL c3_can_lock";
188 SET DEBUG_SYNC = "now WAIT_FOR c3_will_wait";
189 SET DEBUG_SYNC = "now SIGNAL c1_can_commit";
190 COMMIT;
191
192 --connection C1
193 --reap
194
195 --connection C2
196 --reap
197 COMMIT;
198
199 --connection C3
200 --reap
201 COMMIT;
202
203 --connection default
204 --disconnect C1
205 --disconnect C2
206 --disconnect C3
207
208 DROP TABLE t1;
209
210
211 # Scenario:
212 # C1 obtains implicit lock
213 # C2 notices the implicit lock and decides to do impl-to-expl conversion
214 # C1 PREPARES
215 # C1 starts commit and pauses after removing itself from rw-list, but before
216 # (old code) changing state to TRX_STATE_COMMITED_IN_MEMORY
217 # (new code) removing explicit locks
218 # C3 ignores C1 (as it is no longer in rw-list) and decides to adds own exclusive lock on the record
219 # C2 finishes impl-to-explicit conversion
220 # C3 proceeds to add its own lock
221 # C1 finishes commit
222 # C2 gets the lock granted and commits
223 # C3 gets the lock granted and commits
224
225
226 CREATE TABLE t1(id INT PRIMARY KEY) ENGINE=InnoDB;
227 INSERT INTO t1 (id) VALUES (1),(3);
228
229 --connect(C1,localhost,root,,test)
230 --connect(C2,localhost,root,,test)
231 --connect(C3,localhost,root,,test)
232
233 --connection C1
234 XA START "xid0";
235 INSERT INTO t1 (id) VALUES (2);
236
237 --connection C2
238 BEGIN;
239 SET DEBUG_SYNC = "before_lock_rec_convert_impl_to_expl_for_trx
240 SIGNAL c2_decided
241 WAIT_FOR c2_can_convert";
242 SET DEBUG_SYNC = "after_lock_rec_convert_impl_to_expl_for_trx
243 SIGNAL c2_done_conversion";
244 SET DEBUG_SYNC = "after_lock_clust_rec_read_check_and_lock
245 SIGNAL c2_done_locking";
246 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE
247
248 --connection C1
249 SET DEBUG_SYNC = "now WAIT_FOR c2_decided";
250 SET DEBUG_SYNC = "before_lock_trx_release_locks
251 SIGNAL c1_will_commit
252 WAIT_FOR c1_can_commit";
253 XA END "xid0";
254 XA PREPARE "xid0";
255 --send XA COMMIT "xid0"
256
257 --connection C3
258 BEGIN;
259 SET DEBUG_SYNC = "now WAIT_FOR c1_will_commit";
260 SET DEBUG_SYNC = "lock_wait_will_wait SIGNAL c3_will_wait";
261 SET DEBUG_SYNC = "after_lock_clust_rec_read_check_and_lock_impl_to_expl
262 SIGNAL c3_will_lock
263 WAIT_FOR c3_can_lock";
264 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE
265
266 --connection default
267 SET DEBUG_SYNC = "now WAIT_FOR c3_will_lock";
268 SET DEBUG_SYNC = "now SIGNAL c2_can_convert";
269 SET DEBUG_SYNC = "now WAIT_FOR c2_done_conversion";
270 SET DEBUG_SYNC = "now WAIT_FOR c2_done_locking";
271 SET DEBUG_SYNC = "now SIGNAL c3_can_lock";
272
273 SET DEBUG_SYNC = "now WAIT_FOR c3_will_wait";
274 SET DEBUG_SYNC = "now SIGNAL c1_can_commit";
275 COMMIT;
276
277 --connection C1
278 --reap
279
280 --connection C2
281 --reap
282 COMMIT;
283
284 --connection C3
285 --reap
286 COMMIT;
287
288 --connection default
289 --disconnect C1
290 --disconnect C2
291 --disconnect C3
292
293 DROP TABLE t1;
294
295
296 # Scenario:
297 # C1 obtains implicit lock
298 # C2 notices the implicit lock and decides to do validation
299 # C1 starts commit and pauses after removing itself from rw-list, but before
300 # (old code) changing state to TRX_STATE_COMMITED_IN_MEMORY
301 # (new code) removing explicit locks
302 # C3 ignores C1 (as it is no longer in rw-list) and adds own exclusive lock on
303 # the record
304 # C2 performs validation
305
306 CREATE TABLE t1(id INT PRIMARY KEY,val INT, KEY val(val)) ENGINE=InnoDB;
307 INSERT INTO t1 (id,val) VALUES (1,1),(3,3);
308
309 --connect(C1,localhost,root,,test)
310 --connect(C2,localhost,root,,test)
311 --connect(C3,localhost,root,,test)
312
313 --connection C1
314 BEGIN;
315 INSERT INTO t1 (id,val) VALUES (2,2);
316
317 --connection C2
318 BEGIN;
319 SET DEBUG_SYNC = "lock_rec_convert_impl_to_expl_will_validate
320 SIGNAL c2_decided
321 WAIT_FOR c2_can_validate";
322 SET DEBUG_SYNC = "lock_wait_will_wait SIGNAL c2_will_wait";
323 --send SELECT * FROM t1 WHERE val=2 FOR UPDATE
324
325 --connection C1
326 SET DEBUG_SYNC = "now WAIT_FOR c2_decided";
327 SET DEBUG_SYNC = "before_lock_trx_release_locks
328 SIGNAL c1_will_commit
329 WAIT_FOR c1_can_commit";
330 --send COMMIT
331
332 --connection C3
333 BEGIN;
334 SET DEBUG_SYNC = "now WAIT_FOR c1_will_commit";
335 SELECT * FROM t1 WHERE val=2 FOR UPDATE;
336 SET DEBUG_SYNC = "now SIGNAL c2_can_validate";
337 SET DEBUG_SYNC = "now WAIT_FOR c2_will_wait";
338 SET DEBUG_SYNC = "now SIGNAL c1_can_commit";
339 COMMIT;
340
341 --connection C1
342 --reap
343
344 --connection C2
345 --reap
346 COMMIT;
347
348 --connection default
349 --disconnect C1
350 --disconnect C2
351 --disconnect C3
352
353 DROP TABLE t1;
354
355 # Scenario:
356 # C1 obtains implicit lock
357 # C2 notices the implicit lock and decides to do impl-to-expl conversion
358 # C1 starts commit and pauses after trx_erase_lists
359 # C3 ignores C1 (as it is no longer in rw-list) and adds own exclusive lock on
360 # the record
361 # C2 finishes impl-to-explicit conversion
362 # (at this point we have two X locks on the same row)
363
364 CREATE TABLE t1(id INT PRIMARY KEY) ENGINE=InnoDB;
365 INSERT INTO t1 (id) VALUES (1),(3);
366
367 --connect(C1,localhost,root,,test)
368 --connect(C2,localhost,root,,test)
369 --connect(C3,localhost,root,,test)
370
371 --connection C1
372 BEGIN;
373 INSERT INTO t1 (id) VALUES (2);
374
375 --connection C3
376 #ensure that C3 has assigned trx->id before we start hogging the trx_sys->mutex
377 BEGIN;
378 INSERT INTO t1 (id) VALUES (4);
379
380 --connection C2
381 BEGIN;
382 SET DEBUG_SYNC = "before_lock_rec_convert_impl_to_expl_for_trx
383 SIGNAL c2_decided
384 WAIT_FOR c2_can_convert";
385 SET DEBUG_SYNC = "after_lock_clust_rec_read_check_and_lock SIGNAL c2_will_wait";
386 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE
387
388 --connection C1
389 SET DEBUG_SYNC = "now WAIT_FOR c2_decided";
390 SET DEBUG_SYNC = "after_trx_erase_lists
391 SIGNAL c1_will_commit
392 WAIT_FOR c1_can_commit";
393 --send COMMIT
394
395 --connection C3
396 SET DEBUG_SYNC = "now WAIT_FOR c1_will_commit";
397 SET DEBUG_SYNC = "after_lock_clust_rec_read_check_and_lock SIGNAL c2_can_convert WAIT_FOR c3_can_verify";
398 --send SELECT * FROM t1 WHERE id=2 FOR UPDATE;
399
400 --connection default
401 SET DEBUG_SYNC = "now WAIT_FOR c2_will_wait";
402 SET DEBUG_SYNC = "now SIGNAL c1_can_commit";
403 SET DEBUG_SYNC = "now SIGNAL c3_can_verify";
404
405 --connection C3
406 --reap
407 COMMIT;
408
409 --connection C1
410 --reap
411
412 --connection C2
413 --reap
414 COMMIT;
415
416 --connection default
417 --disconnect C1
418 --disconnect C2
419 --disconnect C3
420
421 DROP TABLE t1;
422
423 --source include/wait_until_count_sessions.inc