~vadim-tk/percona-server/percona-5.5.15-galera

« back to all changes in this revision

Viewing changes to mysql-test/t/mdl_sync.test

  • Committer: root
  • Date: 2011-09-10 16:37:18 UTC
  • Revision ID: root@r815.office.percona.com-20110910163718-ydh4zj8hcdgoyavb
Porting Galera to 5.5.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# We need the Debug Sync Facility.
 
3
#
 
4
--source include/have_debug_sync.inc
 
5
 
 
6
# We need InnoDB tables for some of the tests.
 
7
--source include/have_innodb.inc
 
8
 
 
9
# Save the initial number of concurrent sessions.
 
10
--source include/count_sessions.inc
 
11
 
 
12
 
 
13
# Clean up resources used in this test case.
 
14
--disable_warnings
 
15
SET DEBUG_SYNC= 'RESET';
 
16
--enable_warnings
 
17
 
 
18
#
 
19
# Test the case of when a exclusive lock request waits for a
 
20
# shared lock being upgraded to a exclusive lock.
 
21
#
 
22
 
 
23
connect (con1,localhost,root,,test,,);
 
24
connect (con2,localhost,root,,test,,);
 
25
connect (con3,localhost,root,,test,,);
 
26
 
 
27
connection default;
 
28
 
 
29
--disable_warnings
 
30
drop table if exists t1,t2,t3;
 
31
--enable_warnings
 
32
 
 
33
create table t1 (i int);
 
34
create table t2 (i int);
 
35
 
 
36
--echo connection: default
 
37
lock tables t2 read;
 
38
 
 
39
connection con1;
 
40
--echo connection: con1
 
41
set debug_sync='mdl_upgrade_shared_lock_to_exclusive SIGNAL parked WAIT_FOR go';
 
42
--send alter table t1 rename t3
 
43
 
 
44
connection default;
 
45
--echo connection: default
 
46
set debug_sync= 'now WAIT_FOR parked';
 
47
 
 
48
connection con2;
 
49
--echo connection: con2
 
50
set debug_sync='mdl_acquire_lock_wait SIGNAL go';
 
51
--send drop table t1,t2
 
52
 
 
53
connection con1;
 
54
--echo connection: con1
 
55
--reap
 
56
 
 
57
connection default;
 
58
--echo connection: default
 
59
unlock tables;
 
60
 
 
61
connection con2;
 
62
--echo connection: con2
 
63
--error ER_BAD_TABLE_ERROR
 
64
--reap
 
65
 
 
66
connection default;
 
67
drop table t3;
 
68
 
 
69
disconnect con1;
 
70
disconnect con2;
 
71
disconnect con3;
 
72
 
 
73
# Clean up resources used in this test case.
 
74
--disable_warnings
 
75
SET DEBUG_SYNC= 'RESET';
 
76
--enable_warnings
 
77
 
 
78
 
 
79
--echo #
 
80
--echo # Basic test coverage for type-of-operation aware metadata locks.
 
81
--echo #
 
82
--disable_warnings
 
83
drop table if exists t1, t2, t3;
 
84
--enable_warnings
 
85
connect(mdl_con1,localhost,root,,);
 
86
connect(mdl_con2,localhost,root,,);
 
87
connect(mdl_con3,localhost,root,,);
 
88
connection default;
 
89
set debug_sync= 'RESET';
 
90
create table t1 (c1 int);
 
91
 
 
92
--echo # 
 
93
--echo # A) First let us check compatibility rules between differend kinds of
 
94
--echo #    type-of-operation aware metadata locks.
 
95
--echo #    Of course, these rules are already covered by the tests scattered
 
96
--echo #    across the test suite. But it still makes sense to have one place
 
97
--echo #    which covers all of them.
 
98
--echo #
 
99
 
 
100
--echo # 1) Acquire S (simple shared) lock on the table (by using HANDLER):
 
101
--echo #
 
102
handler t1 open;
 
103
--echo # 
 
104
--echo # Switching to connection 'mdl_con1'.
 
105
connection mdl_con1;
 
106
--echo # Check that S, SH, SR and SW locks are compatible with it.
 
107
handler t1 open t;
 
108
handler t close;
 
109
select column_name from information_schema.columns where
 
110
  table_schema='test' and table_name='t1';
 
111
select count(*) from t1;
 
112
insert into t1 values (1), (1);
 
113
--echo # Check that SNW lock is compatible with it. To do this use ALTER TABLE
 
114
--echo # which will fail after opening the table and thus obtaining SNW metadata
 
115
--echo # lock.
 
116
--error ER_DUP_ENTRY
 
117
alter table t1 add primary key (c1);
 
118
--echo # Check that SNRW lock is compatible with S lock.
 
119
lock table t1 write;
 
120
insert into t1 values (1);
 
121
unlock tables;
 
122
--echo # Check that X lock is incompatible with S lock.
 
123
--echo # Sending:
 
124
--send rename table t1 to t2;
 
125
--echo # 
 
126
--echo # Switching to connection 'mdl_con2'.
 
127
connection mdl_con2;
 
128
--echo # Check that the above RENAME is blocked because of S lock.
 
129
let $wait_condition=
 
130
  select count(*) = 1 from information_schema.processlist
 
131
  where state = "Waiting for table metadata lock" and
 
132
        info = "rename table t1 to t2";
 
133
--source include/wait_condition.inc
 
134
--echo # 
 
135
--echo # Switching to connection 'default'.
 
136
connection default;
 
137
--echo # Unblock RENAME TABLE.
 
138
handler t1 close;
 
139
--echo # 
 
140
--echo # Switching to connection 'mdl_con1'.
 
141
connection mdl_con1;
 
142
--echo # Reaping RENAME TABLE.
 
143
--reap
 
144
--echo # Restore the original state of the things.
 
145
rename table t2 to t1;
 
146
--echo # 
 
147
--echo # Switching to connection 'default'.
 
148
connection default;
 
149
handler t1 open;
 
150
--echo # 
 
151
--echo # Switching to connection 'mdl_con1'.
 
152
connection mdl_con1;
 
153
--echo # Check that upgrade from SNW to X is blocked by presence of S lock.
 
154
--echo # Sending:
 
155
--send alter table t1 add column c2 int;
 
156
--echo # 
 
157
--echo # Switching to connection 'mdl_con2'.
 
158
connection mdl_con2;
 
159
--echo # Check that the above ALTER TABLE is blocked because of S lock.
 
160
let $wait_condition=
 
161
  select count(*) = 1 from information_schema.processlist
 
162
  where state = "Waiting for table metadata lock" and
 
163
        info = "alter table t1 add column c2 int";
 
164
--source include/wait_condition.inc
 
165
--echo # 
 
166
--echo # Switching to connection 'default'.
 
167
connection default;
 
168
--echo # Unblock ALTER TABLE.
 
169
handler t1 close;
 
170
--echo # 
 
171
--echo # Switching to connection 'mdl_con1'.
 
172
connection mdl_con1;
 
173
--echo # Reaping ALTER TABLE.
 
174
--reap
 
175
--echo # Restore the original state of the things.
 
176
alter table t1 drop column c2;
 
177
--echo # 
 
178
--echo # Switching to connection 'default'.
 
179
connection default;
 
180
handler t1 open;
 
181
--echo # 
 
182
--echo # Switching to connection 'mdl_con1'.
 
183
connection mdl_con1;
 
184
--echo # Check that upgrade from SNRW to X is blocked by presence of S lock.
 
185
lock table t1 write;
 
186
--echo # Sending:
 
187
--send alter table t1 add column c2 int;
 
188
--echo # 
 
189
--echo # Switching to connection 'mdl_con2'.
 
190
connection mdl_con2;
 
191
--echo # Check that the above upgrade of SNRW to X in ALTER TABLE is blocked
 
192
--echo # because of S lock.
 
193
let $wait_condition=
 
194
  select count(*) = 1 from information_schema.processlist
 
195
  where state = "Waiting for table metadata lock" and
 
196
        info = "alter table t1 add column c2 int";
 
197
--source include/wait_condition.inc
 
198
--echo # 
 
199
--echo # Switching to connection 'default'.
 
200
connection default;
 
201
--echo # Unblock ALTER TABLE.
 
202
handler t1 close;
 
203
--echo # 
 
204
--echo # Switching to connection 'mdl_con1'.
 
205
connection mdl_con1;
 
206
--echo # Reaping ALTER TABLE.
 
207
--reap
 
208
--echo # Restore the original state of the things.
 
209
alter table t1 drop column c2;
 
210
unlock tables;
 
211
--echo # 
 
212
--echo # Switching to connection 'default'.
 
213
connection default;
 
214
--echo #
 
215
--echo # 2) Acquire SH (shared high-priority) lock on the table.
 
216
--echo #    We have to involve DEBUG_SYNC facility for this as usually
 
217
--echo #    such kind of locks are short-lived.
 
218
--echo #
 
219
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
220
--echo # Sending:
 
221
--send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t1';
 
222
--echo # 
 
223
--echo # Switching to connection 'mdl_con1'.
 
224
connection mdl_con1;
 
225
set debug_sync= 'now WAIT_FOR locked';
 
226
--echo # Check that S, SH, SR and SW locks are compatible with it.
 
227
handler t1 open;
 
228
handler t1 close;
 
229
select column_name from information_schema.columns where
 
230
  table_schema='test' and table_name='t1';
 
231
select count(*) from t1;
 
232
insert into t1 values (1);
 
233
--echo # Check that SNW lock is compatible with it. To do this use ALTER TABLE
 
234
--echo # which will fail after opening the table and thus obtaining SNW metadata
 
235
--echo # lock.
 
236
--error ER_DUP_ENTRY
 
237
alter table t1 add primary key (c1);
 
238
--echo # Check that SNRW lock is compatible with SH lock.
 
239
lock table t1 write;
 
240
delete from t1 limit 1;
 
241
unlock tables;
 
242
--echo # Check that X lock is incompatible with SH lock.
 
243
--echo # Sending:
 
244
--send rename table t1 to t2;
 
245
--echo # 
 
246
--echo # Switching to connection 'mdl_con2'.
 
247
connection mdl_con2;
 
248
--echo # Check that the above RENAME is blocked because of SH lock.
 
249
let $wait_condition=
 
250
  select count(*) = 1 from information_schema.processlist
 
251
  where state = "Waiting for table metadata lock" and
 
252
        info = "rename table t1 to t2";
 
253
--source include/wait_condition.inc
 
254
--echo # Unblock RENAME TABLE.
 
255
set debug_sync= 'now SIGNAL finish';
 
256
--echo # 
 
257
--echo # Switching to connection 'default'.
 
258
connection default;
 
259
--echo # Reaping SELECT ... FROM I_S.
 
260
--reap
 
261
--echo # 
 
262
--echo # Switching to connection 'mdl_con1'.
 
263
connection mdl_con1;
 
264
--echo # Reaping RENAME TABLE.
 
265
--reap
 
266
--echo # Restore the original state of the things.
 
267
rename table t2 to t1;
 
268
--echo # 
 
269
--echo # Switching to connection 'default'.
 
270
connection default;
 
271
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
272
--echo # Sending:
 
273
--send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t1';
 
274
--echo # 
 
275
--echo # Switching to connection 'mdl_con1'.
 
276
connection mdl_con1;
 
277
set debug_sync= 'now WAIT_FOR locked';
 
278
--echo # Check that upgrade from SNW to X is blocked by presence of SH lock.
 
279
--echo # Sending:
 
280
--send alter table t1 add column c2 int;
 
281
--echo # 
 
282
--echo # Switching to connection 'mdl_con2'.
 
283
connection mdl_con2;
 
284
--echo # Check that the above ALTER TABLE is blocked because of SH lock.
 
285
let $wait_condition=
 
286
  select count(*) = 1 from information_schema.processlist
 
287
  where state = "Waiting for table metadata lock" and
 
288
        info = "alter table t1 add column c2 int";
 
289
--source include/wait_condition.inc
 
290
--echo # Unblock RENAME TABLE.
 
291
set debug_sync= 'now SIGNAL finish';
 
292
--echo # 
 
293
--echo # Switching to connection 'default'.
 
294
connection default;
 
295
--echo # Reaping SELECT ... FROM I_S.
 
296
--reap
 
297
--echo # 
 
298
--echo # Switching to connection 'mdl_con1'.
 
299
connection mdl_con1;
 
300
--echo # Reaping ALTER TABLE.
 
301
--reap
 
302
--echo # Restore the original state of the things.
 
303
alter table t1 drop column c2;
 
304
--echo # 
 
305
--echo # Switching to connection 'default'.
 
306
connection default;
 
307
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
308
--send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t1';
 
309
--echo # 
 
310
--echo # Switching to connection 'mdl_con1'.
 
311
connection mdl_con1;
 
312
set debug_sync= 'now WAIT_FOR locked';
 
313
--echo # Check that upgrade from SNRW to X is blocked by presence of S lock.
 
314
lock table t1 write;
 
315
--echo # Sending:
 
316
--send alter table t1 add column c2 int;
 
317
--echo # 
 
318
--echo # Switching to connection 'mdl_con2'.
 
319
connection mdl_con2;
 
320
--echo # Check that the above upgrade of SNRW to X in ALTER TABLE is blocked
 
321
--echo # because of S lock.
 
322
let $wait_condition=
 
323
  select count(*) = 1 from information_schema.processlist
 
324
  where state = "Waiting for table metadata lock" and
 
325
        info = "alter table t1 add column c2 int";
 
326
--source include/wait_condition.inc
 
327
--echo # Unblock RENAME TABLE.
 
328
set debug_sync= 'now SIGNAL finish';
 
329
--echo # 
 
330
--echo # Switching to connection 'default'.
 
331
connection default;
 
332
--echo # Reaping SELECT ... FROM I_S.
 
333
--reap
 
334
--echo # 
 
335
--echo # Switching to connection 'mdl_con1'.
 
336
connection mdl_con1;
 
337
--echo # Reaping ALTER TABLE.
 
338
--reap
 
339
--echo # Restore the original state of the things.
 
340
alter table t1 drop column c2;
 
341
unlock tables;
 
342
--echo # 
 
343
--echo # Switching to connection 'default'.
 
344
connection default;
 
345
--echo #
 
346
--echo #
 
347
--echo # 3) Acquire SR lock on the table.
 
348
--echo #
 
349
--echo #
 
350
begin;
 
351
select count(*) from t1;
 
352
--echo # 
 
353
--echo # Switching to connection 'mdl_con1'.
 
354
connection mdl_con1;
 
355
--echo # Check that S, SH, SR and SW locks are compatible with it.
 
356
handler t1 open;
 
357
handler t1 close;
 
358
select column_name from information_schema.columns where
 
359
  table_schema='test' and table_name='t1';
 
360
select count(*) from t1;
 
361
insert into t1 values (1);
 
362
--echo # Check that SNW lock is compatible with it. To do this use ALTER TABLE
 
363
--echo # which will fail after opening the table and thus obtaining SNW metadata
 
364
--echo # lock.
 
365
--error ER_DUP_ENTRY
 
366
alter table t1 add primary key (c1);
 
367
--echo # Check that SNRW lock is not compatible with SR lock.
 
368
--echo # Sending:
 
369
--send lock table t1 write;
 
370
--echo # 
 
371
--echo # Switching to connection 'default'.
 
372
connection default;
 
373
--echo # Check that the above LOCK TABLES is blocked because of SR lock.
 
374
let $wait_condition=
 
375
  select count(*) = 1 from information_schema.processlist
 
376
  where state = "Waiting for table metadata lock" and 
 
377
        info = "lock table t1 write";
 
378
--source include/wait_condition.inc
 
379
--echo # Unblock LOCK TABLES.
 
380
commit;
 
381
--echo # 
 
382
--echo # Switching to connection 'mdl_con1'.
 
383
connection mdl_con1;
 
384
--echo # Reaping LOCK TABLES.
 
385
--reap
 
386
delete from t1 limit 1;
 
387
unlock tables;
 
388
--echo # 
 
389
--echo # Switching to connection 'default'.
 
390
connection default;
 
391
begin;
 
392
select count(*) from t1;
 
393
--echo # 
 
394
--echo # Switching to connection 'mdl_con1'.
 
395
connection mdl_con1;
 
396
--echo # Check that X lock is incompatible with SR lock.
 
397
--echo # Sending:
 
398
--send rename table t1 to t2;
 
399
--echo # 
 
400
--echo # Switching to connection 'mdl_con2'.
 
401
connection mdl_con2;
 
402
--echo # Check that the above RENAME is blocked because of SR lock.
 
403
let $wait_condition=
 
404
  select count(*) = 1 from information_schema.processlist
 
405
  where state = "Waiting for table metadata lock" and
 
406
        info = "rename table t1 to t2";
 
407
--source include/wait_condition.inc
 
408
--echo # 
 
409
--echo # Switching to connection 'default'.
 
410
connection default;
 
411
--echo # Unblock RENAME TABLE.
 
412
commit;
 
413
--echo # 
 
414
--echo # Switching to connection 'mdl_con1'.
 
415
connection mdl_con1;
 
416
--echo # Reaping RENAME TABLE.
 
417
--reap
 
418
--echo # Restore the original state of the things.
 
419
rename table t2 to t1;
 
420
--echo # 
 
421
--echo # Switching to connection 'default'.
 
422
connection default;
 
423
begin;
 
424
select count(*) from t1;
 
425
--echo # 
 
426
--echo # Switching to connection 'mdl_con1'.
 
427
connection mdl_con1;
 
428
--echo # Check that upgrade from SNW to X is blocked by presence of SR lock.
 
429
--echo # Sending:
 
430
--send alter table t1 add column c2 int;
 
431
--echo # 
 
432
--echo # Switching to connection 'mdl_con2'.
 
433
connection mdl_con2;
 
434
--echo # Check that the above ALTER TABLE is blocked because of SR lock.
 
435
let $wait_condition=
 
436
  select count(*) = 1 from information_schema.processlist
 
437
  where state = "Waiting for table metadata lock" and
 
438
        info = "alter table t1 add column c2 int";
 
439
--source include/wait_condition.inc
 
440
--echo # 
 
441
--echo # Switching to connection 'default'.
 
442
connection default;
 
443
--echo # Unblock ALTER TABLE.
 
444
commit;
 
445
--echo # 
 
446
--echo # Switching to connection 'mdl_con1'.
 
447
connection mdl_con1;
 
448
--echo # Reaping ALTER TABLE.
 
449
--reap
 
450
--echo # Restore the original state of the things.
 
451
alter table t1 drop column c2;
 
452
--echo #
 
453
--echo # There is no need to check that upgrade from SNRW to X is blocked
 
454
--echo # by presence of SR lock because SNRW is incompatible with SR anyway.
 
455
--echo # 
 
456
--echo # 
 
457
--echo # Switching to connection 'default'.
 
458
connection default;
 
459
--echo #
 
460
--echo #
 
461
--echo # 4) Acquire SW lock on the table.
 
462
--echo #
 
463
--echo #
 
464
begin;
 
465
insert into t1 values (1);
 
466
--echo # 
 
467
--echo # Switching to connection 'mdl_con1'.
 
468
connection mdl_con1;
 
469
--echo # Check that S, SH, SR and SW locks are compatible with it.
 
470
handler t1 open;
 
471
handler t1 close;
 
472
select column_name from information_schema.columns where
 
473
  table_schema='test' and table_name='t1';
 
474
--echo # Disable result log to make test robust against
 
475
--echo # effects of concurrent insert.
 
476
--disable_result_log
 
477
select * from t1;
 
478
--enable_result_log
 
479
insert into t1 values (1);
 
480
--echo # Check that SNW lock is not compatible with SW lock.
 
481
--echo # Again we use ALTER TABLE which fails after opening
 
482
--echo # the table to avoid upgrade of SNW -> X.
 
483
--echo # Sending:
 
484
--send alter table t1 add primary key (c1);
 
485
--echo # 
 
486
--echo # Switching to connection 'default'.
 
487
connection default;
 
488
--echo # Check that the above ALTER TABLE is blocked because of SW lock.
 
489
let $wait_condition=
 
490
  select count(*) = 1 from information_schema.processlist
 
491
  where state = "Waiting for table metadata lock" and
 
492
        info = "alter table t1 add primary key (c1)";
 
493
--source include/wait_condition.inc
 
494
--echo # Unblock ALTER TABLE.
 
495
commit;
 
496
--echo # 
 
497
--echo # Switching to connection 'mdl_con1'.
 
498
connection mdl_con1;
 
499
--echo # Reaping ALTER TABLE.
 
500
--error ER_DUP_ENTRY
 
501
--reap
 
502
--echo # 
 
503
--echo # Switching to connection 'default'.
 
504
connection default;
 
505
begin;
 
506
insert into t1 values (1);
 
507
--echo # 
 
508
--echo # Switching to connection 'mdl_con1'.
 
509
connection mdl_con1;
 
510
--echo # Check that SNRW lock is not compatible with SW lock.
 
511
--echo # Sending:
 
512
--send lock table t1 write;
 
513
--echo # 
 
514
--echo # Switching to connection 'default'.
 
515
connection default;
 
516
--echo # Check that the above LOCK TABLES is blocked because of SW lock.
 
517
let $wait_condition=
 
518
  select count(*) = 1 from information_schema.processlist
 
519
  where state = "Waiting for table metadata lock" and
 
520
        info = "lock table t1 write";
 
521
--source include/wait_condition.inc
 
522
--echo # Unblock LOCK TABLES.
 
523
commit;
 
524
--echo # 
 
525
--echo # Switching to connection 'mdl_con1'.
 
526
connection mdl_con1;
 
527
--echo # Reaping LOCK TABLES.
 
528
--reap
 
529
delete from t1 limit 2;
 
530
unlock tables;
 
531
--echo # 
 
532
--echo # Switching to connection 'default'.
 
533
connection default;
 
534
begin;
 
535
insert into t1 values (1);
 
536
--echo # 
 
537
--echo # Switching to connection 'mdl_con1'.
 
538
connection mdl_con1;
 
539
--echo # Check that X lock is incompatible with SW lock.
 
540
--echo # Sending:
 
541
--send rename table t1 to t2;
 
542
--echo # 
 
543
--echo # Switching to connection 'mdl_con2'.
 
544
connection mdl_con2;
 
545
--echo # Check that the above RENAME is blocked because of SW lock.
 
546
let $wait_condition=
 
547
  select count(*) = 1 from information_schema.processlist
 
548
  where state = "Waiting for table metadata lock" and
 
549
        info = "rename table t1 to t2";
 
550
--source include/wait_condition.inc
 
551
--echo # 
 
552
--echo # Switching to connection 'default'.
 
553
connection default;
 
554
--echo # Unblock RENAME TABLE.
 
555
commit;
 
556
--echo # 
 
557
--echo # Switching to connection 'mdl_con1'.
 
558
connection mdl_con1;
 
559
--echo # Reaping RENAME TABLE.
 
560
--reap
 
561
--echo # Restore the original state of the things.
 
562
rename table t2 to t1;
 
563
--echo #
 
564
--echo # There is no need to check that upgrade from SNW/SNRW to X is
 
565
--echo # blocked by presence of SW lock because SNW/SNRW is incompatible
 
566
--echo # with SW anyway.
 
567
--echo # 
 
568
--echo # 
 
569
--echo # Switching to connection 'default'.
 
570
connection default;
 
571
--echo #
 
572
--echo #
 
573
--echo # 5) Acquire SNW lock on the table. We have to use DEBUG_SYNC for
 
574
--echo #    this, to prevent SNW from being immediately upgraded to X.
 
575
--echo #
 
576
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
577
--echo # Sending:
 
578
--send alter table t1 add primary key (c1);
 
579
--echo # 
 
580
--echo # Switching to connection 'mdl_con1'.
 
581
connection mdl_con1;
 
582
set debug_sync= 'now WAIT_FOR locked';
 
583
--echo # Check that S, SH and SR locks are compatible with it.
 
584
handler t1 open;
 
585
handler t1 close;
 
586
select column_name from information_schema.columns where
 
587
  table_schema='test' and table_name='t1';
 
588
select count(*) from t1;
 
589
--echo # Check that SW lock is incompatible with SNW lock.
 
590
--echo # Sending:
 
591
--send delete from t1 limit 2;
 
592
--echo # 
 
593
--echo # Switching to connection 'mdl_con2'.
 
594
connection mdl_con2;
 
595
--echo # Check that the above DELETE is blocked because of SNW lock.
 
596
let $wait_condition=
 
597
  select count(*) = 1 from information_schema.processlist
 
598
  where state = "Waiting for table metadata lock" and
 
599
        info = "delete from t1 limit 2";
 
600
--source include/wait_condition.inc
 
601
--echo # Unblock ALTER and thus DELETE.
 
602
set debug_sync= 'now SIGNAL finish';
 
603
--echo # 
 
604
--echo # Switching to connection 'default'.
 
605
connection default;
 
606
--echo # Reaping ALTER TABLE.
 
607
--error ER_DUP_ENTRY
 
608
--reap
 
609
--echo # 
 
610
--echo # Switching to connection 'mdl_con1'.
 
611
connection mdl_con1;
 
612
--echo # Reaping DELETE.
 
613
--reap
 
614
--echo # 
 
615
--echo # Switching to connection 'default'.
 
616
connection default;
 
617
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
618
--echo # Sending:
 
619
--send alter table t1 add primary key (c1);
 
620
--echo # 
 
621
--echo # Switching to connection 'mdl_con1'.
 
622
connection mdl_con1;
 
623
set debug_sync= 'now WAIT_FOR locked';
 
624
--echo # Check that SNW lock is incompatible with SNW lock.
 
625
--echo # Sending:
 
626
--send alter table t1 add primary key (c1);
 
627
--echo # 
 
628
--echo # Switching to connection 'mdl_con2'.
 
629
connection mdl_con2;
 
630
--echo # Check that the above ALTER is blocked because of SNW lock.
 
631
let $wait_condition=
 
632
  select count(*) = 1 from information_schema.processlist
 
633
  where state = "Waiting for table metadata lock" and
 
634
        info = "alter table t1 add primary key (c1)";
 
635
--source include/wait_condition.inc
 
636
--echo # Unblock ALTERs.
 
637
set debug_sync= 'now SIGNAL finish';
 
638
--echo # 
 
639
--echo # Switching to connection 'default'.
 
640
connection default;
 
641
--echo # Reaping first ALTER TABLE.
 
642
--error ER_DUP_ENTRY
 
643
--reap
 
644
--echo # 
 
645
--echo # Switching to connection 'mdl_con1'.
 
646
connection mdl_con1;
 
647
--echo # Reaping another ALTER TABLE.
 
648
--error ER_DUP_ENTRY
 
649
--reap
 
650
--echo # 
 
651
--echo # Switching to connection 'default'.
 
652
connection default;
 
653
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
654
--echo # Sending:
 
655
--send alter table t1 add primary key (c1);
 
656
--echo # 
 
657
--echo # Switching to connection 'mdl_con1'.
 
658
connection mdl_con1;
 
659
set debug_sync= 'now WAIT_FOR locked';
 
660
--echo # Check that SNRW lock is incompatible with SNW lock.
 
661
--echo # Sending:
 
662
--send lock table t1 write;
 
663
--echo # 
 
664
--echo # Switching to connection 'mdl_con2'.
 
665
connection mdl_con2;
 
666
--echo # Check that the above LOCK TABLES is blocked because of SNW lock.
 
667
let $wait_condition=
 
668
  select count(*) = 1 from information_schema.processlist
 
669
  where state = "Waiting for table metadata lock" and
 
670
        info = "lock table t1 write";
 
671
--source include/wait_condition.inc
 
672
--echo # Unblock ALTER and thus LOCK TABLES.
 
673
set debug_sync= 'now SIGNAL finish';
 
674
--echo # 
 
675
--echo # Switching to connection 'default'.
 
676
connection default;
 
677
--echo # Reaping ALTER TABLE.
 
678
--error ER_DUP_ENTRY
 
679
--reap
 
680
--echo # 
 
681
--echo # Switching to connection 'mdl_con1'.
 
682
connection mdl_con1;
 
683
--echo # Reaping LOCK TABLES
 
684
--reap
 
685
insert into t1 values (1);
 
686
unlock tables;
 
687
--echo # 
 
688
--echo # Switching to connection 'default'.
 
689
connection default;
 
690
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
691
--echo # Sending:
 
692
--send alter table t1 add primary key (c1);
 
693
--echo # 
 
694
--echo # Switching to connection 'mdl_con1'.
 
695
connection mdl_con1;
 
696
set debug_sync= 'now WAIT_FOR locked';
 
697
--echo # Check that X lock is incompatible with SNW lock.
 
698
--echo # Sending:
 
699
--send rename table t1 to t2;
 
700
--echo # 
 
701
--echo # Switching to connection 'mdl_con2'.
 
702
connection mdl_con2;
 
703
--echo # Check that the above RENAME is blocked because of SNW lock.
 
704
let $wait_condition=
 
705
  select count(*) = 1 from information_schema.processlist
 
706
  where state = "Waiting for table metadata lock" and
 
707
        info = "rename table t1 to t2";
 
708
--source include/wait_condition.inc
 
709
--echo # Unblock ALTER and thus RENAME TABLE.
 
710
set debug_sync= 'now SIGNAL finish';
 
711
--echo # 
 
712
--echo # Switching to connection 'default'.
 
713
connection default;
 
714
--echo # Reaping ALTER TABLE.
 
715
--error ER_DUP_ENTRY
 
716
--reap
 
717
--echo # 
 
718
--echo # Switching to connection 'mdl_con1'.
 
719
connection mdl_con1;
 
720
--echo # Reaping RENAME TABLE
 
721
--reap
 
722
--echo # Revert back to original state of things.
 
723
rename table t2 to t1;
 
724
--echo #
 
725
--echo # There is no need to check that upgrade from SNW/SNRW to X is
 
726
--echo # blocked by presence of another SNW lock because SNW/SNRW is
 
727
--echo # incompatible with SNW anyway.
 
728
--echo # 
 
729
--echo # Switching to connection 'default'.
 
730
connection default;
 
731
--echo #
 
732
--echo #
 
733
--echo # 6) Acquire SNRW lock on the table. 
 
734
--echo #
 
735
--echo #
 
736
lock table t1 write;
 
737
--echo # 
 
738
--echo # Switching to connection 'mdl_con1'.
 
739
connection mdl_con1;
 
740
--echo # Check that S and SH locks are compatible with it.
 
741
handler t1 open;
 
742
handler t1 close;
 
743
select column_name from information_schema.columns where
 
744
  table_schema='test' and table_name='t1';
 
745
--echo # Check that SR lock is incompatible with SNRW lock.
 
746
--echo # Sending:
 
747
--send select count(*) from t1;
 
748
--echo # 
 
749
--echo # Switching to connection 'default'.
 
750
connection default;
 
751
--echo # Check that the above SELECT is blocked because of SNRW lock.
 
752
let $wait_condition=
 
753
  select count(*) = 1 from information_schema.processlist
 
754
  where state = "Waiting for table metadata lock" and
 
755
        info = "select count(*) from t1";
 
756
--source include/wait_condition.inc
 
757
--echo # Unblock SELECT.
 
758
unlock tables;
 
759
--echo # 
 
760
--echo # Switching to connection 'mdl_con1'.
 
761
connection mdl_con1;
 
762
--echo # Reaping SELECT.
 
763
--reap
 
764
--echo # 
 
765
--echo # Switching to connection 'default'.
 
766
connection default;
 
767
lock table t1 write;
 
768
--echo # 
 
769
--echo # Switching to connection 'mdl_con1'.
 
770
connection mdl_con1;
 
771
--echo # Check that SW lock is incompatible with SNRW lock.
 
772
--echo # Sending:
 
773
--send delete from t1 limit 1;
 
774
--echo # 
 
775
--echo # Switching to connection 'default'.
 
776
connection default;
 
777
--echo # Check that the above DELETE is blocked because of SNRW lock.
 
778
let $wait_condition=
 
779
  select count(*) = 1 from information_schema.processlist
 
780
  where state = "Waiting for table metadata lock" and
 
781
        info = "delete from t1 limit 1";
 
782
--source include/wait_condition.inc
 
783
--echo # Unblock DELETE.
 
784
unlock tables;
 
785
--echo # 
 
786
--echo # Switching to connection 'mdl_con1'.
 
787
connection mdl_con1;
 
788
--echo # Reaping DELETE.
 
789
--reap
 
790
--echo # 
 
791
--echo # Switching to connection 'default'.
 
792
connection default;
 
793
lock table t1 write;
 
794
--echo # 
 
795
--echo # Switching to connection 'mdl_con1'.
 
796
connection mdl_con1;
 
797
--echo # Check that SNW lock is incompatible with SNRW lock.
 
798
--echo # Sending:
 
799
--send alter table t1 add primary key (c1);
 
800
--echo # 
 
801
--echo # Switching to connection 'default'.
 
802
connection default;
 
803
--echo # Check that the above ALTER is blocked because of UNWR lock.
 
804
let $wait_condition=
 
805
  select count(*) = 1 from information_schema.processlist
 
806
  where state = "Waiting for table metadata lock" and
 
807
        info = "alter table t1 add primary key (c1)";
 
808
--source include/wait_condition.inc
 
809
--echo # Unblock ALTER.
 
810
unlock tables;
 
811
--echo # 
 
812
--echo # Switching to connection 'mdl_con1'.
 
813
connection mdl_con1;
 
814
--echo # Reaping ALTER TABLE.
 
815
--error ER_DUP_ENTRY
 
816
--reap
 
817
--echo # 
 
818
--echo # Switching to connection 'default'.
 
819
connection default;
 
820
lock table t1 write;
 
821
--echo # 
 
822
--echo # Switching to connection 'mdl_con1'.
 
823
connection mdl_con1;
 
824
--echo # Check that SNRW lock is incompatible with SNRW lock.
 
825
--echo # Sending:
 
826
--send lock table t1 write;
 
827
--echo # 
 
828
--echo # Switching to connection 'default'.
 
829
connection default;
 
830
--echo # Check that the above LOCK TABLES is blocked because of SNRW lock.
 
831
let $wait_condition=
 
832
  select count(*) = 1 from information_schema.processlist
 
833
  where state = "Waiting for table metadata lock" and
 
834
        info = "lock table t1 write";
 
835
--source include/wait_condition.inc
 
836
--echo # Unblock waiting LOCK TABLES.
 
837
unlock tables;
 
838
--echo # 
 
839
--echo # Switching to connection 'mdl_con1'.
 
840
connection mdl_con1;
 
841
--echo # Reaping LOCK TABLES
 
842
--reap
 
843
insert into t1 values (1);
 
844
unlock tables;
 
845
--echo # 
 
846
--echo # Switching to connection 'default'.
 
847
connection default;
 
848
lock table t1 write;
 
849
--echo # 
 
850
--echo # Switching to connection 'mdl_con1'.
 
851
connection mdl_con1;
 
852
--echo # Check that X lock is incompatible with SNRW lock.
 
853
--echo # Sending:
 
854
--send rename table t1 to t2;
 
855
--echo # 
 
856
--echo # Switching to connection 'default'.
 
857
connection default;
 
858
--echo # Check that the above RENAME is blocked because of SNRW lock.
 
859
let $wait_condition=
 
860
  select count(*) = 1 from information_schema.processlist
 
861
  where state = "Waiting for table metadata lock" and
 
862
        info = "rename table t1 to t2";
 
863
--source include/wait_condition.inc
 
864
--echo # Unblock RENAME TABLE
 
865
unlock tables;
 
866
--echo # 
 
867
--echo # Switching to connection 'mdl_con1'.
 
868
connection mdl_con1;
 
869
--echo # Reaping RENAME TABLE
 
870
--reap
 
871
--echo # Revert back to original state of things.
 
872
rename table t2 to t1;
 
873
--echo #
 
874
--echo # There is no need to check that upgrade from SNW/SNRW to X is
 
875
--echo # blocked by presence of another SNRW lock because SNW/SNRW is
 
876
--echo # incompatible with SNRW anyway.
 
877
--echo # 
 
878
--echo # Switching to connection 'default'.
 
879
connection default;
 
880
--echo #
 
881
--echo #
 
882
--echo # 7) Now do the same round of tests for X lock. We use additional
 
883
--echo #    table to get long-lived lock of this type.
 
884
--echo #
 
885
create table t2 (c1 int);
 
886
--echo # 
 
887
--echo # Switching to connection 'mdl_con2'.
 
888
connection mdl_con2;
 
889
--echo # Take a lock on t2, so RENAME TABLE t1 TO t2 will get blocked
 
890
--echo # after acquiring X lock on t1.
 
891
lock tables t2 read;
 
892
--echo # 
 
893
--echo # Switching to connection 'default'.
 
894
connection default;
 
895
--echo # Sending:
 
896
--send rename table t1 to t2;
 
897
--echo # 
 
898
--echo # Switching to connection 'mdl_con1'.
 
899
connection mdl_con1;
 
900
--echo # Check that RENAME has acquired X lock on t1 and is waiting for t2.
 
901
let $wait_condition=
 
902
select count(*) = 1 from information_schema.processlist
 
903
where state = "Waiting for table metadata lock" and
 
904
      info = "rename table t1 to t2";
 
905
--source include/wait_condition.inc
 
906
--echo # Check that S lock in incompatible with X lock.
 
907
--echo # Sending:
 
908
--send handler t1 open;
 
909
--echo # 
 
910
--echo # Switching to connection 'mdl_con2'.
 
911
connection mdl_con2;
 
912
--echo # Check that the above HANDLER statement is blocked because of X lock.
 
913
let $wait_condition=
 
914
select count(*) = 1 from information_schema.processlist
 
915
where state = "Waiting for table metadata lock" and
 
916
      info = "handler t1 open";
 
917
--source include/wait_condition.inc
 
918
--echo # Unblock RENAME TABLE
 
919
unlock tables;
 
920
--echo # 
 
921
--echo # Switching to connection 'default'.
 
922
connection default;
 
923
--echo # Reaping RENAME TABLE.
 
924
--error ER_TABLE_EXISTS_ERROR
 
925
--reap
 
926
--echo # 
 
927
--echo # Switching to connection 'mdl_con1'.
 
928
connection mdl_con1;
 
929
--echo # Reaping HANDLER.
 
930
--reap
 
931
handler t1 close;
 
932
--echo # 
 
933
--echo # Switching to connection 'mdl_con2'.
 
934
connection mdl_con2;
 
935
--echo # Prepare for blocking RENAME TABLE.
 
936
lock tables t2 read;
 
937
--echo # 
 
938
--echo # Switching to connection 'default'.
 
939
connection default;
 
940
--echo # Sending:
 
941
--send rename table t1 to t2;
 
942
--echo # 
 
943
--echo # Switching to connection 'mdl_con1'.
 
944
connection mdl_con1;
 
945
--echo # Check that RENAME has acquired X lock on t1 and is waiting for t2.
 
946
let $wait_condition=
 
947
select count(*) = 1 from information_schema.processlist
 
948
where state = "Waiting for table metadata lock" and
 
949
      info = "rename table t1 to t2";
 
950
--source include/wait_condition.inc
 
951
--echo # Check that SH lock in incompatible with X lock.
 
952
--echo # Sending:
 
953
--send select column_name from information_schema.columns where table_schema='test' and table_name='t1';
 
954
--echo # 
 
955
--echo # Switching to connection 'mdl_con2'.
 
956
connection mdl_con2;
 
957
--echo # Check that the above SELECT ... FROM I_S ... statement is blocked
 
958
--echo # because of X lock.
 
959
let $wait_condition=
 
960
select count(*) = 1 from information_schema.processlist
 
961
where state = "Waiting for table metadata lock" and
 
962
      info like "select column_name from information_schema.columns%";
 
963
--source include/wait_condition.inc
 
964
--echo # Unblock RENAME TABLE
 
965
unlock tables;
 
966
--echo # 
 
967
--echo # Switching to connection 'default'.
 
968
connection default;
 
969
--echo # Reaping RENAME TABLE.
 
970
--error ER_TABLE_EXISTS_ERROR
 
971
--reap
 
972
--echo # 
 
973
--echo # Switching to connection 'mdl_con1'.
 
974
connection mdl_con1;
 
975
--echo # Reaping SELECT ... FROM I_S.
 
976
--reap
 
977
--echo # 
 
978
--echo # Switching to connection 'mdl_con2'.
 
979
connection mdl_con2;
 
980
--echo # Prepare for blocking RENAME TABLE.
 
981
lock tables t2 read;
 
982
--echo # 
 
983
--echo # Switching to connection 'default'.
 
984
connection default;
 
985
--echo # Sending:
 
986
--send rename table t1 to t2;
 
987
--echo # 
 
988
--echo # Switching to connection 'mdl_con1'.
 
989
connection mdl_con1;
 
990
--echo # Check that RENAME has acquired X lock on t1 and is waiting for t2.
 
991
let $wait_condition=
 
992
select count(*) = 1 from information_schema.processlist
 
993
where state = "Waiting for table metadata lock" and
 
994
      info = "rename table t1 to t2";
 
995
--source include/wait_condition.inc
 
996
--echo # Check that SR lock in incompatible with X lock.
 
997
--echo # Sending:
 
998
--send select count(*) from t1;
 
999
--echo # 
 
1000
--echo # Switching to connection 'mdl_con2'.
 
1001
connection mdl_con2;
 
1002
--echo # Check that the above SELECT statement is blocked
 
1003
--echo # because of X lock.
 
1004
let $wait_condition=
 
1005
select count(*) = 1 from information_schema.processlist
 
1006
where state = "Waiting for table metadata lock" and 
 
1007
      info = "select count(*) from t1";
 
1008
--source include/wait_condition.inc
 
1009
--echo # Unblock RENAME TABLE
 
1010
unlock tables;
 
1011
--echo # 
 
1012
--echo # Switching to connection 'default'.
 
1013
connection default;
 
1014
--echo # Reaping RENAME TABLE.
 
1015
--error ER_TABLE_EXISTS_ERROR
 
1016
--reap
 
1017
--echo # 
 
1018
--echo # Switching to connection 'mdl_con1'.
 
1019
connection mdl_con1;
 
1020
--echo # Reaping SELECT.
 
1021
--reap
 
1022
--echo # 
 
1023
--echo # Switching to connection 'mdl_con2'.
 
1024
connection mdl_con2;
 
1025
--echo # Prepare for blocking RENAME TABLE.
 
1026
lock tables t2 read;
 
1027
--echo # 
 
1028
--echo # Switching to connection 'default'.
 
1029
connection default;
 
1030
--echo # Sending:
 
1031
--send rename table t1 to t2;
 
1032
--echo # 
 
1033
--echo # Switching to connection 'mdl_con1'.
 
1034
connection mdl_con1;
 
1035
--echo # Check that RENAME has acquired X lock on t1 and is waiting for t2.
 
1036
let $wait_condition=
 
1037
select count(*) = 1 from information_schema.processlist
 
1038
where state = "Waiting for table metadata lock" and
 
1039
      info = "rename table t1 to t2";
 
1040
--source include/wait_condition.inc
 
1041
--echo # Check that SW lock in incompatible with X lock.
 
1042
--echo # Sending:
 
1043
--send delete from t1 limit 1;
 
1044
--echo # 
 
1045
--echo # Switching to connection 'mdl_con2'.
 
1046
connection mdl_con2;
 
1047
--echo # Check that the above DELETE statement is blocked
 
1048
--echo # because of X lock.
 
1049
let $wait_condition=
 
1050
select count(*) = 1 from information_schema.processlist
 
1051
where state = "Waiting for table metadata lock" and
 
1052
      info = "delete from t1 limit 1";
 
1053
--source include/wait_condition.inc
 
1054
--echo # Unblock RENAME TABLE
 
1055
unlock tables;
 
1056
--echo # 
 
1057
--echo # Switching to connection 'default'.
 
1058
connection default;
 
1059
--echo # Reaping RENAME TABLE.
 
1060
--error ER_TABLE_EXISTS_ERROR
 
1061
--reap
 
1062
--echo # 
 
1063
--echo # Switching to connection 'mdl_con1'.
 
1064
connection mdl_con1;
 
1065
--echo # Reaping DELETE.
 
1066
--reap
 
1067
--echo # 
 
1068
--echo # Switching to connection 'mdl_con2'.
 
1069
connection mdl_con2;
 
1070
--echo # Prepare for blocking RENAME TABLE.
 
1071
lock tables t2 read;
 
1072
--echo # 
 
1073
--echo # Switching to connection 'default'.
 
1074
connection default;
 
1075
--echo # Sending:
 
1076
--send rename table t1 to t2;
 
1077
--echo # 
 
1078
--echo # Switching to connection 'mdl_con1'.
 
1079
connection mdl_con1;
 
1080
--echo # Check that RENAME has acquired X lock on t1 and is waiting for t2.
 
1081
let $wait_condition=
 
1082
select count(*) = 1 from information_schema.processlist
 
1083
where state = "Waiting for table metadata lock" and
 
1084
      info = "rename table t1 to t2";
 
1085
--source include/wait_condition.inc
 
1086
--echo # Check that SNW lock is incompatible with X lock.
 
1087
--echo # Sending:
 
1088
--send alter table t1 add primary key (c1);
 
1089
--echo # 
 
1090
--echo # Switching to connection 'mdl_con2'.
 
1091
connection mdl_con2;
 
1092
--echo # Check that the above ALTER statement is blocked
 
1093
--echo # because of X lock.
 
1094
let $wait_condition=
 
1095
select count(*) = 1 from information_schema.processlist
 
1096
where state = "Waiting for table metadata lock" and
 
1097
      info = "alter table t1 add primary key (c1)";
 
1098
--source include/wait_condition.inc
 
1099
--echo # Unblock RENAME TABLE
 
1100
unlock tables;
 
1101
--echo # 
 
1102
--echo # Switching to connection 'default'.
 
1103
connection default;
 
1104
--echo # Reaping RENAME TABLE
 
1105
--error ER_TABLE_EXISTS_ERROR
 
1106
--reap
 
1107
--echo # 
 
1108
--echo # Switching to connection 'mdl_con1'.
 
1109
connection mdl_con1;
 
1110
--echo # Reaping ALTER.
 
1111
--error ER_DUP_ENTRY
 
1112
--reap
 
1113
--echo # 
 
1114
--echo # Switching to connection 'mdl_con2'.
 
1115
connection mdl_con2;
 
1116
--echo # Prepare for blocking RENAME TABLE.
 
1117
lock tables t2 read;
 
1118
--echo # 
 
1119
--echo # Switching to connection 'default'.
 
1120
connection default;
 
1121
--echo # Sending:
 
1122
--send rename table t1 to t2;
 
1123
--echo # 
 
1124
--echo # Switching to connection 'mdl_con1'.
 
1125
connection mdl_con1;
 
1126
--echo # Check that RENAME has acquired X lock on t1 and is waiting for t2.
 
1127
let $wait_condition=
 
1128
select count(*) = 1 from information_schema.processlist
 
1129
where state = "Waiting for table metadata lock" and
 
1130
      info = "rename table t1 to t2";
 
1131
--source include/wait_condition.inc
 
1132
--echo # Check that SNRW lock is incompatible with X lock.
 
1133
--echo # Sending:
 
1134
--send lock table t1 write;
 
1135
--echo # 
 
1136
--echo # Switching to connection 'mdl_con2'.
 
1137
connection mdl_con2;
 
1138
--echo # Check that the above LOCK TABLE statement is blocked
 
1139
--echo # because of X lock.
 
1140
let $wait_condition=
 
1141
select count(*) = 1 from information_schema.processlist
 
1142
where state = "Waiting for table metadata lock" and
 
1143
      info = "lock table t1 write";
 
1144
--source include/wait_condition.inc
 
1145
--echo # Unblock RENAME TABLE
 
1146
unlock tables;
 
1147
--echo # 
 
1148
--echo # Switching to connection 'default'.
 
1149
connection default;
 
1150
--echo # Reaping RENAME TABLE
 
1151
--error ER_TABLE_EXISTS_ERROR
 
1152
--reap
 
1153
--echo # 
 
1154
--echo # Switching to connection 'mdl_con1'.
 
1155
connection mdl_con1;
 
1156
--echo # Reaping LOCK TABLE.
 
1157
--reap
 
1158
unlock tables;
 
1159
--echo # 
 
1160
--echo # Switching to connection 'mdl_con2'.
 
1161
connection mdl_con2;
 
1162
--echo # Prepare for blocking RENAME TABLE.
 
1163
lock tables t2 read;
 
1164
--echo # 
 
1165
--echo # Switching to connection 'default'.
 
1166
connection default;
 
1167
--echo # Sending:
 
1168
--send rename table t1 to t2;
 
1169
--echo # 
 
1170
--echo # Switching to connection 'mdl_con1'.
 
1171
connection mdl_con1;
 
1172
--echo # Check that RENAME has acquired X lock on t1 and is waiting for t2.
 
1173
let $wait_condition=
 
1174
select count(*) = 1 from information_schema.processlist
 
1175
where state = "Waiting for table metadata lock" and
 
1176
      info = "rename table t1 to t2";
 
1177
--source include/wait_condition.inc
 
1178
--echo # Check that X lock is incompatible with X lock.
 
1179
--echo # Sending:
 
1180
--send rename table t1 to t3;
 
1181
--echo # 
 
1182
--echo # Switching to connection 'mdl_con2'.
 
1183
connection mdl_con2;
 
1184
--echo # Check that the above RENAME statement is blocked
 
1185
--echo # because of X lock.
 
1186
let $wait_condition=
 
1187
select count(*) = 1 from information_schema.processlist
 
1188
where state = "Waiting for table metadata lock" and
 
1189
      info = "rename table t1 to t3";
 
1190
--source include/wait_condition.inc
 
1191
--echo # Unblock RENAME TABLE
 
1192
unlock tables;
 
1193
--echo # 
 
1194
--echo # Switching to connection 'default'.
 
1195
connection default;
 
1196
--echo # Reaping RENAME TABLE
 
1197
--error ER_TABLE_EXISTS_ERROR
 
1198
--reap
 
1199
--echo # 
 
1200
--echo # Switching to connection 'mdl_con1'.
 
1201
connection mdl_con1;
 
1202
--echo # Reaping RENAME.
 
1203
--reap
 
1204
rename table t3 to t1;
 
1205
 
 
1206
--echo #
 
1207
--echo # B) Now let us test compatibility in cases when both locks
 
1208
--echo #    are pending. I.e. let us test rules for priorities between
 
1209
--echo #    different types of metadata locks.
 
1210
--echo #
 
1211
 
 
1212
--echo # 
 
1213
--echo # Switching to connection 'mdl_con2'.
 
1214
connection mdl_con2;
 
1215
--echo #
 
1216
--echo # 1) Check compatibility for pending SNW lock.
 
1217
--echo #
 
1218
--echo # Acquire SW lock in order to create pending SNW lock later.
 
1219
begin;
 
1220
insert into t1 values (1);
 
1221
--echo # 
 
1222
--echo # Switching to connection 'default'.
 
1223
connection default;
 
1224
--echo # Add pending SNW lock.
 
1225
--echo # Sending:
 
1226
--send alter table t1 add primary key (c1);
 
1227
--echo # 
 
1228
--echo # Switching to connection 'mdl_con1'.
 
1229
connection mdl_con1;
 
1230
--echo # Check that ALTER TABLE is waiting with pending SNW lock.
 
1231
let $wait_condition=
 
1232
select count(*) = 1 from information_schema.processlist
 
1233
where state = "Waiting for table metadata lock" and
 
1234
      info = "alter table t1 add primary key (c1)";
 
1235
--source include/wait_condition.inc
 
1236
--echo # Check that S, SH and SR locks are compatible with pending SNW
 
1237
handler t1 open t;
 
1238
handler t close;
 
1239
select column_name from information_schema.columns where
 
1240
  table_schema='test' and table_name='t1';
 
1241
select count(*) from t1;
 
1242
--echo # Check that SW is incompatible with pending SNW
 
1243
--echo # Sending:
 
1244
--send delete from t1 limit 1;
 
1245
--echo # 
 
1246
--echo # Switching to connection 'mdl_con2'.
 
1247
connection mdl_con2;
 
1248
--echo # Check that the above DELETE is blocked because of pending SNW lock.
 
1249
let $wait_condition=
 
1250
select count(*) = 1 from information_schema.processlist
 
1251
where state = "Waiting for table metadata lock" and
 
1252
      info = "delete from t1 limit 1";
 
1253
--source include/wait_condition.inc
 
1254
--echo # Unblock ALTER TABLE.
 
1255
commit;
 
1256
--echo # 
 
1257
--echo # Switching to connection 'default'.
 
1258
connection default;
 
1259
--echo # Reaping ALTER.
 
1260
--error ER_DUP_ENTRY
 
1261
--reap
 
1262
--echo # 
 
1263
--echo # Switching to connection 'mdl_con1'.
 
1264
connection mdl_con1;
 
1265
--echo # Reaping DELETE.
 
1266
--reap
 
1267
--echo #
 
1268
--echo # We can't do similar check for SNW, SNRW and X locks because
 
1269
--echo # they will also be blocked by active SW lock.
 
1270
--echo #
 
1271
--echo # 
 
1272
--echo # Switching to connection 'mdl_con2'.
 
1273
connection mdl_con2;
 
1274
--echo #
 
1275
--echo # 2) Check compatibility for pending SNRW lock.
 
1276
--echo #
 
1277
--echo # Acquire SR lock in order to create pending SNRW lock.
 
1278
begin;
 
1279
select count(*) from t1;
 
1280
--echo # 
 
1281
--echo # Switching to connection 'default'.
 
1282
connection default;
 
1283
--echo # Add pending SNRW lock.
 
1284
--echo # Sending:
 
1285
--send lock table t1 write;
 
1286
--echo # 
 
1287
--echo # Switching to connection 'mdl_con1'.
 
1288
connection mdl_con1;
 
1289
--echo # Check that LOCK TABLE is waiting with pending SNRW lock.
 
1290
let $wait_condition=
 
1291
select count(*) = 1 from information_schema.processlist
 
1292
where state = "Waiting for table metadata lock" and
 
1293
      info = "lock table t1 write";
 
1294
--source include/wait_condition.inc
 
1295
--echo # Check that S and SH locks are compatible with pending SNRW
 
1296
handler t1 open t;
 
1297
handler t close;
 
1298
select column_name from information_schema.columns where
 
1299
  table_schema='test' and table_name='t1';
 
1300
--echo # Check that SR is incompatible with pending SNRW
 
1301
--echo # Sending:
 
1302
--send select count(*) from t1;
 
1303
--echo # 
 
1304
--echo # Switching to connection 'mdl_con2'.
 
1305
connection mdl_con2;
 
1306
--echo # Check that the above SELECT is blocked because of pending SNRW lock.
 
1307
let $wait_condition=
 
1308
select count(*) = 1 from information_schema.processlist
 
1309
where state = "Waiting for table metadata lock" and
 
1310
      info = "select count(*) from t1";
 
1311
--source include/wait_condition.inc
 
1312
--echo # Unblock LOCK TABLE.
 
1313
commit;
 
1314
--echo # 
 
1315
--echo # Switching to connection 'default'.
 
1316
connection default;
 
1317
--echo # Reaping LOCK TABLE.
 
1318
--reap
 
1319
unlock tables;
 
1320
--echo # 
 
1321
--echo # Switching to connection 'mdl_con1'.
 
1322
connection mdl_con1;
 
1323
--echo # Reaping SELECT.
 
1324
--reap
 
1325
--echo # Restore pending SNRW lock.
 
1326
--echo # 
 
1327
--echo # Switching to connection 'mdl_con2'.
 
1328
connection mdl_con2;
 
1329
begin;
 
1330
select count(*) from t1;
 
1331
--echo # 
 
1332
--echo # Switching to connection 'default'.
 
1333
connection default;
 
1334
--echo # Sending:
 
1335
--send lock table t1 write;
 
1336
--echo # 
 
1337
--echo # Switching to connection 'mdl_con1'.
 
1338
connection mdl_con1;
 
1339
--echo # Check that LOCK TABLE is waiting with pending SNRW lock.
 
1340
let $wait_condition=
 
1341
select count(*) = 1 from information_schema.processlist
 
1342
where state = "Waiting for table metadata lock" and
 
1343
      info = "lock table t1 write";
 
1344
--source include/wait_condition.inc
 
1345
--echo # Check that SW is incompatible with pending SNRW
 
1346
--echo # Sending:
 
1347
--send insert into t1 values (1);
 
1348
--echo # 
 
1349
--echo # Switching to connection 'mdl_con2'.
 
1350
connection mdl_con2;
 
1351
--echo # Check that the above INSERT is blocked because of pending SNRW lock.
 
1352
let $wait_condition=
 
1353
select count(*) = 1 from information_schema.processlist
 
1354
where state = "Waiting for table metadata lock" and
 
1355
      info = "insert into t1 values (1)";
 
1356
--source include/wait_condition.inc
 
1357
--echo # Unblock LOCK TABLE.
 
1358
commit;
 
1359
--echo # 
 
1360
--echo # Switching to connection 'default'.
 
1361
connection default;
 
1362
--echo # Reaping LOCK TABLE.
 
1363
--reap
 
1364
unlock tables;
 
1365
--echo # 
 
1366
--echo # Switching to connection 'mdl_con1'.
 
1367
connection mdl_con1;
 
1368
--echo # Reaping INSERT.
 
1369
--reap
 
1370
--echo # Restore pending SNRW lock.
 
1371
--echo # 
 
1372
--echo # Switching to connection 'mdl_con2'.
 
1373
connection mdl_con2;
 
1374
begin;
 
1375
select count(*) from t1;
 
1376
--echo # 
 
1377
--echo # Switching to connection 'default'.
 
1378
connection default;
 
1379
--echo # Sending:
 
1380
--send lock table t1 write;
 
1381
--echo # 
 
1382
--echo # Switching to connection 'mdl_con1'.
 
1383
connection mdl_con1;
 
1384
--echo # Check that LOCK TABLE is waiting with pending SNRW lock.
 
1385
let $wait_condition=
 
1386
select count(*) = 1 from information_schema.processlist
 
1387
where state = "Waiting for table metadata lock" and
 
1388
      info = "lock table t1 write";
 
1389
--source include/wait_condition.inc
 
1390
--echo # Check that SNW is compatible with pending SNRW
 
1391
--echo # So ALTER TABLE statements are not starved by LOCK TABLEs.
 
1392
--error ER_DUP_ENTRY
 
1393
alter table t1 add primary key (c1);
 
1394
--echo # 
 
1395
--echo # Switching to connection 'mdl_con2'.
 
1396
connection mdl_con2;
 
1397
--echo # Unblock LOCK TABLE.
 
1398
commit;
 
1399
--echo # 
 
1400
--echo # Switching to connection 'default'.
 
1401
connection default;
 
1402
--echo # Reaping LOCK TABLE.
 
1403
--reap
 
1404
unlock tables;
 
1405
--echo #
 
1406
--echo # We can't do similar check for SNRW and X locks because
 
1407
--echo # they will also be blocked by active SR lock.
 
1408
--echo #
 
1409
--echo # 
 
1410
--echo # Switching to connection 'mdl_con2'.
 
1411
connection mdl_con2;
 
1412
--echo #
 
1413
--echo # 3) Check compatibility for pending X lock.
 
1414
--echo #
 
1415
--echo # Acquire SR lock in order to create pending X lock.
 
1416
begin;
 
1417
select count(*) from t1;
 
1418
--echo # 
 
1419
--echo # Switching to connection 'default'.
 
1420
connection default;
 
1421
--echo # Add pending X lock.
 
1422
--echo # Sending:
 
1423
--send rename table t1 to t2;
 
1424
--echo # 
 
1425
--echo # Switching to connection 'mdl_con1'.
 
1426
connection mdl_con1;
 
1427
--echo # Check that RENAME TABLE is waiting with pending X lock.
 
1428
let $wait_condition=
 
1429
select count(*) = 1 from information_schema.processlist
 
1430
where state = "Waiting for table metadata lock" and
 
1431
      info = "rename table t1 to t2";
 
1432
--source include/wait_condition.inc
 
1433
--echo # Check that SH locks are compatible with pending X
 
1434
select column_name from information_schema.columns where
 
1435
  table_schema='test' and table_name='t1';
 
1436
--echo # Check that S is incompatible with pending X
 
1437
--echo # Sending:
 
1438
--send handler t1 open;
 
1439
--echo # 
 
1440
--echo # Switching to connection 'mdl_con2'.
 
1441
connection mdl_con2;
 
1442
--echo # Check that the above HANDLER OPEN is blocked because of pending X lock.
 
1443
let $wait_condition=
 
1444
select count(*) = 1 from information_schema.processlist
 
1445
where state = "Waiting for table metadata lock" and
 
1446
      info = "handler t1 open";
 
1447
--source include/wait_condition.inc
 
1448
--echo # Unblock RENAME TABLE.
 
1449
commit;
 
1450
--echo # 
 
1451
--echo # Switching to connection 'default'.
 
1452
connection default;
 
1453
--echo # Reaping RENAME TABLE.
 
1454
--error ER_TABLE_EXISTS_ERROR
 
1455
--reap
 
1456
--echo # 
 
1457
--echo # Switching to connection 'mdl_con1'.
 
1458
connection mdl_con1;
 
1459
--echo # Reaping HANDLER t1 OPEN.
 
1460
--reap
 
1461
handler t1 close;
 
1462
--echo # Restore pending X lock.
 
1463
--echo # 
 
1464
--echo # Switching to connection 'mdl_con2'.
 
1465
connection mdl_con2;
 
1466
begin;
 
1467
select count(*) from t1;
 
1468
--echo # 
 
1469
--echo # Switching to connection 'default'.
 
1470
connection default;
 
1471
--echo # Add pending X lock.
 
1472
--echo # Sending:
 
1473
--send rename table t1 to t2;
 
1474
--echo # 
 
1475
--echo # Switching to connection 'mdl_con1'.
 
1476
connection mdl_con1;
 
1477
--echo # Check that RENAME TABLE is waiting with pending X lock.
 
1478
let $wait_condition=
 
1479
select count(*) = 1 from information_schema.processlist
 
1480
where state = "Waiting for table metadata lock" and
 
1481
      info = "rename table t1 to t2";
 
1482
--source include/wait_condition.inc
 
1483
--echo # Check that SR is incompatible with pending X
 
1484
--echo # Sending:
 
1485
--send select count(*) from t1;
 
1486
--echo # 
 
1487
--echo # Switching to connection 'mdl_con2'.
 
1488
connection mdl_con2;
 
1489
--echo # Check that the above SELECT is blocked because of pending X lock.
 
1490
let $wait_condition=
 
1491
select count(*) = 1 from information_schema.processlist
 
1492
where state = "Waiting for table metadata lock" and
 
1493
      info = "select count(*) from t1";
 
1494
--source include/wait_condition.inc
 
1495
--echo # Unblock RENAME TABLE.
 
1496
commit;
 
1497
--echo # 
 
1498
--echo # Switching to connection 'default'.
 
1499
connection default;
 
1500
--echo # Reaping RENAME TABLE.
 
1501
--error ER_TABLE_EXISTS_ERROR
 
1502
--reap
 
1503
--echo # 
 
1504
--echo # Switching to connection 'mdl_con1'.
 
1505
connection mdl_con1;
 
1506
--echo # Reaping SELECT.
 
1507
--reap
 
1508
--echo # Restore pending X lock.
 
1509
--echo # 
 
1510
--echo # Switching to connection 'mdl_con2'.
 
1511
connection mdl_con2;
 
1512
begin;
 
1513
select count(*) from t1;
 
1514
--echo # 
 
1515
--echo # Switching to connection 'default'.
 
1516
connection default;
 
1517
--echo # Add pending X lock.
 
1518
--echo # Sending:
 
1519
--send rename table t1 to t2;
 
1520
--echo # 
 
1521
--echo # Switching to connection 'mdl_con1'.
 
1522
connection mdl_con1;
 
1523
--echo # Check that RENAME TABLE is waiting with pending X lock.
 
1524
let $wait_condition=
 
1525
select count(*) = 1 from information_schema.processlist
 
1526
where state = "Waiting for table metadata lock" and
 
1527
      info = "rename table t1 to t2";
 
1528
--source include/wait_condition.inc
 
1529
--echo # Check that SW is incompatible with pending X
 
1530
--echo # Sending:
 
1531
--send delete from t1 limit 1;
 
1532
--echo # 
 
1533
--echo # Switching to connection 'mdl_con2'.
 
1534
connection mdl_con2;
 
1535
--echo # Check that the above DELETE is blocked because of pending X lock.
 
1536
let $wait_condition=
 
1537
select count(*) = 1 from information_schema.processlist
 
1538
where state = "Waiting for table metadata lock" and
 
1539
      info = "delete from t1 limit 1";
 
1540
--source include/wait_condition.inc
 
1541
--echo # Unblock RENAME TABLE.
 
1542
commit;
 
1543
--echo # 
 
1544
--echo # Switching to connection 'default'.
 
1545
connection default;
 
1546
--echo # Reaping RENAME TABLE.
 
1547
--error ER_TABLE_EXISTS_ERROR
 
1548
--reap
 
1549
--echo # 
 
1550
--echo # Switching to connection 'mdl_con1'.
 
1551
connection mdl_con1;
 
1552
--echo # Reaping DELETE.
 
1553
--reap
 
1554
--echo # Restore pending X lock.
 
1555
--echo # 
 
1556
--echo # Switching to connection 'mdl_con2'.
 
1557
connection mdl_con2;
 
1558
begin;
 
1559
select count(*) from t1;
 
1560
--echo # 
 
1561
--echo # Switching to connection 'default'.
 
1562
connection default;
 
1563
--echo # Add pending X lock.
 
1564
--echo # Sending:
 
1565
--send rename table t1 to t2;
 
1566
--echo # 
 
1567
--echo # Switching to connection 'mdl_con1'.
 
1568
connection mdl_con1;
 
1569
--echo # Check that RENAME TABLE is waiting with pending X lock.
 
1570
let $wait_condition=
 
1571
select count(*) = 1 from information_schema.processlist
 
1572
where state = "Waiting for table metadata lock" and
 
1573
      info = "rename table t1 to t2";
 
1574
--source include/wait_condition.inc
 
1575
--echo # Check that SNW is incompatible with pending X
 
1576
--echo # Sending:
 
1577
--send alter table t1 add primary key (c1);
 
1578
--echo # 
 
1579
--echo # Switching to connection 'mdl_con2'.
 
1580
connection mdl_con2;
 
1581
--echo # Check that the above ALTER TABLE is blocked because of pending X lock.
 
1582
let $wait_condition=
 
1583
select count(*) = 1 from information_schema.processlist
 
1584
where state = "Waiting for table metadata lock" and
 
1585
      info = "alter table t1 add primary key (c1)";
 
1586
--source include/wait_condition.inc
 
1587
--echo # Unblock RENAME TABLE.
 
1588
commit;
 
1589
--echo # 
 
1590
--echo # Switching to connection 'default'.
 
1591
connection default;
 
1592
--echo # Reaping RENAME TABLE.
 
1593
--error ER_TABLE_EXISTS_ERROR
 
1594
--reap
 
1595
--echo # 
 
1596
--echo # Switching to connection 'mdl_con1'.
 
1597
connection mdl_con1;
 
1598
--echo # Reaping ALTER TABLE.
 
1599
--error ER_DUP_ENTRY
 
1600
--reap
 
1601
--echo # Restore pending X lock.
 
1602
--echo # 
 
1603
--echo # Switching to connection 'mdl_con2'.
 
1604
connection mdl_con2;
 
1605
handler t1 open;
 
1606
--echo # 
 
1607
--echo # Switching to connection 'default'.
 
1608
connection default;
 
1609
--echo # Add pending X lock.
 
1610
--echo # Sending:
 
1611
--send rename table t1 to t2;
 
1612
--echo # 
 
1613
--echo # Switching to connection 'mdl_con1'.
 
1614
connection mdl_con1;
 
1615
--echo # Check that RENAME TABLE is waiting with pending X lock.
 
1616
let $wait_condition=
 
1617
select count(*) = 1 from information_schema.processlist
 
1618
where state = "Waiting for table metadata lock" and
 
1619
      info = "rename table t1 to t2";
 
1620
--source include/wait_condition.inc
 
1621
--echo # Check that SNRW is incompatible with pending X
 
1622
--echo # Sending:
 
1623
--send lock table t1 write;
 
1624
--echo # 
 
1625
--echo # Switching to connection 'mdl_con3'.
 
1626
connection mdl_con3;
 
1627
--echo # Check that the above LOCK TABLES is blocked because of pending X lock.
 
1628
let $wait_condition=
 
1629
select count(*) = 1 from information_schema.processlist
 
1630
where state = "Waiting for table metadata lock" and
 
1631
      info = "lock table t1 write";
 
1632
--source include/wait_condition.inc
 
1633
--echo # 
 
1634
--echo # Switching to connection 'mdl_con2'.
 
1635
connection mdl_con2;
 
1636
--echo # Unblock RENAME TABLE.
 
1637
handler t1 close;
 
1638
--echo # 
 
1639
--echo # Switching to connection 'default'.
 
1640
connection default;
 
1641
--echo # Reaping RENAME TABLE.
 
1642
--error ER_TABLE_EXISTS_ERROR
 
1643
--reap
 
1644
--echo # 
 
1645
--echo # Switching to connection 'mdl_con1'.
 
1646
connection mdl_con1;
 
1647
--echo # Reaping LOCK TABLES.
 
1648
--reap
 
1649
unlock tables;
 
1650
--echo # 
 
1651
--echo # Switching to connection 'default'.
 
1652
connection default;
 
1653
 
 
1654
--echo #
 
1655
--echo #
 
1656
--echo # C) Now let us test how type-of-operation locks are handled in
 
1657
--echo #    transactional context. Obviously we are mostly interested
 
1658
--echo #    in conflicting types of locks.
 
1659
--echo #
 
1660
 
 
1661
--echo #
 
1662
--echo # 1) Let us check how various locks used within transactional
 
1663
--echo #    context interact with active/pending SNW lock.
 
1664
--echo #
 
1665
--echo #    We start with case when we are acquiring lock on the table
 
1666
--echo #    which was not used in the transaction before.
 
1667
begin;
 
1668
select count(*) from t1;
 
1669
--echo # 
 
1670
--echo # Switching to connection 'mdl_con1'.
 
1671
connection mdl_con1;
 
1672
--echo # Create an active SNW lock on t2.
 
1673
--echo # We have to use DEBUG_SYNC facility as otherwise SNW lock
 
1674
--echo # will be immediately released (or upgraded to X lock).
 
1675
insert into t2 values (1), (1);
 
1676
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
1677
--echo # Sending:
 
1678
--send alter table t2 add primary key (c1);
 
1679
--echo # 
 
1680
--echo # Switching to connection 'default'.
 
1681
connection default;
 
1682
set debug_sync= 'now WAIT_FOR locked';
 
1683
--echo # SR lock should be acquired without any waiting.
 
1684
select count(*) from t2;
 
1685
commit;
 
1686
--echo # Now let us check that we will wait in case of SW lock.
 
1687
begin;
 
1688
select count(*) from t1;
 
1689
--echo # Sending:
 
1690
--send insert into t2 values (1);
 
1691
--echo # 
 
1692
--echo # Switching to connection 'mdl_con2'.
 
1693
connection mdl_con2;
 
1694
--echo # Check that the above INSERT is blocked.
 
1695
let $wait_condition=
 
1696
select count(*) = 1 from information_schema.processlist
 
1697
where state = "Waiting for table metadata lock" and
 
1698
      info = "insert into t2 values (1)";
 
1699
--source include/wait_condition.inc
 
1700
--echo # Unblock ALTER TABLE and thus INSERT.
 
1701
set debug_sync= 'now SIGNAL finish';
 
1702
--echo # 
 
1703
--echo # Switching to connection 'mdl_con1'.
 
1704
connection mdl_con1;
 
1705
--echo # Reap ALTER TABLE.
 
1706
--error ER_DUP_ENTRY
 
1707
--reap
 
1708
--echo # 
 
1709
--echo # Switching to connection 'default'.
 
1710
connection default;
 
1711
--echo # Reap INSERT.
 
1712
--reap
 
1713
commit;
 
1714
--echo #
 
1715
--echo # Now let us see what happens when we are acquiring lock on the table
 
1716
--echo # which is already used in transaction.
 
1717
--echo #
 
1718
--echo # *) First, case when transaction which has SR lock on the table also
 
1719
--echo #    locked in SNW mode acquires yet another SR lock and then tries
 
1720
--echo #    to acquire SW lock.
 
1721
begin;
 
1722
select count(*) from t1;
 
1723
--echo # 
 
1724
--echo # Switching to connection 'mdl_con1'.
 
1725
connection mdl_con1;
 
1726
--echo # Create an active SNW lock on t1.
 
1727
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
1728
--echo # Sending:
 
1729
--send alter table t1 add primary key (c1);
 
1730
--echo # 
 
1731
--echo # Switching to connection 'default'.
 
1732
connection default;
 
1733
set debug_sync= 'now WAIT_FOR locked';
 
1734
--echo # We should still be able to get SR lock without waiting.
 
1735
select count(*) from t1;
 
1736
--echo # Since the above ALTER TABLE is not upgrading SNW lock to X by waiting
 
1737
--echo # for SW lock we won't create deadlock.
 
1738
--echo # So the below INSERT should not end-up with ER_LOCK_DEADLOCK error.
 
1739
--echo # Sending:
 
1740
--send insert into t1 values (1);
 
1741
--echo # 
 
1742
--echo # Switching to connection 'mdl_con2'.
 
1743
connection mdl_con2;
 
1744
--echo # Check that the above INSERT is blocked.
 
1745
let $wait_condition=
 
1746
select count(*) = 1 from information_schema.processlist
 
1747
where state = "Waiting for table metadata lock" and
 
1748
      info = "insert into t1 values (1)";
 
1749
--source include/wait_condition.inc
 
1750
--echo # Unblock ALTER TABLE and thus INSERT.
 
1751
set debug_sync= 'now SIGNAL finish';
 
1752
--echo # 
 
1753
--echo # Switching to connection 'mdl_con1'.
 
1754
connection mdl_con1;
 
1755
--echo # Reap ALTER TABLE.
 
1756
--error ER_DUP_ENTRY
 
1757
--reap
 
1758
--echo # 
 
1759
--echo # Switching to connection 'default'.
 
1760
connection default;
 
1761
--echo # Reap INSERT.
 
1762
--reap
 
1763
commit;
 
1764
--echo #
 
1765
--echo # **) Now test in which transaction that has SW lock on the table
 
1766
--echo #     against which there is pending SNW lock acquires SR and SW
 
1767
--echo #     locks on this table.
 
1768
--echo #
 
1769
begin;
 
1770
insert into t1 values (1);
 
1771
--echo # 
 
1772
--echo # Switching to connection 'mdl_con1'.
 
1773
connection mdl_con1;
 
1774
--echo # Create pending SNW lock on t1.
 
1775
--echo # Sending:
 
1776
--send alter table t1 add primary key (c1);
 
1777
--echo # 
 
1778
--echo # Switching to connection 'default'.
 
1779
connection default;
 
1780
--echo # Wait until ALTER TABLE starts waiting for SNW lock.
 
1781
let $wait_condition=
 
1782
select count(*) = 1 from information_schema.processlist
 
1783
where state = "Waiting for table metadata lock" and
 
1784
      info = "alter table t1 add primary key (c1)";
 
1785
--source include/wait_condition.inc
 
1786
--echo # We should still be able to get both SW and SR locks without waiting.
 
1787
select count(*) from t1;
 
1788
delete from t1 limit 1;
 
1789
--echo # Unblock ALTER TABLE.
 
1790
commit;
 
1791
--echo # 
 
1792
--echo # Switching to connection 'mdl_con1'.
 
1793
connection mdl_con1;
 
1794
--echo # Reap ALTER TABLE.
 
1795
--error ER_DUP_ENTRY
 
1796
--reap
 
1797
--echo # 
 
1798
--echo # Switching to connection 'default'.
 
1799
connection default;
 
1800
--echo #
 
1801
--echo # 2) Now similar tests for active SNW lock which is being upgraded
 
1802
--echo #    to X lock.
 
1803
--echo #
 
1804
--echo #    Again we start with case when we are acquiring lock on the
 
1805
--echo #    table which was not used in the transaction before.
 
1806
begin;
 
1807
select count(*) from t1;
 
1808
--echo # 
 
1809
--echo # Switching to connection 'mdl_con2'.
 
1810
connection mdl_con2;
 
1811
--echo # Start transaction which will prevent SNW -> X upgrade from
 
1812
--echo # completing immediately.
 
1813
begin;
 
1814
select count(*) from t2;
 
1815
--echo # 
 
1816
--echo # Switching to connection 'mdl_con1'.
 
1817
connection mdl_con1;
 
1818
--echo # Create SNW lock pending upgrade to X on t2.
 
1819
--echo # Sending:
 
1820
--send alter table t2 add column c2 int;
 
1821
--echo # 
 
1822
--echo # Switching to connection 'default'.
 
1823
connection default;
 
1824
--echo # Wait until ALTER TABLE starts waiting X lock.
 
1825
let $wait_condition=
 
1826
select count(*) = 1 from information_schema.processlist
 
1827
where state = "Waiting for table metadata lock" and
 
1828
      info = "alter table t2 add column c2 int";
 
1829
--source include/wait_condition.inc
 
1830
--echo # Check that attempt to acquire SR lock on t2 causes waiting.
 
1831
--echo # Sending:
 
1832
--send select count(*) from t2;
 
1833
--echo # 
 
1834
--echo # Switching to connection 'mdl_con2'.
 
1835
connection mdl_con2;
 
1836
--echo # Check that the above SELECT is blocked.
 
1837
let $wait_condition=
 
1838
select count(*) = 1 from information_schema.processlist
 
1839
where state = "Waiting for table metadata lock" and
 
1840
      info = "select count(*) from t2";
 
1841
--source include/wait_condition.inc
 
1842
--echo # Unblock ALTER TABLE.
 
1843
commit;
 
1844
--echo # 
 
1845
--echo # Switching to connection 'mdl_con1'.
 
1846
connection mdl_con1;
 
1847
--echo # Reap ALTER TABLE.
 
1848
--reap
 
1849
--echo # 
 
1850
--echo # Switching to connection 'default'.
 
1851
connection default;
 
1852
--echo # Reap SELECT.
 
1853
--reap
 
1854
commit;
 
1855
--echo # Do similar check for SW lock.
 
1856
begin;
 
1857
select count(*) from t1;
 
1858
--echo # 
 
1859
--echo # Switching to connection 'mdl_con2'.
 
1860
connection mdl_con2;
 
1861
--echo # Start transaction which will prevent SNW -> X upgrade from
 
1862
--echo # completing immediately.
 
1863
begin;
 
1864
select count(*) from t2;
 
1865
--echo # 
 
1866
--echo # Switching to connection 'mdl_con1'.
 
1867
connection mdl_con1;
 
1868
--echo # Create SNW lock pending upgrade to X on t2.
 
1869
--echo # Sending:
 
1870
--send alter table t2 drop column c2;
 
1871
--echo # 
 
1872
--echo # Switching to connection 'default'.
 
1873
connection default;
 
1874
--echo # Wait until ALTER TABLE starts waiting X lock.
 
1875
let $wait_condition=
 
1876
select count(*) = 1 from information_schema.processlist
 
1877
where state = "Waiting for table metadata lock" and
 
1878
      info = "alter table t2 drop column c2";
 
1879
--source include/wait_condition.inc
 
1880
--echo # Check that attempt to acquire SW lock on t2 causes waiting.
 
1881
--echo # Sending:
 
1882
--send insert into t2 values (1);
 
1883
--echo # 
 
1884
--echo # Switching to connection 'mdl_con2'.
 
1885
connection mdl_con2;
 
1886
--echo # Check that the above INSERT is blocked.
 
1887
let $wait_condition=
 
1888
select count(*) = 1 from information_schema.processlist
 
1889
where state = "Waiting for table metadata lock" and
 
1890
      info = "insert into t2 values (1)";
 
1891
--source include/wait_condition.inc
 
1892
--echo # Unblock ALTER TABLE.
 
1893
commit;
 
1894
--echo # 
 
1895
--echo # Switching to connection 'mdl_con1'.
 
1896
connection mdl_con1;
 
1897
--echo # Reap ALTER TABLE.
 
1898
--reap
 
1899
--echo # 
 
1900
--echo # Switching to connection 'default'.
 
1901
connection default;
 
1902
--echo # Reap INSERT.
 
1903
--reap
 
1904
commit;
 
1905
--echo #
 
1906
--echo # Test for the case in which we are acquiring lock on the table
 
1907
--echo # which is already used in transaction.
 
1908
--echo #
 
1909
begin;
 
1910
select count(*) from t1;
 
1911
--echo # 
 
1912
--echo # Switching to connection 'mdl_con1'.
 
1913
connection mdl_con1;
 
1914
--echo # Create SNW lock pending upgrade to X.
 
1915
--echo # Sending:
 
1916
--send alter table t1 add column c2 int;
 
1917
--echo # 
 
1918
--echo # Switching to connection 'default'.
 
1919
connection default;
 
1920
--echo # Wait until ALTER TABLE starts waiting X lock.
 
1921
let $wait_condition=
 
1922
select count(*) = 1 from information_schema.processlist
 
1923
where state = "Waiting for table metadata lock" and
 
1924
      info = "alter table t1 add column c2 int";
 
1925
--source include/wait_condition.inc
 
1926
--echo # Check that transaction is still able to acquire SR lock.
 
1927
select count(*) from t1;
 
1928
--echo # Waiting trying to acquire SW lock will cause deadlock and
 
1929
--echo # therefore should cause an error.
 
1930
--error ER_LOCK_DEADLOCK
 
1931
delete from t1 limit 1;
 
1932
--echo # Unblock ALTER TABLE.
 
1933
commit;
 
1934
--echo # 
 
1935
--echo # Switching to connection 'mdl_con1'.
 
1936
connection mdl_con1;
 
1937
--echo # Reap ALTER TABLE.
 
1938
--reap
 
1939
--echo # 
 
1940
--echo # Switching to connection 'default'.
 
1941
connection default;
 
1942
--echo #
 
1943
--echo # 3) Check how various locks used within transactional context
 
1944
--echo #    interact with active/pending SNRW lock.
 
1945
--echo # 
 
1946
--echo #    Once again we start with case when we are acquiring lock on
 
1947
--echo #    the table which was not used in the transaction before.
 
1948
begin;
 
1949
select count(*) from t1;
 
1950
--echo # 
 
1951
--echo # Switching to connection 'mdl_con1'.
 
1952
connection mdl_con1;
 
1953
lock table t2 write;
 
1954
--echo # 
 
1955
--echo # Switching to connection 'default'.
 
1956
connection default;
 
1957
--echo # Attempt to acquire SR should be blocked. It should
 
1958
--echo # not cause errors as it does not creates deadlock.
 
1959
--echo # Sending:
 
1960
--send select count(*) from t2;
 
1961
--echo # 
 
1962
--echo # Switching to connection 'mdl_con1'.
 
1963
connection mdl_con1;
 
1964
--echo # Check that the above SELECT is blocked 
 
1965
let $wait_condition=
 
1966
select count(*) = 1 from information_schema.processlist
 
1967
where state = "Waiting for table metadata lock" and
 
1968
      info = "select count(*) from t2";
 
1969
--source include/wait_condition.inc
 
1970
--echo # Unblock SELECT.
 
1971
unlock tables;
 
1972
--echo # 
 
1973
--echo # Switching to connection 'default'.
 
1974
connection default;
 
1975
--echo # Reap SELECT.
 
1976
--reap
 
1977
commit;
 
1978
--echo # Repeat the same test for SW lock.
 
1979
begin;
 
1980
select count(*) from t1;
 
1981
--echo # 
 
1982
--echo # Switching to connection 'mdl_con1'.
 
1983
connection mdl_con1;
 
1984
lock table t2 write;
 
1985
--echo # 
 
1986
--echo # Switching to connection 'default'.
 
1987
connection default;
 
1988
--echo # Again attempt to acquire SW should be blocked and should
 
1989
--echo # not cause any errors.
 
1990
--echo # Sending:
 
1991
--send delete from t2 limit 1;
 
1992
--echo # 
 
1993
--echo # Switching to connection 'mdl_con1'.
 
1994
connection mdl_con1;
 
1995
--echo # Check that the above DELETE is blocked 
 
1996
let $wait_condition=
 
1997
select count(*) = 1 from information_schema.processlist
 
1998
where state = "Waiting for table metadata lock" and
 
1999
      info = "delete from t2 limit 1";
 
2000
--source include/wait_condition.inc
 
2001
--echo # Unblock DELETE.
 
2002
unlock tables;
 
2003
--echo # 
 
2004
--echo # Switching to connection 'default'.
 
2005
connection default;
 
2006
--echo # Reap DELETE.
 
2007
--reap
 
2008
commit;
 
2009
--echo #
 
2010
--echo # Now coverage for the case in which we are acquiring lock on
 
2011
--echo # the table which is already used in transaction and against
 
2012
--echo # which there is a pending SNRW lock request.
 
2013
--echo #
 
2014
--echo # *) Let us start with case when transaction has only a SR lock.
 
2015
--echo #
 
2016
begin;
 
2017
select count(*) from t1;
 
2018
--echo # 
 
2019
--echo # Switching to connection 'mdl_con1'.
 
2020
connection mdl_con1;
 
2021
--echo # Sending:
 
2022
--send lock table t1 write;
 
2023
--echo # 
 
2024
--echo # Switching to connection 'default'.
 
2025
connection default;
 
2026
--echo # Wait until LOCK TABLE is blocked creating pending request for X lock.
 
2027
let $wait_condition=
 
2028
select count(*) = 1 from information_schema.processlist
 
2029
where state = "Waiting for table metadata lock" and
 
2030
      info = "lock table t1 write";
 
2031
--source include/wait_condition.inc
 
2032
--echo # Check that another instance of SR lock is granted without waiting.
 
2033
select count(*) from t1;
 
2034
--echo # Attempt to wait for SW lock will lead to deadlock, thus
 
2035
--echo # the below statement should end with ER_LOCK_DEADLOCK error.
 
2036
--error ER_LOCK_DEADLOCK
 
2037
delete from t1 limit 1;
 
2038
--echo # Unblock LOCK TABLES.
 
2039
commit;
 
2040
--echo # 
 
2041
--echo # Switching to connection 'mdl_con1'.
 
2042
connection mdl_con1;
 
2043
--echo # Reap LOCK TABLES.
 
2044
--reap
 
2045
unlock tables;
 
2046
--echo # 
 
2047
--echo # Switching to connection 'default'.
 
2048
connection default;
 
2049
--echo #
 
2050
--echo # **) Now case when transaction has a SW lock.
 
2051
--echo #
 
2052
begin;
 
2053
delete from t1 limit 1;
 
2054
--echo # 
 
2055
--echo # Switching to connection 'mdl_con1'.
 
2056
connection mdl_con1;
 
2057
--echo # Sending:
 
2058
--send lock table t1 write;
 
2059
--echo # 
 
2060
--echo # Switching to connection 'default'.
 
2061
connection default;
 
2062
--echo # Wait until LOCK TABLE is blocked creating pending request for X lock.
 
2063
let $wait_condition=
 
2064
select count(*) = 1 from information_schema.processlist
 
2065
where state = "Waiting for table metadata lock" and
 
2066
      info = "lock table t1 write";
 
2067
--source include/wait_condition.inc
 
2068
--echo # Check that both SR and SW locks are granted without waiting
 
2069
--echo # and errors.
 
2070
select count(*) from t1;
 
2071
insert into t1 values (1, 1);
 
2072
--echo # Unblock LOCK TABLES.
 
2073
commit;
 
2074
--echo # 
 
2075
--echo # Switching to connection 'mdl_con1'.
 
2076
connection mdl_con1;
 
2077
--echo # Reap LOCK TABLES.
 
2078
--reap
 
2079
unlock tables;
 
2080
--echo # 
 
2081
--echo # Switching to connection 'default'.
 
2082
connection default;
 
2083
--echo #
 
2084
--echo # 4) Check how various locks used within transactional context
 
2085
--echo #    interact with active/pending X lock.
 
2086
--echo # 
 
2087
--echo #    As usual we start with case when we are acquiring lock on
 
2088
--echo #    the table which was not used in the transaction before.
 
2089
begin;
 
2090
select count(*) from t1;
 
2091
--echo # 
 
2092
--echo # Switching to connection 'mdl_con2'.
 
2093
connection mdl_con2;
 
2094
--echo # Start transaction which will prevent X lock from going away
 
2095
--echo # immediately.
 
2096
begin;
 
2097
select count(*) from t2;
 
2098
--echo # 
 
2099
--echo # Switching to connection 'mdl_con1'.
 
2100
connection mdl_con1;
 
2101
--echo # Create pending X lock on t2.
 
2102
--echo # Sending:
 
2103
--send rename table t2 to t3;
 
2104
--echo # 
 
2105
--echo # Switching to connection 'default'.
 
2106
connection default;
 
2107
--echo # Wait until RENAME TABLE starts waiting with pending X lock.
 
2108
let $wait_condition=
 
2109
select count(*) = 1 from information_schema.processlist
 
2110
where state = "Waiting for table metadata lock" and
 
2111
      info = "rename table t2 to t3";
 
2112
--source include/wait_condition.inc
 
2113
--echo # Check that attempt to acquire SR lock on t2 causes waiting.
 
2114
--echo # Sending:
 
2115
--send select count(*) from t2;
 
2116
--echo # 
 
2117
--echo # Switching to connection 'mdl_con2'.
 
2118
connection mdl_con2;
 
2119
--echo # Check that the above SELECT is blocked.
 
2120
let $wait_condition=
 
2121
select count(*) = 1 from information_schema.processlist
 
2122
where state = "Waiting for table metadata lock" and
 
2123
      info = "select count(*) from t2";
 
2124
--source include/wait_condition.inc
 
2125
--echo # Unblock RENAME TABLE.
 
2126
commit;
 
2127
--echo # 
 
2128
--echo # Switching to connection 'mdl_con1'.
 
2129
connection mdl_con1;
 
2130
--echo # Reap RENAME TABLE.
 
2131
--reap
 
2132
--echo # 
 
2133
--echo # Switching to connection 'default'.
 
2134
connection default;
 
2135
--echo # Reap SELECT.
 
2136
--error ER_NO_SUCH_TABLE
 
2137
--reap
 
2138
commit;
 
2139
rename table t3 to t2;
 
2140
--echo # The same test for SW lock.
 
2141
begin;
 
2142
select count(*) from t1;
 
2143
--echo # 
 
2144
--echo # Switching to connection 'mdl_con2'.
 
2145
connection mdl_con2;
 
2146
--echo # Start transaction which will prevent X lock from going away
 
2147
--echo # immediately.
 
2148
begin;
 
2149
select count(*) from t2;
 
2150
--echo # 
 
2151
--echo # Switching to connection 'mdl_con1'.
 
2152
connection mdl_con1;
 
2153
--echo # Create pending X lock on t2.
 
2154
--echo # Sending:
 
2155
--send rename table t2 to t3;
 
2156
--echo # 
 
2157
--echo # Switching to connection 'default'.
 
2158
connection default;
 
2159
--echo # Wait until RENAME TABLE starts waiting with pending X lock.
 
2160
let $wait_condition=
 
2161
select count(*) = 1 from information_schema.processlist
 
2162
where state = "Waiting for table metadata lock" and
 
2163
      info = "rename table t2 to t3";
 
2164
--source include/wait_condition.inc
 
2165
--echo # Check that attempt to acquire SW lock on t2 causes waiting.
 
2166
--echo # Sending:
 
2167
--send delete from t2 limit 1;
 
2168
--echo # 
 
2169
--echo # Switching to connection 'mdl_con2'.
 
2170
connection mdl_con2;
 
2171
--echo # Check that the above DELETE is blocked.
 
2172
let $wait_condition=
 
2173
select count(*) = 1 from information_schema.processlist
 
2174
where state = "Waiting for table metadata lock" and
 
2175
      info = "delete from t2 limit 1";
 
2176
--source include/wait_condition.inc
 
2177
--echo # Unblock RENAME TABLE.
 
2178
commit;
 
2179
--echo # 
 
2180
--echo # Switching to connection 'mdl_con1'.
 
2181
connection mdl_con1;
 
2182
--echo # Reap RENAME TABLE.
 
2183
--reap
 
2184
--echo # 
 
2185
--echo # Switching to connection 'default'.
 
2186
connection default;
 
2187
--echo # Reap DELETE.
 
2188
--error ER_NO_SUCH_TABLE
 
2189
--reap
 
2190
commit;
 
2191
rename table t3 to t2;
 
2192
--echo #
 
2193
--echo # Coverage for the case in which we are acquiring lock on
 
2194
--echo # the table which is already used in transaction and against
 
2195
--echo # which there is a pending X lock request.
 
2196
--echo #
 
2197
--echo # *) The first case is when transaction has only a SR lock.
 
2198
--echo #
 
2199
begin;
 
2200
select count(*) from t1;
 
2201
--echo # 
 
2202
--echo # Switching to connection 'mdl_con1'.
 
2203
connection mdl_con1;
 
2204
--echo # Sending:
 
2205
--send rename table t1 to t2;
 
2206
--echo # 
 
2207
--echo # Switching to connection 'default'.
 
2208
connection default;
 
2209
--echo # Wait until RENAME TABLE is blocked creating pending request for X lock.
 
2210
let $wait_condition=
 
2211
select count(*) = 1 from information_schema.processlist
 
2212
where state = "Waiting for table metadata lock" and
 
2213
      info = "rename table t1 to t2";
 
2214
--source include/wait_condition.inc
 
2215
--echo # Check that another instance of SR lock is granted without waiting.
 
2216
select count(*) from t1;
 
2217
--echo # Attempt to wait for SW lock will lead to deadlock, thus
 
2218
--echo # the below statement should end with ER_LOCK_DEADLOCK error.
 
2219
--error ER_LOCK_DEADLOCK
 
2220
delete from t1 limit 1;
 
2221
--echo # Unblock RENAME TABLE.
 
2222
commit;
 
2223
--echo # 
 
2224
--echo # Switching to connection 'mdl_con1'.
 
2225
connection mdl_con1;
 
2226
--echo # Reap RENAME TABLE.
 
2227
--error ER_TABLE_EXISTS_ERROR
 
2228
--reap
 
2229
--echo # 
 
2230
--echo # Switching to connection 'default'.
 
2231
connection default;
 
2232
--echo #
 
2233
--echo # **) The second case is when transaction has a SW lock.
 
2234
--echo #
 
2235
begin;
 
2236
delete from t1 limit 1;
 
2237
--echo # 
 
2238
--echo # Switching to connection 'mdl_con1'.
 
2239
connection mdl_con1;
 
2240
--echo # Sending:
 
2241
--send rename table t1 to t2;
 
2242
--echo # 
 
2243
--echo # Switching to connection 'default'.
 
2244
connection default;
 
2245
--echo # Wait until RENAME TABLE is blocked creating pending request for X lock.
 
2246
let $wait_condition=
 
2247
select count(*) = 1 from information_schema.processlist
 
2248
where state = "Waiting for table metadata lock" and
 
2249
      info = "rename table t1 to t2";
 
2250
--source include/wait_condition.inc
 
2251
--echo # Check that both SR and SW locks are granted without waiting
 
2252
--echo # and errors.
 
2253
select count(*) from t1;
 
2254
insert into t1 values (1, 1);
 
2255
--echo # Unblock RENAME TABLE.
 
2256
commit;
 
2257
--echo # 
 
2258
--echo # Switching to connection 'mdl_con1'.
 
2259
connection mdl_con1;
 
2260
--echo # Reap RENAME TABLE.
 
2261
--error ER_TABLE_EXISTS_ERROR
 
2262
--reap
 
2263
--echo # 
 
2264
--echo # Switching to connection 'default'.
 
2265
connection default;
 
2266
 
 
2267
--echo # Clean-up.
 
2268
disconnect mdl_con1;
 
2269
disconnect mdl_con2;
 
2270
disconnect mdl_con3;
 
2271
set debug_sync= 'RESET';
 
2272
drop table t1, t2;
 
2273
 
 
2274
 
 
2275
--echo #
 
2276
--echo # Additional coverage for some scenarios in which not quite
 
2277
--echo # correct use of S metadata locks by HANDLER statement might
 
2278
--echo # have caused deadlocks.
 
2279
--echo #
 
2280
--disable_warnings
 
2281
drop table if exists t1, t2;
 
2282
--enable_warnings
 
2283
connect(handler_con1,localhost,root,,);
 
2284
connect(handler_con2,localhost,root,,);
 
2285
connection default;
 
2286
create table t1 (i int);
 
2287
create table t2 (j int);
 
2288
insert into t1 values (1);
 
2289
 
 
2290
--echo #
 
2291
--echo # First, check scenario in which we upgrade SNRW lock to X lock
 
2292
--echo # on a table while having HANDLER READ trying to acquire TL_READ
 
2293
--echo # on the same table.
 
2294
--echo #
 
2295
handler t1 open;
 
2296
--echo # 
 
2297
--echo # Switching to connection 'handler_con1'.
 
2298
connection handler_con1;
 
2299
lock table t1 write;
 
2300
--echo # Upgrade SNRW to X lock.
 
2301
--echo # Sending:
 
2302
--send alter table t1 add column j int;
 
2303
--echo # 
 
2304
--echo # Switching to connection 'handler_con2'.
 
2305
connection handler_con2;
 
2306
--echo # Wait until ALTER is blocked during upgrade.
 
2307
let $wait_condition=
 
2308
  select count(*) = 1 from information_schema.processlist
 
2309
  where state = "Waiting for table metadata lock" and
 
2310
        info = "alter table t1 add column j int";
 
2311
--source include/wait_condition.inc
 
2312
--echo # 
 
2313
--echo # Switching to connection 'default'.
 
2314
connection default;
 
2315
--echo # The below statement should not cause deadlock.
 
2316
--send handler t1 read first;
 
2317
--echo # 
 
2318
--echo # Switching to connection 'handler_con1'.
 
2319
connection handler_con1;
 
2320
--echo # Reap ALTER TABLE.
 
2321
--reap
 
2322
unlock tables;
 
2323
--echo # 
 
2324
--echo # Switching to connection 'default'.
 
2325
connection default;
 
2326
--echo # Reap HANDLER READ.
 
2327
--reap
 
2328
handler t1 close;
 
2329
 
 
2330
--echo #
 
2331
--echo # Now, check scenario in which upgrade of SNRW lock to X lock
 
2332
--echo # can be blocked by HANDLER which is open in connection currently
 
2333
--echo # waiting to get table-lock owned by connection doing upgrade.
 
2334
--echo #
 
2335
handler t1 open;
 
2336
--echo # 
 
2337
--echo # Switching to connection 'handler_con1'.
 
2338
connection handler_con1;
 
2339
lock table t1 write, t2 read;
 
2340
--echo # 
 
2341
--echo # Switching to connection 'default'.
 
2342
connection default;
 
2343
--echo # Execute statement which will be blocked on table-level lock
 
2344
--echo # owned by connection 'handler_con1'.
 
2345
--echo # Sending:
 
2346
--send insert into t2 values (1);
 
2347
--echo # 
 
2348
--echo # Switching to connection 'handler_con1'.
 
2349
connection handler_con1;
 
2350
--echo # Wait until INSERT is blocked on table-level lock.
 
2351
let $wait_condition=
 
2352
  select count(*) = 1 from information_schema.processlist
 
2353
  where state = "Waiting for table level lock" and
 
2354
        info = "insert into t2 values (1)";
 
2355
--source include/wait_condition.inc
 
2356
--echo # Sending 'alter table t1 drop column j'. It should not cause
 
2357
--echo # deadlock.
 
2358
send alter table t1 drop column j;
 
2359
--echo # Switching to connection 'handler_con2'.
 
2360
connection handler_con2;
 
2361
--echo # Wait until ALTER is blocked during upgrade.
 
2362
let $wait_condition=
 
2363
  select count(*) = 1 from information_schema.processlist
 
2364
  where state = "Waiting for table metadata lock" and
 
2365
        info = "alter table t1 drop column j";
 
2366
--source include/wait_condition.inc
 
2367
--echo # 
 
2368
--echo # Switching to connection 'default'.
 
2369
connection default;
 
2370
--echo # Reap INSERT.
 
2371
--error ER_LOCK_ABORTED
 
2372
--reap
 
2373
handler t1 close;
 
2374
--echo #
 
2375
--echo # Switching to connection 'handler_con1'.
 
2376
connection handler_con1;
 
2377
--echo # Reaping 'alter table t1 drop column j'
 
2378
--reap
 
2379
unlock tables;
 
2380
--echo # Switching to connection 'default'.
 
2381
connection default;
 
2382
 
 
2383
--echo # Then, check the scenario in which upgrade of SNRW lock to X
 
2384
--echo # lock is blocked by HANDLER which is open in connection currently
 
2385
--echo # waiting to get SW lock on the same table.
 
2386
--echo #
 
2387
handler t1 open;
 
2388
--echo # 
 
2389
--echo # Switching to connection 'handler_con1'.
 
2390
connection handler_con1;
 
2391
lock table t1 write;
 
2392
--echo # 
 
2393
--echo # Switching to connection 'default'.
 
2394
connection default;
 
2395
--echo # The below insert should be blocked because active SNRW lock on 't1'.
 
2396
--echo # Sending:
 
2397
--send insert into t1 values (1);
 
2398
--echo # 
 
2399
--echo # Switching to connection 'handler_con1'.
 
2400
connection handler_con1;
 
2401
--echo # Wait until INSERT is blocked because of SNRW lock.
 
2402
let $wait_condition=
 
2403
  select count(*) = 1 from information_schema.processlist
 
2404
  where state = "Waiting for table metadata lock" and
 
2405
        info = "insert into t1 values (1)";
 
2406
--source include/wait_condition.inc
 
2407
--echo # The below ALTER TABLE will be blocked because of presence of HANDLER.
 
2408
--echo # Sending:
 
2409
--send alter table t1 add column j int;
 
2410
--echo # 
 
2411
--echo # Switching to connection 'default'.
 
2412
connection default;
 
2413
--echo # INSERT should be chosen as victim for resolving deadlock.
 
2414
--echo # Reaping INSERT.
 
2415
--error ER_LOCK_DEADLOCK
 
2416
--reap
 
2417
--echo # Close HANDLER to unblock ALTER TABLE.
 
2418
handler t1 close;
 
2419
--echo # 
 
2420
--echo # Switching to connection 'handler_con1'.
 
2421
connection handler_con1;
 
2422
--echo # Reaping ALTER TABLE.
 
2423
--reap
 
2424
unlock tables;
 
2425
--echo # 
 
2426
--echo # Switching to connection 'default'.
 
2427
connection default;
 
2428
 
 
2429
--echo #
 
2430
--echo # Finally, test in which upgrade of SNRW lock to X lock is blocked
 
2431
--echo # by HANDLER which is open in connection currently waiting to get
 
2432
--echo # SR lock on the table on which lock is upgraded.
 
2433
--echo #
 
2434
handler t1 open;
 
2435
--echo # 
 
2436
--echo # Switching to connection 'handler_con1'.
 
2437
connection handler_con1;
 
2438
lock table t1 write, t2 write;
 
2439
--echo # 
 
2440
--echo # Switching to connection 'default'.
 
2441
connection default;
 
2442
--echo # The below insert should be blocked because active SNRW lock on 't1'.
 
2443
--echo # Sending:
 
2444
--send insert into t2 values (1);
 
2445
--echo # 
 
2446
--echo # Switching to connection 'handler_con1'.
 
2447
connection handler_con1;
 
2448
--echo # Wait until INSERT is blocked because of SNRW lock.
 
2449
let $wait_condition=
 
2450
  select count(*) = 1 from information_schema.processlist
 
2451
  where state = "Waiting for table metadata lock" and
 
2452
        info = "insert into t2 values (1)";
 
2453
--source include/wait_condition.inc
 
2454
--echo # The below ALTER TABLE will be blocked because of presence of HANDLER.
 
2455
--echo # Sending:
 
2456
--send alter table t1 drop column j;
 
2457
--echo # 
 
2458
--echo # Switching to connection 'default'.
 
2459
connection default;
 
2460
--echo # INSERT should be chosen as victim for resolving deadlock.
 
2461
--echo # Reaping INSERT.
 
2462
--error ER_LOCK_DEADLOCK
 
2463
--reap
 
2464
--echo # Close HANDLER to unblock ALTER TABLE.
 
2465
handler t1 close;
 
2466
--echo # 
 
2467
--echo # Switching to connection 'handler_con1'.
 
2468
connection handler_con1;
 
2469
--echo # Reaping ALTER TABLE.
 
2470
--reap
 
2471
unlock tables;
 
2472
--echo # 
 
2473
--echo # Switching to connection 'default'.
 
2474
connection default;
 
2475
 
 
2476
--echo # Clean-up.
 
2477
disconnect handler_con1;
 
2478
disconnect handler_con2;
 
2479
drop tables t1, t2;
 
2480
 
 
2481
 
 
2482
--echo #
 
2483
--echo # Test coverage for basic deadlock detection in metadata
 
2484
--echo # locking subsystem.
 
2485
--echo #
 
2486
--disable_warnings
 
2487
drop tables if exists t0, t1, t2, t3, t4, t5;
 
2488
--enable_warnings
 
2489
set debug_sync= 'RESET';
 
2490
 
 
2491
connect(deadlock_con1,localhost,root,,);
 
2492
connect(deadlock_con2,localhost,root,,);
 
2493
connect(deadlock_con3,localhost,root,,);
 
2494
connection default;
 
2495
create table t1 (i int);
 
2496
create table t2 (j int);
 
2497
create table t3 (k int);
 
2498
create table t4 (k int);
 
2499
 
 
2500
--echo #
 
2501
--echo # Test for the case in which no deadlock occurs.
 
2502
--echo #
 
2503
 
 
2504
--echo #
 
2505
--echo # Switching to connection 'deadlock_con1'.
 
2506
connection deadlock_con1;
 
2507
begin;
 
2508
insert into t1 values (1);
 
2509
 
 
2510
--echo #
 
2511
--echo # Switching to connection 'deadlock_con2'.
 
2512
connection deadlock_con2;
 
2513
begin;
 
2514
insert into t2 values (1);
 
2515
 
 
2516
--echo #
 
2517
--echo # Switching to connection 'default'.
 
2518
connection default;
 
2519
--echo # Send:
 
2520
--send rename table t2 to t0, t3 to t2, t0 to t3;
 
2521
 
 
2522
--echo #
 
2523
--echo # Switching to connection 'deadlock_con1'.
 
2524
connection deadlock_con1;
 
2525
--echo # Wait until the above RENAME TABLE is blocked because it has to wait
 
2526
--echo # for 'deadlock_con2' which holds shared metadata lock on 't2'.
 
2527
let $wait_condition=
 
2528
  select count(*) = 1 from information_schema.processlist
 
2529
  where state = "Waiting for table metadata lock" and
 
2530
        info = "rename table t2 to t0, t3 to t2, t0 to t3";
 
2531
--source include/wait_condition.inc
 
2532
--echo # The below statement should wait for exclusive metadata lock
 
2533
--echo # on 't2' to go away and should not produce ER_LOCK_DEADLOCK
 
2534
--echo # as no deadlock is possible in this situation.
 
2535
--echo # Send:
 
2536
--send select * from t2;
 
2537
 
 
2538
--echo #
 
2539
--echo # Switching to connection 'deadlock_con2'.
 
2540
connection deadlock_con2;
 
2541
--echo # Wait until the above SELECT * FROM t2 is starts waiting
 
2542
--echo # for an exclusive metadata lock to go away.
 
2543
let $wait_condition=
 
2544
  select count(*) = 1 from information_schema.processlist
 
2545
  where state = "Waiting for table metadata lock" and
 
2546
        info = "select * from t2";
 
2547
--source include/wait_condition.inc
 
2548
--echo #
 
2549
--echo # Unblock RENAME TABLE by releasing shared metadata lock on t2.
 
2550
commit;
 
2551
 
 
2552
--echo #
 
2553
--echo # Switching to connection 'default'.
 
2554
connection default;
 
2555
--echo # Reap RENAME TABLE.
 
2556
--reap
 
2557
 
 
2558
--echo #
 
2559
--echo # Switching to connection 'deadlock_con1'.
 
2560
connection deadlock_con1;
 
2561
--echo # Reap SELECT.
 
2562
--reap
 
2563
 
 
2564
--echo #
 
2565
--echo # Switching to connection 'default'.
 
2566
connection default;
 
2567
--echo #
 
2568
--echo # Let us check that in the process of waiting for conflicting lock
 
2569
--echo # on table 't2' to go away transaction in connection 'deadlock_con1'
 
2570
--echo # has not released metadata lock on table 't1'.
 
2571
--echo # Send:
 
2572
--send rename table t1 to t0, t3 to t1, t0 to t3;
 
2573
 
 
2574
--echo #
 
2575
--echo # Switching to connection 'deadlock_con1'.
 
2576
connection deadlock_con1;
 
2577
--echo # Wait until the above RENAME TABLE is blocked because it has to wait
 
2578
--echo # for 'deadlock_con1' which should still hold shared metadata lock on
 
2579
--echo # table 't1'.
 
2580
let $wait_condition=
 
2581
  select count(*) = 1 from information_schema.processlist
 
2582
  where state = "Waiting for table metadata lock" and
 
2583
        info = "rename table t1 to t0, t3 to t1, t0 to t3";
 
2584
--source include/wait_condition.inc
 
2585
--echo # Commit transaction to unblock RENAME TABLE.
 
2586
commit;
 
2587
 
 
2588
--echo #
 
2589
--echo # Switching to connection 'default'.
 
2590
connection default;
 
2591
--echo # Reap RENAME TABLE.
 
2592
--reap
 
2593
 
 
2594
--echo #
 
2595
--echo # Test for case when deadlock occurs and should be detected immediately.
 
2596
--echo #
 
2597
 
 
2598
--echo #
 
2599
--echo # Switching to connection 'deadlock_con1'.
 
2600
connection deadlock_con1;
 
2601
begin;
 
2602
insert into t2 values (2);
 
2603
 
 
2604
--echo #
 
2605
--echo # Switching to connection 'default'.
 
2606
connection default;
 
2607
--echo # Send:
 
2608
--send rename table t2 to t0, t1 to t2, t0 to t1;
 
2609
 
 
2610
--echo #
 
2611
--echo # Switching to connection 'deadlock_con1'.
 
2612
connection deadlock_con1;
 
2613
--echo # Wait until the above RENAME TABLE is blocked because it has to wait
 
2614
--echo # for 'deadlock_con1' which holds shared metadata lock on 't2'.
 
2615
let $wait_condition=
 
2616
  select count(*) = 1 from information_schema.processlist
 
2617
  where state = "Waiting for table metadata lock" and
 
2618
        info = "rename table t2 to t0, t1 to t2, t0 to t1";
 
2619
--source include/wait_condition.inc
 
2620
--echo # 
 
2621
--echo # The below statement should not wait as doing so will cause deadlock.
 
2622
--echo # Instead it should fail and emit ER_LOCK_DEADLOCK statement.
 
2623
--error ER_LOCK_DEADLOCK
 
2624
select * from t1;
 
2625
 
 
2626
--echo #
 
2627
--echo # Let us check that failure of the above statement has not released
 
2628
--echo # metadata lock on table 't1', i.e. that RENAME TABLE is still blocked.
 
2629
let $wait_condition=
 
2630
  select count(*) = 1 from information_schema.processlist
 
2631
  where state = "Waiting for table metadata lock" and
 
2632
        info = "rename table t2 to t0, t1 to t2, t0 to t1";
 
2633
--source include/wait_condition.inc
 
2634
--echo # Commit transaction to unblock RENAME TABLE.
 
2635
commit;
 
2636
 
 
2637
--echo #
 
2638
--echo # Switching to connection 'default'.
 
2639
connection default;
 
2640
--echo # Reap RENAME TABLE.
 
2641
--reap
 
2642
 
 
2643
--echo #
 
2644
--echo # Test for the case in which deadlock also occurs but not immediately.
 
2645
--echo #
 
2646
 
 
2647
--echo #
 
2648
--echo # Switching to connection 'deadlock_con1'.
 
2649
connection deadlock_con1;
 
2650
begin;
 
2651
insert into t2 values (1);
 
2652
 
 
2653
--echo #
 
2654
--echo # Switching to connection 'default'.
 
2655
connection default;
 
2656
lock table t1 write;
 
2657
 
 
2658
--echo #
 
2659
--echo # Switching to connection 'deadlock_con1'.
 
2660
connection deadlock_con1;
 
2661
--echo # The below SELECT statement should wait for metadata lock
 
2662
--echo # on table 't1' and should not produce ER_LOCK_DEADLOCK
 
2663
--echo # immediately as no deadlock is possible at the moment.
 
2664
--send select * from t1;
 
2665
 
 
2666
--echo #
 
2667
--echo # Switching to connection 'deadlock_con2'.
 
2668
connection deadlock_con2;
 
2669
--echo # Wait until the above SELECT * FROM t1 is starts waiting
 
2670
--echo # for an UNRW metadata lock to go away.
 
2671
let $wait_condition=
 
2672
  select count(*) = 1 from information_schema.processlist
 
2673
  where state = "Waiting for table metadata lock" and info = "select * from t1";
 
2674
--source include/wait_condition.inc
 
2675
 
 
2676
--echo # Send RENAME TABLE statement that will deadlock with the
 
2677
--echo # SELECT statement and thus should abort the latter.
 
2678
--send rename table t1 to t0, t2 to t1, t0 to t2;
 
2679
 
 
2680
--echo #
 
2681
--echo # Switching to connection 'default'.
 
2682
connection default;
 
2683
--echo # Wait till above RENAME TABLE is blocked while holding
 
2684
--echo # pending X lock on t1.
 
2685
let $wait_condition=
 
2686
  select count(*) = 1 from information_schema.processlist
 
2687
  where state = "Waiting for table metadata lock" and
 
2688
        info = "rename table t1 to t0, t2 to t1, t0 to t2";
 
2689
--source include/wait_condition.inc
 
2690
--echo # Allow the above RENAME TABLE to acquire lock on t1 and
 
2691
--echo # create pending lock on t2 thus creating deadlock.
 
2692
unlock tables;
 
2693
 
 
2694
--echo #
 
2695
--echo # Switching to connection 'deadlock_con1'.
 
2696
connection deadlock_con1;
 
2697
--echo # Since the latest RENAME TABLE entered in deadlock with SELECT
 
2698
--echo # statement the latter should be aborted and emit ER_LOCK_DEADLOCK
 
2699
--echo # error.
 
2700
--echo # Reap SELECT * FROM t1.
 
2701
--error ER_LOCK_DEADLOCK
 
2702
--reap
 
2703
 
 
2704
--echo #
 
2705
--echo # Again let us check that failure of the SELECT statement has not
 
2706
--echo # released metadata lock on table 't2', i.e. that the latest RENAME
 
2707
--echo # is blocked.
 
2708
let $wait_condition=
 
2709
  select count(*) = 1 from information_schema.processlist
 
2710
  where state = "Waiting for table metadata lock" and
 
2711
        info = "rename table t1 to t0, t2 to t1, t0 to t2";
 
2712
--source include/wait_condition.inc
 
2713
--echo # Commit transaction to unblock this RENAME TABLE.
 
2714
commit;
 
2715
 
 
2716
--echo #
 
2717
--echo # Switching to connection 'deadlock_con2'.
 
2718
connection deadlock_con2;
 
2719
--echo # Reap RENAME TABLE ... .
 
2720
--reap;
 
2721
 
 
2722
--echo #
 
2723
--echo # Switching to connection 'default'.
 
2724
connection default;
 
2725
 
 
2726
drop tables t1, t2, t3, t4;
 
2727
 
 
2728
--echo #
 
2729
--echo # Now, test case which shows that deadlock detection empiric
 
2730
--echo # also takes into account requests for metadata lock upgrade.
 
2731
--echo #
 
2732
create table t1 (i int);
 
2733
insert into t1 values (1);
 
2734
--echo # Avoid race which occurs when SELECT in 'deadlock_con1' connection
 
2735
--echo # accesses table before the above INSERT unlocks the table and thus
 
2736
--echo # its result becomes visible to other connections.
 
2737
select * from t1;
 
2738
 
 
2739
--echo #
 
2740
--echo # Switching to connection 'deadlock_con1'.
 
2741
connection deadlock_con1;
 
2742
begin;
 
2743
select * from t1;
 
2744
 
 
2745
--echo #
 
2746
--echo # Switching to connection 'default'.
 
2747
connection default;
 
2748
--echo # Send:
 
2749
--send alter table t1 add column j int, rename to t2;
 
2750
 
 
2751
--echo #
 
2752
--echo # Switching to connection 'deadlock_con1'.
 
2753
connection deadlock_con1;
 
2754
--echo # Wait until the above ALTER TABLE ... RENAME acquires exclusive
 
2755
--echo # metadata lock on 't2' and starts waiting for connection
 
2756
--echo # 'deadlock_con1' which holds shared lock on 't1'.
 
2757
let $wait_condition=
 
2758
  select count(*) = 1 from information_schema.processlist
 
2759
  where state = "Waiting for table metadata lock" and
 
2760
        info = "alter table t1 add column j int, rename to t2";
 
2761
--source include/wait_condition.inc
 
2762
 
 
2763
--echo # The below statement should not wait as it will cause deadlock.
 
2764
--echo # An appropriate error should be reported instead.
 
2765
--error ER_LOCK_DEADLOCK
 
2766
select * from t2;
 
2767
 
 
2768
--echo # Again let us check that failure of the above statement has not
 
2769
--echo # released all metadata locks in connection 'deadlock_con1' and
 
2770
--echo # so ALTER TABLE ... RENAME is still blocked.
 
2771
let $wait_condition=
 
2772
  select count(*) = 1 from information_schema.processlist
 
2773
  where state = "Waiting for table metadata lock" and
 
2774
        info = "alter table t1 add column j int, rename to t2";
 
2775
--source include/wait_condition.inc
 
2776
 
 
2777
--echo # Commit transaction to unblock ALTER TABLE ... RENAME.
 
2778
commit;
 
2779
 
 
2780
--echo #
 
2781
--echo # Switching to connection 'default'.
 
2782
connection default;
 
2783
--echo # Reap ALTER TABLE ... RENAME.
 
2784
--reap
 
2785
 
 
2786
drop table t2;
 
2787
 
 
2788
--echo #
 
2789
--echo # Test that in situation when MDL subsystem detects a deadlock
 
2790
--echo # but it turns out that it can be resolved by backing-off locks
 
2791
--echo # acquired by one of participating transactions (which is
 
2792
--echo # possible when one of transactions consists only of currently
 
2793
--echo # executed statement, e.g. in autocommit mode) no error is
 
2794
--echo # reported.
 
2795
--echo #
 
2796
create table t1 (i int);
 
2797
create table t2 (j int);
 
2798
--echo # Ensure that the below SELECT stops once it has acquired metadata
 
2799
--echo # lock on table 't2'.
 
2800
set debug_sync= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
2801
--echo # Sending:
 
2802
--send select * from t2, t1
 
2803
 
 
2804
--echo #
 
2805
--echo # Switching to connection 'deadlock_con1'.
 
2806
connection deadlock_con1;
 
2807
--echo # Wait till SELECT acquires MDL on 't2' and starts waiting for signal.
 
2808
set debug_sync= 'now WAIT_FOR locked';
 
2809
--echo # Sending:
 
2810
--send lock tables t1 write, t2 write
 
2811
 
 
2812
--echo #
 
2813
--echo # Switching to connection 'deadlock_con2'.
 
2814
connection deadlock_con2;
 
2815
--echo # Wait until LOCK TABLES acquires SNRW lock on 't1' and is blocked
 
2816
--echo # while trying to acquire SNRW lock on 't1'.
 
2817
let $wait_condition=
 
2818
  select count(*) = 1 from information_schema.processlist
 
2819
  where state = "Waiting for table metadata lock" and
 
2820
        info = "lock tables t1 write, t2 write";
 
2821
--source include/wait_condition.inc
 
2822
--echo # Resume SELECT execution, this should eventually unblock LOCK TABLES.
 
2823
set debug_sync= 'now SIGNAL finish';
 
2824
 
 
2825
--echo #
 
2826
--echo # Switching to connection 'deadlock_con1'.
 
2827
connection deadlock_con1;
 
2828
--echo # Reaping LOCK TABLES.
 
2829
--reap
 
2830
unlock tables;
 
2831
 
 
2832
--echo #
 
2833
--echo # Switching to connection 'default'.
 
2834
connection default;
 
2835
--echo # Reaping SELECT. It succeed and not report ER_LOCK_DEADLOCK error.
 
2836
--reap
 
2837
 
 
2838
drop tables t1, t2;
 
2839
 
 
2840
--echo #
 
2841
--echo # Test coverage for situation in which a race has happened
 
2842
--echo # during deadlock detection process which led to unwarranted
 
2843
--echo # ER_LOCK_DEADLOCK error.
 
2844
--echo #
 
2845
create table t1 (i int);
 
2846
 
 
2847
--echo # Ensure that ALTER waits once it has acquired SNW lock.
 
2848
set debug_sync='after_open_table_mdl_shared SIGNAL parked1 WAIT_FOR go1';
 
2849
--echo # Sending:
 
2850
--send alter table t1 add column j int
 
2851
 
 
2852
--echo #
 
2853
--echo # Switching to connection 'deadlock_con1'.
 
2854
connection deadlock_con1;
 
2855
--echo # Wait till ALTER acquires SNW lock and stops.
 
2856
set debug_sync='now WAIT_FOR parked1';
 
2857
--echo # Ensure that INSERT is paused once it detects that there is
 
2858
--echo # a conflicting metadata lock so it has to wait, but before
 
2859
--echo # deadlock detection is run.
 
2860
set debug_sync='mdl_acquire_lock_wait SIGNAL parked2 WAIT_FOR go2';
 
2861
--echo # Sending:
 
2862
--send insert into t1 values ()
 
2863
 
 
2864
--echo #
 
2865
--echo # Switching to connection 'deadlock_con2'.
 
2866
connection deadlock_con2;
 
2867
--echo # Wait till INSERT is paused.
 
2868
set debug_sync='now WAIT_FOR parked2';
 
2869
--echo # Resume ALTER execution. Eventually it will release its
 
2870
--echo # metadata lock and INSERT's request for SW lock will be
 
2871
--echo # satisified.
 
2872
set debug_sync='now SIGNAL go1';
 
2873
 
 
2874
--echo #
 
2875
--echo # Switching to connection 'default'.
 
2876
connection default;
 
2877
--echo # Reaping ALTER TABLE.
 
2878
--reap
 
2879
--echo # Add a new request for SNW lock to waiting graph.
 
2880
--echo # Sending:
 
2881
--send alter table t1 drop column j
 
2882
 
 
2883
--echo #
 
2884
--echo # Switching to connection 'deadlock_con2'.
 
2885
connection deadlock_con2;
 
2886
--echo # Wait until ALTER is blocked.
 
2887
let $wait_condition=
 
2888
  select count(*) = 1 from information_schema.processlist
 
2889
  where state = "Waiting for table metadata lock" and
 
2890
        info = "alter table t1 drop column j";
 
2891
--source include/wait_condition.inc
 
2892
--echo # Resume INSERT so it can start deadlock detection.
 
2893
--echo #
 
2894
--echo # At this point there is a discrepancy between the fact that INSERT's
 
2895
--echo # SW lock is already satisfied, but INSERT's connection is still
 
2896
--echo # marked as waiting for it. Looking for a loop in waiters graph
 
2897
--echo # without additional checks has detected a deadlock (INSERT waits
 
2898
--echo # for SW lock; which is not granted because of pending SNW lock from
 
2899
--echo # ALTER; which waits for active SW lock from INSERT). Since requests
 
2900
--echo # for SW and SNW locks have same weight ALTER was selected as a victim
 
2901
--echo # and ended with ER_LOCK_DEADLOCK error.
 
2902
set debug_sync='now SIGNAL go2';
 
2903
 
 
2904
--echo #
 
2905
--echo # Switching to connection 'deadlock_con1'.
 
2906
connection deadlock_con1;
 
2907
--echo # Reaping INSERT.
 
2908
--reap
 
2909
 
 
2910
--echo #
 
2911
--echo # Switching to connection 'default'.
 
2912
connection default;
 
2913
--echo # Reaping ALTER. It should succeed and not produce ER_LOCK_DEADLOCK.
 
2914
--reap
 
2915
 
 
2916
drop table t1;
 
2917
 
 
2918
--echo #
 
2919
--echo # Now, test for a situation in which deadlock involves waiting not
 
2920
--echo # only in MDL subsystem but also for TDC. Such deadlocks should be
 
2921
--echo # successfully detected. If possible, they should be resolved without
 
2922
--echo # resorting to ER_LOCK_DEADLOCK error.
 
2923
--echo #
 
2924
create table t1(i int);
 
2925
create table t2(j int);
 
2926
 
 
2927
--echo #
 
2928
--echo # First, let us check how we handle a simple scenario involving
 
2929
--echo # waits in MDL and TDC.
 
2930
--echo #
 
2931
set debug_sync= 'RESET';
 
2932
 
 
2933
--echo # Switching to connection 'deadlock_con1'.
 
2934
connection deadlock_con1;
 
2935
--echo # Start a statement, which will acquire SR metadata lock on t1, open it
 
2936
--echo # and then stop, before trying to acquire SW lock on t2 and opening it.
 
2937
set debug_sync='open_tables_after_open_and_process_table SIGNAL parked WAIT_FOR go';
 
2938
--echo # Sending:
 
2939
--send select * from t1 where i in (select j from t2 for update)
 
2940
 
 
2941
--echo # Switching to connection 'deadlock_con2'.
 
2942
connection deadlock_con2;
 
2943
--echo # Wait till the above SELECT stops.
 
2944
set debug_sync='now WAIT_FOR parked';
 
2945
--echo # The below FLUSH TABLES WITH READ LOCK should acquire
 
2946
--echo # SNW locks on t1 and t2 and wait till SELECT closes t1.
 
2947
--echo # Sending:
 
2948
send flush tables t1, t2 with read lock;
 
2949
 
 
2950
--echo # Switching to connection 'deadlock_con3'.
 
2951
connection deadlock_con3;
 
2952
--echo # Wait until FLUSH TABLES WITH t1, t2 READ LOCK starts waiting
 
2953
--echo # for SELECT to close t1.
 
2954
let $wait_condition=
 
2955
  select count(*) = 1 from information_schema.processlist
 
2956
  where state = "Waiting for table flush" and
 
2957
        info = "flush tables t1, t2 with read lock";
 
2958
--source include/wait_condition.inc
 
2959
 
 
2960
--echo # Resume SELECT, so it tries to acquire SW lock on t1 and blocks,
 
2961
--echo # creating a deadlock. This deadlock should be detected and resolved
 
2962
--echo # by backing-off SELECT. As a result FTWRL should be able to finish.
 
2963
set debug_sync='now SIGNAL go';
 
2964
 
 
2965
--echo # Switching to connection 'deadlock_con2'.
 
2966
connection deadlock_con2;
 
2967
--echo # Reap FLUSH TABLES WITH READ LOCK.
 
2968
reap;
 
2969
unlock tables;
 
2970
 
 
2971
--echo # Switching to connection 'deadlock_con1'.
 
2972
connection deadlock_con1;
 
2973
--echo # Reap SELECT.
 
2974
reap;
 
2975
 
 
2976
--echo #
 
2977
--echo # The same scenario with a slightly different order of events
 
2978
--echo # which emphasizes that setting correct deadlock detector weights
 
2979
--echo # for flush waits is important.
 
2980
--echo #
 
2981
set debug_sync= 'RESET';
 
2982
 
 
2983
--echo # Switching to connection 'deadlock_con2'.
 
2984
connection deadlock_con2;
 
2985
set debug_sync='flush_tables_with_read_lock_after_acquire_locks SIGNAL parked WAIT_FOR go';
 
2986
 
 
2987
--echo # The below FLUSH TABLES WITH READ LOCK should acquire
 
2988
--echo # SNW locks on t1 and t2 and wait on debug sync point.
 
2989
--echo # Sending:
 
2990
send flush tables t1, t2 with read lock;
 
2991
 
 
2992
--echo # Switching to connection 'deadlock_con1'.
 
2993
connection deadlock_con1;
 
2994
--echo # Wait till FLUSH TABLE WITH READ LOCK stops.
 
2995
set debug_sync='now WAIT_FOR parked';
 
2996
 
 
2997
--echo # Start statement which will acquire SR metadata lock on t1, open
 
2998
--echo # it and then will block while trying to acquire SW lock on t2.
 
2999
--echo # Sending:
 
3000
send select * from t1 where i in (select j from t2 for update);
 
3001
 
 
3002
--echo # Switching to connection 'deadlock_con3'.
 
3003
connection deadlock_con3;
 
3004
--echo # Wait till the above SELECT blocks.
 
3005
let $wait_condition=
 
3006
  select count(*) = 1 from information_schema.processlist
 
3007
  where state = "Waiting for table metadata lock" and
 
3008
        info = "select * from t1 where i in (select j from t2 for update)";
 
3009
--source include/wait_condition.inc
 
3010
 
 
3011
--echo # Resume FLUSH TABLES, so it tries to flush t1, thus creating
 
3012
--echo # a deadlock. This deadlock should be detected and resolved by
 
3013
--echo # backing-off SELECT. As a result FTWRL should be able to finish.
 
3014
set debug_sync='now SIGNAL go';
 
3015
 
 
3016
--echo # Switching to connection 'deadlock_con2'.
 
3017
connection deadlock_con2;
 
3018
--echo # Reap FLUSH TABLES WITH READ LOCK.
 
3019
reap;
 
3020
unlock tables;
 
3021
 
 
3022
--echo # Switching to connection 'deadlock_con1'.
 
3023
connection deadlock_con1;
 
3024
--echo # Reap SELECT.
 
3025
reap;
 
3026
 
 
3027
--echo #
 
3028
--echo # Now a more complex scenario involving two connections
 
3029
--echo # waiting for MDL and one for TDC.
 
3030
--echo #
 
3031
set debug_sync= 'RESET';
 
3032
 
 
3033
--echo # Switching to connection 'deadlock_con1'.
 
3034
connection deadlock_con1;
 
3035
--echo # Start a statement which will acquire SR metadata lock on t2, open it
 
3036
--echo # and then stop, before trying to acquire SR on t1 and opening it.
 
3037
set debug_sync='open_tables_after_open_and_process_table SIGNAL parked WAIT_FOR go';
 
3038
--echo # Sending:
 
3039
send select * from t2, t1;
 
3040
 
 
3041
--echo # Switching to connection 'deadlock_con2'.
 
3042
connection deadlock_con2;
 
3043
--echo # Wait till the above SELECT stops.
 
3044
set debug_sync='now WAIT_FOR parked';
 
3045
--echo # The below FLUSH TABLES WITH READ LOCK should acquire
 
3046
--echo # SNW locks on t2 and wait till SELECT closes t2.
 
3047
--echo # Sending:
 
3048
send flush tables t2 with read lock;
 
3049
 
 
3050
--echo # Switching to connection 'deadlock_con3'.
 
3051
connection deadlock_con3;
 
3052
--echo # Wait until FLUSH TABLES WITH READ LOCK starts waiting
 
3053
--echo # for SELECT to close t2.
 
3054
let $wait_condition=
 
3055
  select count(*) = 1 from information_schema.processlist
 
3056
  where state = "Waiting for table flush" and
 
3057
        info = "flush tables t2 with read lock";
 
3058
--source include/wait_condition.inc
 
3059
 
 
3060
--echo # The below DROP TABLES should acquire X lock on t1 and start
 
3061
--echo # waiting for X lock on t2.
 
3062
--echo # Sending:
 
3063
send drop tables t1, t2;
 
3064
 
 
3065
--echo # Switching to connection 'default'.
 
3066
connection default;
 
3067
--echo # Wait until DROP TABLES starts waiting for X lock on t2.
 
3068
let $wait_condition=
 
3069
  select count(*) = 1 from information_schema.processlist
 
3070
  where state = "Waiting for table metadata lock" and
 
3071
        info = "drop tables t1, t2";
 
3072
--source include/wait_condition.inc
 
3073
 
 
3074
--echo # Resume SELECT, so it tries to acquire SR lock on t1 and blocks,
 
3075
--echo # creating a deadlock. This deadlock should be detected and resolved
 
3076
--echo # by backing-off SELECT. As a result, FTWRL should be able to finish.
 
3077
set debug_sync='now SIGNAL go';
 
3078
 
 
3079
--echo # Switching to connection 'deadlock_con2'.
 
3080
connection deadlock_con2;
 
3081
--echo # Reap FLUSH TABLES WITH READ LOCK.
 
3082
reap;
 
3083
--echo # Unblock DROP TABLES.
 
3084
unlock tables;
 
3085
 
 
3086
--echo # Switching to connection 'deadlock_con3'.
 
3087
connection deadlock_con3;
 
3088
--echo # Reap DROP TABLES.
 
3089
reap;
 
3090
 
 
3091
--echo # Switching to connection 'deadlock_con1'.
 
3092
connection deadlock_con1;
 
3093
--echo # Reap SELECT. It should emit error about missing table.
 
3094
--error ER_NO_SUCH_TABLE
 
3095
reap;
 
3096
 
 
3097
--echo # Switching to connection 'default'.
 
3098
connection default;
 
3099
 
 
3100
set debug_sync= 'RESET';
 
3101
 
 
3102
disconnect deadlock_con1;
 
3103
disconnect deadlock_con2;
 
3104
disconnect deadlock_con3;
 
3105
 
 
3106
 
 
3107
--echo #
 
3108
--echo # Test for a scenario in which FLUSH TABLES <list> WITH READ LOCK
 
3109
--echo # used to erroneously release metadata locks.
 
3110
--echo # 
 
3111
connect(con1,localhost,root,,);
 
3112
connect(con2,localhost,root,,);
 
3113
connection default;
 
3114
--disable_warnings
 
3115
drop tables if exists t1, t2;
 
3116
--enable_warnings
 
3117
set debug_sync= 'RESET';
 
3118
create table t1(i int);
 
3119
create table t2(j int);
 
3120
 
 
3121
--echo # Switching to connection 'con2'.
 
3122
connection con2;
 
3123
set debug_sync='open_tables_after_open_and_process_table SIGNAL parked WAIT_FOR go';
 
3124
 
 
3125
--echo # The below FLUSH TABLES <list> WITH READ LOCK should acquire
 
3126
--echo # SNW locks on t1 and t2, open table t1 and block on the debug
 
3127
--echo # sync point.
 
3128
--echo # Sending:
 
3129
send flush tables t1, t2 with read lock;
 
3130
 
 
3131
--echo # Switching to connection 'con1'.
 
3132
connection con1;
 
3133
--echo # Wait till FLUSH TABLES <list> WITH READ LOCK stops.
 
3134
set debug_sync='now WAIT_FOR parked';
 
3135
 
 
3136
--echo # Start a statement which will flush all tables and thus
 
3137
--echo # invalidate table t1 open by FLUSH TABLES <list> WITH READ LOCK.
 
3138
--echo # Sending:
 
3139
send flush tables;
 
3140
 
 
3141
--echo # Switching to connection 'default'.
 
3142
connection default;
 
3143
--echo # Wait till the above FLUSH TABLES blocks.
 
3144
let $wait_condition=
 
3145
  select count(*) = 1 from information_schema.processlist
 
3146
  where state = "Waiting for table flush" and
 
3147
        info = "flush tables";
 
3148
--source include/wait_condition.inc
 
3149
 
 
3150
--echo # Resume FLUSH TABLES <list> WITH READ LOCK, so it tries to open t2
 
3151
--echo # discovers that its t1 is obsolete and tries to reopen all tables.
 
3152
--echo # Such reopen should not cause releasing of SNW metadata locks
 
3153
--echo # which would result in assertion failures.
 
3154
set debug_sync='now SIGNAL go';
 
3155
 
 
3156
--echo # Switching to connection 'con2'.
 
3157
connection con2;
 
3158
--echo # Reap FLUSH TABLES <list> WITH READ LOCK.
 
3159
reap;
 
3160
unlock tables;
 
3161
 
 
3162
--echo # Switching to connection 'con1'.
 
3163
connection con1;
 
3164
--echo # Reap FLUSH TABLES.
 
3165
reap;
 
3166
 
 
3167
--echo # Clean-up.
 
3168
--echo # Switching to connection 'default'.
 
3169
connection default;
 
3170
drop tables t1, t2;
 
3171
set debug_sync= 'RESET';
 
3172
disconnect con1;
 
3173
disconnect con2;
 
3174
 
 
3175
 
 
3176
--echo #
 
3177
--echo # Test for bug #46748 "Assertion in MDL_context::wait_for_locks()
 
3178
--echo # on INSERT + CREATE TRIGGER".
 
3179
--echo #
 
3180
--disable_warnings
 
3181
drop tables if exists t1, t2, t3, t4, t5;
 
3182
--enable_warnings
 
3183
--echo # Let us simulate scenario in which we open some tables from extended
 
3184
--echo # part of prelocking set but then encounter conflicting metadata lock,
 
3185
--echo # so have to back-off and wait for it to go away.
 
3186
connect (con1root,localhost,root,,test,,);
 
3187
connect (con2root,localhost,root,,test,,);
 
3188
connection default;
 
3189
create table t1 (i int);
 
3190
create table t2 (j int);
 
3191
create table t3 (k int);
 
3192
create table t4 (l int);
 
3193
create trigger t1_bi before insert on t1 for each row
 
3194
  insert into t2 values (new.i);
 
3195
create trigger t2_bi before insert on t2 for each row
 
3196
  insert into t3 values (new.j);
 
3197
--echo #
 
3198
--echo # Switching to connection 'con1root'.
 
3199
connection con1root;
 
3200
lock tables t4 read;
 
3201
--echo #
 
3202
--echo # Switching to connection 'con2root'.
 
3203
connection con2root;
 
3204
--echo # Send :
 
3205
--send rename table t3 to t5, t4 to t3;
 
3206
--echo #
 
3207
--echo # Switching to connection 'default'.
 
3208
connection default;
 
3209
--echo # Wait until the above RENAME TABLE adds pending requests for exclusive
 
3210
--echo # metadata lock on its tables and blocks due to 't4' being used by LOCK
 
3211
--echo # TABLES.
 
3212
let $wait_condition= select count(*)= 1 from information_schema.processlist
 
3213
                       where state= 'Waiting for table metadata lock' and
 
3214
                             info='rename table t3 to t5, t4 to t3';
 
3215
--source include/wait_condition.inc
 
3216
--echo # Send :
 
3217
--send insert into t1 values (1);
 
3218
--echo #
 
3219
--echo # Switching to connection 'con1root'.
 
3220
connection con1root;
 
3221
--echo # Wait until INSERT statement waits due to encountering pending
 
3222
--echo # exclusive metadata lock on 't3'.
 
3223
let $wait_condition= select count(*)= 1 from information_schema.processlist
 
3224
                       where state= 'Waiting for table metadata lock' and
 
3225
                             info='insert into t1 values (1)';
 
3226
--source include/wait_condition.inc
 
3227
unlock tables;
 
3228
--echo #
 
3229
--echo # Switching to connection 'con2root'.
 
3230
connection con2root;
 
3231
--echo # Reap RENAME TABLE.
 
3232
--reap
 
3233
--echo #
 
3234
--echo # Switching to connection 'default'.
 
3235
connection default;
 
3236
--echo # Reap INSERT.
 
3237
--reap
 
3238
--echo # Clean-up.
 
3239
disconnect con1root;
 
3240
disconnect con2root;
 
3241
drop tables t1, t2, t3, t5;
 
3242
 
 
3243
 
 
3244
--echo #
 
3245
--echo # Bug#42546 - Backup: RESTORE fails, thinking it finds an existing table
 
3246
--echo #
 
3247
 
 
3248
--disable_warnings
 
3249
DROP TABLE IF EXISTS t1;
 
3250
--enable_warnings
 
3251
set @save_log_output=@@global.log_output;
 
3252
set global log_output=file;
 
3253
 
 
3254
connect(con2, localhost, root,,);
 
3255
 
 
3256
--echo #
 
3257
--echo # Test 1: CREATE TABLE
 
3258
--echo #
 
3259
 
 
3260
--echo # Connection 2 
 
3261
connection con2;
 
3262
--echo # Start insert on the not-yet existing table
 
3263
--echo # Wait after taking the MDL lock
 
3264
SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
3265
--send INSERT INTO t1 VALUES(1,"def")
 
3266
 
 
3267
--echo # Connection 1
 
3268
connection default;
 
3269
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
3270
--echo # Now INSERT has a MDL on the non-existent table t1.
 
3271
 
 
3272
--echo #
 
3273
--echo # Continue the INSERT once CREATE waits for exclusive lock
 
3274
SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL finish';
 
3275
--echo # Try to create that table.
 
3276
--send CREATE TABLE t1 (c1 INT, c2 VARCHAR(100), KEY(c1))
 
3277
 
 
3278
--echo # Connection 2
 
3279
--echo # Insert fails
 
3280
connection con2;
 
3281
--error ER_NO_SUCH_TABLE
 
3282
--reap
 
3283
 
 
3284
--echo # Connection 1
 
3285
connection default;
 
3286
--reap;
 
3287
SET DEBUG_SYNC= 'RESET';
 
3288
SHOW TABLES;
 
3289
 
 
3290
--disable_warnings
 
3291
DROP TABLE IF EXISTS t1;
 
3292
--enable_warnings
 
3293
 
 
3294
--echo #
 
3295
--echo # Test 2: CREATE TABLE LIKE
 
3296
--echo #
 
3297
 
 
3298
CREATE TABLE t2 (c1 INT, c2 VARCHAR(100), KEY(c1));
 
3299
 
 
3300
--echo # Connection 2 
 
3301
connection con2;
 
3302
--echo # Start insert on the not-yet existing table
 
3303
--echo # Wait after taking the MDL
 
3304
SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL locked WAIT_FOR finish';
 
3305
--send INSERT INTO t1 VALUES(1,"def")
 
3306
 
 
3307
--echo # Connection 1
 
3308
connection default;
 
3309
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
3310
--echo # Now INSERT has a MDL on the non-existent table t1.
 
3311
 
 
3312
--echo #
 
3313
--echo # Continue the INSERT once CREATE waits for exclusive lock
 
3314
SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL finish';
 
3315
--echo # Try to create that table.
 
3316
--send CREATE TABLE t1 LIKE t2
 
3317
 
 
3318
--echo # Connection 2
 
3319
--echo # Insert fails
 
3320
connection con2;
 
3321
--error ER_NO_SUCH_TABLE
 
3322
--reap
 
3323
 
 
3324
--echo # Connection 1
 
3325
connection default;
 
3326
--reap
 
3327
SET DEBUG_SYNC= 'RESET';
 
3328
SHOW TABLES;
 
3329
 
 
3330
DROP TABLE t2;
 
3331
disconnect con2;
 
3332
--disable_warnings
 
3333
DROP TABLE IF EXISTS t1;
 
3334
--enable_warnings
 
3335
 
 
3336
set global log_output=@save_log_output;
 
3337
 
 
3338
 
 
3339
--echo #
 
3340
--echo # Bug #46044 "MDL deadlock on LOCK TABLE + CREATE TABLE HIGH_PRIORITY
 
3341
--echo #             FOR UPDATE"
 
3342
--echo #
 
3343
--disable_warnings
 
3344
drop tables if exists t1, t2;
 
3345
--enable_warnings
 
3346
connect (con46044, localhost, root,,);
 
3347
connect (con46044_2, localhost, root,,);
 
3348
connection default;
 
3349
create table t1 (i int);
 
3350
 
 
3351
--echo # Let us check that we won't deadlock if during filling
 
3352
--echo # of I_S table we encounter conflicting metadata lock
 
3353
--echo # which owner is in its turn waiting for our connection.
 
3354
lock tables t1 read;
 
3355
 
 
3356
--echo # Switching to connection 'con46044'.
 
3357
connection con46044;
 
3358
--echo # Sending:
 
3359
--send create table t2 select * from t1 for update;
 
3360
 
 
3361
--echo # Switching to connection 'default'.
 
3362
connection default;
 
3363
--echo # Waiting until CREATE TABLE ... SELECT ... is blocked.
 
3364
let $wait_condition=
 
3365
  select count(*) = 1 from information_schema.processlist
 
3366
  where state = "Waiting for table level lock" and
 
3367
        info = "create table t2 select * from t1 for update";
 
3368
--source include/wait_condition.inc
 
3369
 
 
3370
--echo # First let us check that SHOW FIELDS/DESCRIBE doesn't
 
3371
--echo # gets blocked and emits and error.
 
3372
--error ER_WARN_I_S_SKIPPED_TABLE
 
3373
show fields from t2;
 
3374
 
 
3375
--echo # Now test for I_S query which reads only .FRMs.
 
3376
--echo #
 
3377
--echo # Query below should only emit a warning.
 
3378
select column_name from information_schema.columns
 
3379
  where table_schema='test' and table_name='t2';
 
3380
 
 
3381
--echo # Finally, test for I_S query which does full-blown table open.
 
3382
--echo #
 
3383
--echo # Query below should not be blocked. Warning message should be
 
3384
--echo # stored in the 'table_comment' column.
 
3385
select table_name, table_type, auto_increment, table_comment
 
3386
  from information_schema.tables where table_schema='test' and table_name='t2';
 
3387
 
 
3388
--echo # Switching to connection 'default'.
 
3389
connection default;
 
3390
unlock tables;
 
3391
 
 
3392
--echo # Switching to connection 'con46044'.
 
3393
connection con46044;
 
3394
--echo # Reaping CREATE TABLE ... SELECT ... .
 
3395
--reap
 
3396
drop table t2;
 
3397
 
 
3398
--echo #
 
3399
--echo # Let us also check that queries to I_S wait for conflicting metadata
 
3400
--echo # locks to go away instead of skipping table with a warning in cases
 
3401
--echo # when deadlock is not possible. This is a nice thing from compatibility
 
3402
--echo # and ease of use points of view.
 
3403
--echo #
 
3404
--echo # We check same three queries to I_S in this new situation.
 
3405
 
 
3406
--echo # Switching to connection 'con46044_2'.
 
3407
connection con46044_2;
 
3408
lock tables t1 read;
 
3409
 
 
3410
--echo # Switching to connection 'con46044'.
 
3411
connection con46044;
 
3412
--echo # Sending:
 
3413
--send create table t2 select * from t1 for update;
 
3414
 
 
3415
--echo # Switching to connection 'default'.
 
3416
connection default;
 
3417
--echo # Waiting until CREATE TABLE ... SELECT ... is blocked.
 
3418
let $wait_condition=
 
3419
  select count(*) = 1 from information_schema.processlist
 
3420
  where state = "Waiting for table level lock" and
 
3421
        info = "create table t2 select * from t1 for update";
 
3422
--source include/wait_condition.inc
 
3423
 
 
3424
--echo # Let us check that SHOW FIELDS/DESCRIBE gets blocked.
 
3425
--echo # Sending:
 
3426
--send show fields from t2;
 
3427
 
 
3428
--echo # Switching to connection 'con46044_2'.
 
3429
connection con46044_2;
 
3430
--echo # Wait until SHOW FIELDS gets blocked.
 
3431
let $wait_condition=
 
3432
  select count(*) = 1 from information_schema.processlist
 
3433
  where state = "Waiting for table metadata lock" and
 
3434
        info = "show fields from t2";
 
3435
--source include/wait_condition.inc
 
3436
 
 
3437
unlock tables;
 
3438
 
 
3439
--echo # Switching to connection 'con46044'.
 
3440
connection con46044;
 
3441
--echo # Reaping CREATE TABLE ... SELECT ... .
 
3442
--reap
 
3443
 
 
3444
--echo # Switching to connection 'default'.
 
3445
connection default;
 
3446
--echo # Reaping SHOW FIELDS ...
 
3447
--reap
 
3448
drop table t2;
 
3449
 
 
3450
--echo # Switching to connection 'con46044_2'.
 
3451
connection con46044_2;
 
3452
lock tables t1 read;
 
3453
 
 
3454
--echo # Switching to connection 'con46044'.
 
3455
connection con46044;
 
3456
--echo # Sending:
 
3457
--send create table t2 select * from t1 for update;
 
3458
 
 
3459
--echo # Switching to connection 'default'.
 
3460
connection default;
 
3461
--echo # Waiting until CREATE TABLE ... SELECT ... is blocked.
 
3462
let $wait_condition=
 
3463
  select count(*) = 1 from information_schema.processlist
 
3464
  where state = "Waiting for table level lock" and
 
3465
        info = "create table t2 select * from t1 for update";
 
3466
--source include/wait_condition.inc
 
3467
 
 
3468
--echo # Check that I_S query which reads only .FRMs gets blocked.
 
3469
--echo # Sending:
 
3470
--send select column_name from information_schema.columns where table_schema='test' and table_name='t2';
 
3471
 
 
3472
--echo # Switching to connection 'con46044_2'.
 
3473
connection con46044_2;
 
3474
--echo # Wait until SELECT COLUMN_NAME FROM I_S.COLUMNS  gets blocked.
 
3475
let $wait_condition=
 
3476
  select count(*) = 1 from information_schema.processlist
 
3477
  where state = "Waiting for table metadata lock" and
 
3478
        info like "select column_name from information_schema.columns%";
 
3479
--source include/wait_condition.inc
 
3480
 
 
3481
unlock tables;
 
3482
 
 
3483
--echo # Switching to connection 'con46044'.
 
3484
connection con46044;
 
3485
--echo # Reaping CREATE TABLE ... SELECT ... .
 
3486
--reap
 
3487
 
 
3488
--echo # Switching to connection 'default'.
 
3489
connection default;
 
3490
--echo # Reaping SELECT COLUMN_NAME FROM I_S.COLUMNS
 
3491
--reap
 
3492
drop table t2;
 
3493
 
 
3494
--echo # Switching to connection 'con46044_2'.
 
3495
connection con46044_2;
 
3496
lock tables t1 read;
 
3497
 
 
3498
--echo # Switching to connection 'con46044'.
 
3499
connection con46044;
 
3500
--echo # Sending:
 
3501
--send create table t2 select * from t1 for update;
 
3502
 
 
3503
--echo # Switching to connection 'default'.
 
3504
connection default;
 
3505
--echo # Waiting until CREATE TABLE ... SELECT ... is blocked.
 
3506
let $wait_condition=
 
3507
  select count(*) = 1 from information_schema.processlist
 
3508
  where state = "Waiting for table level lock" and
 
3509
        info = "create table t2 select * from t1 for update";
 
3510
--source include/wait_condition.inc
 
3511
 
 
3512
--echo # Finally, check that I_S query which does full-blown table open
 
3513
--echo # also gets blocked.
 
3514
--echo # Sending:
 
3515
--send select table_name, table_type, auto_increment, table_comment from information_schema.tables where table_schema='test' and table_name='t2';
 
3516
 
 
3517
--echo # Switching to connection 'con46044_2'.
 
3518
connection con46044_2;
 
3519
--echo # Wait until SELECT ... FROM I_S.TABLES gets blocked.
 
3520
let $wait_condition=
 
3521
  select count(*) = 1 from information_schema.processlist
 
3522
  where state = "Waiting for table metadata lock" and
 
3523
        info like "select table_name, table_type, auto_increment, table_comment from information_schema.tables%";
 
3524
--source include/wait_condition.inc
 
3525
 
 
3526
unlock tables;
 
3527
 
 
3528
--echo # Switching to connection 'con46044'.
 
3529
connection con46044;
 
3530
--echo # Reaping CREATE TABLE ... SELECT ... .
 
3531
--reap
 
3532
 
 
3533
--echo # Switching to connection 'default'.
 
3534
connection default;
 
3535
--echo # Reaping SELECT ... FROM I_S.TABLES
 
3536
--reap
 
3537
drop table t2;
 
3538
 
 
3539
--echo # Switching to connection 'default'.
 
3540
connection default;
 
3541
--echo # Clean-up.
 
3542
disconnect con46044;
 
3543
disconnect con46044_2;
 
3544
drop table t1;
 
3545
 
 
3546
 
 
3547
--echo #
 
3548
--echo # Test for bug #46273 "MySQL 5.4.4 new MDL: Bug#989 is not fully fixed
 
3549
--echo #                      in case of ALTER".
 
3550
--echo #
 
3551
--disable_warnings
 
3552
drop table if exists t1;
 
3553
--enable_warnings
 
3554
set debug_sync= 'RESET';
 
3555
connect (con46273,localhost,root,,test,,);
 
3556
connection default;
 
3557
create table t1 (c1 int primary key, c2 int, c3 int);
 
3558
insert into t1 values (1,1,0),(2,2,0),(3,3,0),(4,4,0),(5,5,0);
 
3559
 
 
3560
begin;
 
3561
select * from t1 where c2 = 3;
 
3562
 
 
3563
--echo #
 
3564
--echo # Switching to connection 'con46273'.
 
3565
connection con46273;
 
3566
set debug_sync='after_lock_tables_takes_lock SIGNAL alter_table_locked WAIT_FOR alter_go';
 
3567
--send alter table t1 add column e int, rename to t2;
 
3568
 
 
3569
--echo #
 
3570
--echo # Switching to connection 'default'.
 
3571
connection default;
 
3572
set debug_sync='now WAIT_FOR alter_table_locked';
 
3573
set debug_sync='mdl_acquire_lock_wait SIGNAL alter_go';
 
3574
--echo # The below statement should get ER_LOCK_DEADLOCK error
 
3575
--echo # (i.e. it should not allow ALTER to proceed, and then
 
3576
--echo # fail due to 't1' changing its name to 't2').
 
3577
--error ER_LOCK_DEADLOCK
 
3578
update t1 set c3=c3+1 where c2 = 3;
 
3579
 
 
3580
--echo #
 
3581
--echo # Let us check that failure of the above statement has not released
 
3582
--echo # metadata lock on table 't1', i.e. that ALTER TABLE is still blocked.
 
3583
let $wait_condition=
 
3584
  select count(*) = 1 from information_schema.processlist
 
3585
  where state = "Waiting for table metadata lock" and
 
3586
        info = "alter table t1 add column e int, rename to t2";
 
3587
--source include/wait_condition.inc
 
3588
 
 
3589
--echo # Unblock ALTER TABLE by commiting transaction and thus releasing
 
3590
--echo # metadata lock on 't1'.
 
3591
commit;
 
3592
 
 
3593
--echo #
 
3594
--echo # Switching to connection 'con46273'.
 
3595
connection con46273;
 
3596
--echo # Reap ALTER TABLE.
 
3597
--reap
 
3598
 
 
3599
--echo #
 
3600
--echo # Switching to connection 'default'.
 
3601
connection default;
 
3602
disconnect con46273;
 
3603
--echo # Clean-up.
 
3604
set debug_sync= 'RESET';
 
3605
drop table t2;
 
3606
 
 
3607
 
 
3608
--echo #
 
3609
--echo # Test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK
 
3610
--echo #                      and DML".
 
3611
--echo #
 
3612
--disable_warnings
 
3613
drop tables if exists t1;
 
3614
--enable_warnings
 
3615
connect (con46673, localhost, root,,);
 
3616
connection default;
 
3617
create table t1 (i int);
 
3618
 
 
3619
--echo # Switching to connection 'con46673'.
 
3620
connection con46673;
 
3621
begin;
 
3622
insert into t1 values (1);
 
3623
 
 
3624
--echo # Switching to connection 'default'.
 
3625
connection default;
 
3626
--echo # Statement below should not get blocked. And if after some
 
3627
--echo # changes to code it is there should not be a deadlock between
 
3628
--echo # it and transaction from connection 'con46673'.
 
3629
flush tables with read lock;
 
3630
unlock tables;
 
3631
 
 
3632
--echo # Switching to connection 'con46673'.
 
3633
connection con46673;
 
3634
delete from t1 where i = 1;
 
3635
commit;
 
3636
 
 
3637
--echo # Switching to connection 'default'.
 
3638
connection default;
 
3639
--echo # Clean-up
 
3640
disconnect con46673;
 
3641
drop table t1;
 
3642
 
 
3643
 
 
3644
--echo #
 
3645
--echo # Bug#48210 FLUSH TABLES WITH READ LOCK deadlocks 
 
3646
--echo #           against concurrent CREATE PROCEDURE
 
3647
--echo #
 
3648
 
 
3649
connect (con2, localhost, root);
 
3650
 
 
3651
--echo # Test 1: CREATE PROCEDURE
 
3652
 
 
3653
--echo # Connection 1
 
3654
connection default;
 
3655
--echo # Start CREATE PROCEDURE and open mysql.proc
 
3656
SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL table_opened WAIT_FOR grlwait';
 
3657
--send CREATE PROCEDURE p1() SELECT 1
 
3658
 
 
3659
--echo # Connection 2
 
3660
connection con2;
 
3661
SET DEBUG_SYNC= 'now WAIT_FOR table_opened';
 
3662
--echo # Check that FLUSH must wait to get the GRL
 
3663
--echo # and let CREATE PROCEDURE continue
 
3664
SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL grlwait';
 
3665
--send FLUSH TABLES WITH READ LOCK
 
3666
 
 
3667
--echo # Connection 1
 
3668
connection default;
 
3669
--reap
 
3670
 
 
3671
--echo # Connection 2
 
3672
connection con2;
 
3673
--reap
 
3674
UNLOCK TABLES;
 
3675
 
 
3676
--echo # Connection 1
 
3677
connection default;
 
3678
SET DEBUG_SYNC= 'RESET';
 
3679
 
 
3680
--echo # Test 2: DROP PROCEDURE
 
3681
 
 
3682
connection default;
 
3683
--echo # Start DROP PROCEDURE and open tables
 
3684
SET DEBUG_SYNC= 'after_open_table_mdl_shared SIGNAL table_opened WAIT_FOR grlwait';
 
3685
--send DROP PROCEDURE p1
 
3686
 
 
3687
--echo # Connection 2
 
3688
connection con2;
 
3689
SET DEBUG_SYNC= 'now WAIT_FOR table_opened';
 
3690
--echo # Check that FLUSH must wait to get the GRL
 
3691
--echo # and let DROP PROCEDURE continue
 
3692
SET DEBUG_SYNC= 'mdl_acquire_lock_wait SIGNAL grlwait';
 
3693
--send FLUSH TABLES WITH READ LOCK
 
3694
 
 
3695
--echo # Connection 1
 
3696
connection default;
 
3697
--echo # Once FLUSH TABLES WITH READ LOCK starts waiting
 
3698
--echo # DROP PROCEDURE will be waked up and will drop
 
3699
--echo # procedure. Global read lock will be granted after
 
3700
--echo # this statement ends.
 
3701
--echo #
 
3702
--echo # Reaping DROP PROCEDURE.
 
3703
--reap
 
3704
 
 
3705
--echo # Connection 2
 
3706
connection con2;
 
3707
--echo # Reaping FTWRL.
 
3708
--reap
 
3709
UNLOCK TABLES;
 
3710
 
 
3711
--echo # Connection 1
 
3712
connection default;
 
3713
SET DEBUG_SYNC= 'RESET';
 
3714
 
 
3715
disconnect con2;
 
3716
 
 
3717
 
 
3718
--echo #
 
3719
--echo # Bug#50786 Assertion `thd->mdl_context.trans_sentinel() == __null' 
 
3720
--echo #           failed in open_ltable()
 
3721
--echo #
 
3722
 
 
3723
--echo # Supress warnings written to the log file
 
3724
call mtr.add_suppression("Wait on a lock was aborted due to a pending exclusive lock");
 
3725
--disable_warnings
 
3726
DROP TABLE IF EXISTS t1, t2;
 
3727
--enable_warnings
 
3728
 
 
3729
connect (con1,localhost,root);
 
3730
connect (con2,localhost,root);
 
3731
connect (con3,localhost,root);
 
3732
connection default;
 
3733
 
 
3734
CREATE TABLE t1 (i INT);
 
3735
CREATE TABLE t2 (i INT);
 
3736
 
 
3737
SET @old_general_log= @@global.general_log;
 
3738
SET @@global.general_log= 1;
 
3739
 
 
3740
SET @old_log_output= @@global.log_output;
 
3741
SET @@global.log_output= 'TABLE';
 
3742
 
 
3743
SET @old_sql_log_off= @@session.sql_log_off;
 
3744
SET @@session.sql_log_off= 1;
 
3745
 
 
3746
--echo # connection: con1
 
3747
connection con1;
 
3748
HANDLER t1 OPEN;
 
3749
 
 
3750
--echo # connection: con3
 
3751
connection con3;
 
3752
SET @@session.sql_log_off= 1;
 
3753
 
 
3754
--echo # connection: con2
 
3755
connection con2;
 
3756
SET DEBUG_SYNC= 'thr_multi_lock_after_thr_lock SIGNAL parked WAIT_FOR go';
 
3757
 
 
3758
# The below statement will block on the debug sync point
 
3759
# after it gets write lock on mysql.general_log table.
 
3760
--echo # Sending:
 
3761
--send SELECT 1
 
3762
 
 
3763
--echo # connection: con3
 
3764
connection con3;
 
3765
SET DEBUG_SYNC= 'now WAIT_FOR parked';
 
3766
 
 
3767
--echo # connection: con1
 
3768
connection con1;
 
3769
# This statement will block in open_ltable() when
 
3770
# trying to write into mysql.general_log.
 
3771
--echo # Sending:
 
3772
--send SELECT 1
 
3773
 
 
3774
--echo # connection: con3
 
3775
connection con3;
 
3776
let $wait_condition=
 
3777
  SELECT COUNT(*) = 1 FROM information_schema.processlist
 
3778
  WHERE state = "Waiting for table level lock" and info = "SELECT 1";
 
3779
--source include/wait_condition.inc
 
3780
# The ALTER below will try to abort the statement in connection con1,
 
3781
# since the latter waits on a table-level lock while having a HANDLER
 
3782
# open. This will cause mysql_lock_tables() in con1 fail which before
 
3783
# triggered the assert.
 
3784
ALTER TABLE t1 ADD COLUMN j INT;
 
3785
 
 
3786
--echo # connection: default
 
3787
connection default;
 
3788
SET DEBUG_SYNC= 'now SIGNAL go';
 
3789
 
 
3790
--echo # connection: con1
 
3791
connection con1;
 
3792
--echo # Reaping SELECT 1
 
3793
--reap
 
3794
HANDLER t1 CLOSE;
 
3795
 
 
3796
--echo # connection: con2
 
3797
connection con2;
 
3798
--echo # Reaping SELECT 1
 
3799
--reap
 
3800
 
 
3801
--echo # connection: default
 
3802
connection default;
 
3803
DROP TABLE t1, t2;
 
3804
SET DEBUG_SYNC= 'RESET';
 
3805
disconnect con1;
 
3806
disconnect con2;
 
3807
disconnect con3;
 
3808
SET @@global.general_log= @old_general_log;
 
3809
SET @@global.log_output= @old_log_output;
 
3810
SET @@session.sql_log_off= @old_sql_log_off;
 
3811
 
 
3812
 
 
3813
--echo #
 
3814
--echo # Additional coverage for bug #50913 "Deadlock between
 
3815
--echo # open_and_lock_tables_derived and MDL". The main test
 
3816
--echo # case is in lock_multi.test
 
3817
--echo #
 
3818
--disable_warnings
 
3819
drop table if exists t1;
 
3820
--enable_warnings
 
3821
set debug_sync= 'RESET';
 
3822
connect (con50913_1,localhost,root);
 
3823
connect (con50913_2,localhost,root);
 
3824
connection default;
 
3825
create table t1 (i int) engine=InnoDB;
 
3826
 
 
3827
--echo # Switching to connection 'con50913_1'.
 
3828
connection con50913_1;
 
3829
set debug_sync= 'thr_multi_lock_after_thr_lock SIGNAL parked WAIT_FOR go';
 
3830
--echo # Sending:
 
3831
--send alter table t1 add column j int
 
3832
 
 
3833
--echo # Switching to connection 'default'.
 
3834
connection default;
 
3835
--echo # Wait until ALTER TABLE gets blocked on a sync point after
 
3836
--echo # acquiring thr_lock.c lock.
 
3837
set debug_sync= 'now WAIT_FOR parked';
 
3838
--echo # The below statement should wait on MDL lock and not deadlock on
 
3839
--echo # thr_lock.c lock.
 
3840
--echo # Sending:
 
3841
--send truncate table t1
 
3842
 
 
3843
--echo # Switching to connection 'con50913_2'.
 
3844
connection con50913_2;
 
3845
--echo # Wait until TRUNCATE TABLE is blocked on MDL lock.
 
3846
let $wait_condition=
 
3847
  select count(*) = 1 from information_schema.processlist
 
3848
  where state = "Waiting for table metadata lock" and
 
3849
        info = "truncate table t1";
 
3850
--source include/wait_condition.inc
 
3851
--echo # Unblock ALTER TABLE.
 
3852
set debug_sync= 'now SIGNAL go';
 
3853
 
 
3854
--echo # Switching to connection 'con50913_1'.
 
3855
connection con50913_1;
 
3856
--echo # Reaping ALTER TABLE.
 
3857
--reap
 
3858
 
 
3859
--echo # Switching to connection 'default'.
 
3860
connection default;
 
3861
--echo # Reaping TRUNCATE TABLE.
 
3862
--reap
 
3863
disconnect con50913_1;
 
3864
disconnect con50913_2;
 
3865
set debug_sync= 'RESET';
 
3866
drop table t1;
 
3867
 
 
3868
 
 
3869
--echo #
 
3870
--echo # Test for bug #50998 "Deadlock in MDL code during test
 
3871
--echo #                      rqg_mdl_stability".
 
3872
--echo # Also provides coverage for the case when addition of
 
3873
--echo # waiting statement adds several loops in the waiters
 
3874
--echo # graph and therefore several searches for deadlock
 
3875
--echo # should be performed.
 
3876
--disable_warnings
 
3877
drop table if exists t1;
 
3878
--enable_warnings
 
3879
set debug_sync= 'RESET';
 
3880
connect (con1,localhost,root);
 
3881
connect (con2,localhost,root);
 
3882
connect (con3,localhost,root);
 
3883
connection default;
 
3884
create table t1 (i int);
 
3885
 
 
3886
--echo # Switching to connection 'con1'.
 
3887
connection con1;
 
3888
begin;
 
3889
select * from t1;
 
3890
 
 
3891
--echo # Switching to connection 'con2'.
 
3892
connection con2;
 
3893
begin;
 
3894
select * from t1;
 
3895
 
 
3896
--echo # Switching to connection 'default'.
 
3897
connection default;
 
3898
--echo # Start ALTER TABLE which will acquire SNW lock and
 
3899
--echo # table lock and get blocked on sync point.
 
3900
set debug_sync= 'thr_multi_lock_after_thr_lock SIGNAL parked WAIT_FOR go';
 
3901
--echo # Sending:
 
3902
--send alter table t1 add column j int
 
3903
 
 
3904
--echo # Switching to connection 'con1'.
 
3905
connection con1;
 
3906
--echo # Wait until ALTER TABLE gets blocked on a sync point.
 
3907
set debug_sync= 'now WAIT_FOR parked';
 
3908
--echo # Sending:
 
3909
--send insert into t1 values (1)
 
3910
 
 
3911
--echo # Switching to connection 'con2'.
 
3912
connection con2;
 
3913
--echo # Sending:
 
3914
--send insert into t1 values (1)
 
3915
 
 
3916
--echo # Switching to connection 'con3'.
 
3917
connection con3;
 
3918
--echo # Wait until both 'con1' and 'con2' are blocked trying to acquire
 
3919
--echo # SW lock on the table.
 
3920
let $wait_condition=
 
3921
  select count(*) = 2 from information_schema.processlist
 
3922
  where state = "Waiting for table metadata lock" and
 
3923
        info = "insert into t1 values (1)";
 
3924
--source include/wait_condition.inc
 
3925
--echo # Unblock ALTER TABLE. Since it will try to upgrade SNW to X lock
 
3926
--echo # deadlock with two loops in waiting graph will occur. Both loops
 
3927
--echo # should be found and DML statements in both 'con1' and 'con2'
 
3928
--echo # should be aborted with ER_LOCK_DEADLOCK errors.
 
3929
set debug_sync= 'now SIGNAL go';
 
3930
 
 
3931
--echo # Switching to connection 'con1'.
 
3932
connection con1;
 
3933
--echo # Reaping INSERT. It should end with ER_LOCK_DEADLOCK error and
 
3934
--echo # not wait indefinitely (as it happened before the bugfix).
 
3935
--error ER_LOCK_DEADLOCK
 
3936
--reap
 
3937
commit;
 
3938
 
 
3939
--echo # Switching to connection 'con2'.
 
3940
connection con2;
 
3941
--echo # Reaping INSERT.
 
3942
--error ER_LOCK_DEADLOCK
 
3943
--reap
 
3944
commit;
 
3945
 
 
3946
--echo # Switching to connection 'default'.
 
3947
connection default;
 
3948
--echo # Reap ALTER TABLE.
 
3949
--reap
 
3950
 
 
3951
disconnect con1;
 
3952
disconnect con2;
 
3953
disconnect con3;
 
3954
connection default;
 
3955
set debug_sync= 'RESET';
 
3956
drop table t1;
 
3957
 
 
3958
--echo #
 
3959
--echo # Bug#42643: InnoDB does not support replication of TRUNCATE TABLE
 
3960
--echo #
 
3961
--echo # Ensure that a acquired lock is not given up due to a conflict.
 
3962
--echo #
 
3963
 
 
3964
connect (con1,localhost,root,,test,,);
 
3965
connect (con2,localhost,root,,test,,);
 
3966
connect (con3,localhost,root,,test,,);
 
3967
 
 
3968
connection default;
 
3969
 
 
3970
--disable_warnings
 
3971
DROP TABLE IF EXISTS t1;
 
3972
--enable_warnings
 
3973
 
 
3974
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
 
3975
INSERT INTO t1 VALUES (1),(2),(3);
 
3976
 
 
3977
--echo # Connection: con1
 
3978
connection con1;
 
3979
LOCK TABLES t1 WRITE;
 
3980
SET debug_sync='upgrade_lock_for_truncate SIGNAL parked_truncate WAIT_FOR go_truncate';
 
3981
send TRUNCATE TABLE t1;
 
3982
 
 
3983
connection default;
 
3984
--echo # Connection: default
 
3985
SET debug_sync='now WAIT_FOR parked_truncate';
 
3986
 
 
3987
connection con2;
 
3988
--echo # Connection: con2
 
3989
SET debug_sync='after_open_table_ignore_flush SIGNAL parked_show WAIT_FOR go_show';
 
3990
send SHOW FIELDS FROM t1;
 
3991
 
 
3992
connection default;
 
3993
--echo # Connection: default
 
3994
SET debug_sync='now WAIT_FOR parked_show';
 
3995
 
 
3996
connection con3;
 
3997
--echo # Connection: con3
 
3998
SET debug_sync='after_flush_unlock SIGNAL parked_flush WAIT_FOR go_flush';
 
3999
send FLUSH TABLES t1;
 
4000
 
 
4001
connection default;
 
4002
--echo # Connection: default
 
4003
SET debug_sync='now WAIT_FOR parked_flush';
 
4004
SET debug_sync='now SIGNAL go_truncate';
 
4005
--echo # Ensure that truncate waits for a exclusive lock
 
4006
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4007
  WHERE state='Waiting for table metadata lock' AND info='TRUNCATE TABLE t1';
 
4008
--source include/wait_condition.inc
 
4009
SET debug_sync= 'now SIGNAL go_show';
 
4010
 
 
4011
connection con1;
 
4012
--echo # Connection: con1 (TRUNCATE)
 
4013
--echo # Reaping...
 
4014
reap;
 
4015
UNLOCK TABLES;
 
4016
 
 
4017
connection con2;
 
4018
--echo # Connection: con2 (SHOW FIELDS FROM t1)
 
4019
--echo # Reaping...
 
4020
reap;
 
4021
 
 
4022
connection default;
 
4023
--echo # Connection: default
 
4024
SET debug_sync= 'now SIGNAL go_flush';
 
4025
 
 
4026
connection con3;
 
4027
--echo # Connection: con3 (FLUSH TABLES t1)
 
4028
--echo # Reaping...
 
4029
reap;
 
4030
 
 
4031
disconnect con1;
 
4032
disconnect con2;
 
4033
disconnect con3;
 
4034
 
 
4035
connection default;
 
4036
--echo # Connection: default
 
4037
SET debug_sync= 'RESET';
 
4038
DROP TABLE t1;
 
4039
 
 
4040
 
 
4041
--echo #
 
4042
--echo # Bug#52856 concurrent show columns or show full columns causes a crash!!!
 
4043
--echo #
 
4044
CREATE TABLE t1(a CHAR(255));
 
4045
 
 
4046
connect(con1, localhost, root);
 
4047
SET DEBUG_SYNC= "get_schema_column SIGNAL waiting WAIT_FOR completed";
 
4048
--send SHOW FULL COLUMNS FROM t1
 
4049
 
 
4050
connection default;
 
4051
SET DEBUG_SYNC= "now WAIT_FOR waiting";
 
4052
--replace_column 8 #
 
4053
SHOW FULL COLUMNS FROM t1;
 
4054
SET DEBUG_SYNC= "now SIGNAL completed";
 
4055
--replace_column 8 #
 
4056
connection con1;
 
4057
--reap
 
4058
connection default;
 
4059
DROP TABLE t1;
 
4060
disconnect con1;
 
4061
 
 
4062
 
 
4063
--echo #
 
4064
--echo # Tests for schema-scope locks
 
4065
--echo #
 
4066
 
 
4067
--disable_warnings
 
4068
DROP DATABASE IF EXISTS db1;
 
4069
DROP DATABASE IF EXISTS db2;
 
4070
--enable_warnings
 
4071
 
 
4072
connect (con2, localhost, root);
 
4073
connect (con3, localhost, root);
 
4074
 
 
4075
--echo # Test 1: 
 
4076
--echo # CREATE DATABASE blocks database DDL on the same database, but
 
4077
--echo # not database DDL on different databases. Tests X vs X lock.
 
4078
--echo #
 
4079
 
 
4080
--echo # Connection default
 
4081
connection default;
 
4082
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4083
--echo # Sending:
 
4084
--send CREATE DATABASE db1
 
4085
 
 
4086
--echo # Connection con2
 
4087
connection con2;
 
4088
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4089
--echo # Sending:
 
4090
# This should block.
 
4091
--send CREATE DATABASE db1
 
4092
 
 
4093
--echo # Connection con3
 
4094
connection con3;
 
4095
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4096
  WHERE state='Waiting for schema metadata lock' AND info='CREATE DATABASE db1';
 
4097
--source include/wait_condition.inc
 
4098
# This should not block.
 
4099
CREATE DATABASE db2;
 
4100
ALTER DATABASE db2 DEFAULT CHARACTER SET utf8;
 
4101
DROP DATABASE db2;
 
4102
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4103
 
 
4104
--echo # Connection default
 
4105
connection default;
 
4106
--echo # Reaping: CREATE DATABASE db1
 
4107
--reap
 
4108
 
 
4109
--echo # Connection con2
 
4110
connection con2;
 
4111
--echo # Reaping: CREATE DATABASE db1
 
4112
--error ER_DB_CREATE_EXISTS
 
4113
--reap
 
4114
 
 
4115
--echo # Test 2:
 
4116
--echo # ALTER DATABASE blocks database DDL on the same database, but
 
4117
--echo # not database DDL on different databases. Tests X vs X lock.
 
4118
--echo #
 
4119
 
 
4120
--echo # Connection default
 
4121
connection default;
 
4122
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4123
--echo # Sending:
 
4124
--send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4125
 
 
4126
--echo # Connection con2
 
4127
connection con2;
 
4128
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4129
--echo # Sending:
 
4130
# This should block.
 
4131
--send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4132
 
 
4133
--echo # Connection con3
 
4134
connection con3;
 
4135
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4136
  WHERE state='Waiting for schema metadata lock'
 
4137
  AND info='ALTER DATABASE db1 DEFAULT CHARACTER SET utf8';
 
4138
--source include/wait_condition.inc
 
4139
# This should not block.
 
4140
CREATE DATABASE db2;
 
4141
ALTER DATABASE db2 DEFAULT CHARACTER SET utf8;
 
4142
DROP DATABASE db2;
 
4143
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4144
 
 
4145
--echo # Connection default
 
4146
connection default;
 
4147
--echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4148
--reap
 
4149
 
 
4150
--echo # Connection con2
 
4151
connection con2;
 
4152
--echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4153
--reap
 
4154
 
 
4155
--echo # Connection default
 
4156
connection default;
 
4157
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4158
--echo # Sending:
 
4159
--send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4160
 
 
4161
--echo # Connection con2
 
4162
connection con2;
 
4163
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4164
--echo # Sending:
 
4165
# This should also block.
 
4166
--send DROP DATABASE db1
 
4167
 
 
4168
--echo # Connection con3
 
4169
connection con3;
 
4170
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4171
  WHERE state='Waiting for schema metadata lock' AND info='DROP DATABASE db1';
 
4172
--source include/wait_condition.inc
 
4173
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4174
 
 
4175
--echo # Connection default
 
4176
connection default;
 
4177
--echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4178
--reap
 
4179
 
 
4180
--echo # Connection con2
 
4181
connection con2;
 
4182
--echo # Reaping: DROP DATABASE db1
 
4183
--reap
 
4184
# Recreate the database
 
4185
CREATE DATABASE db1;
 
4186
 
 
4187
--echo # Test 3:
 
4188
--echo # Two ALTER..UPGRADE of the same database are mutually exclusive, but
 
4189
--echo # two ALTER..UPGRADE of different databases are not. Tests X vs X lock.
 
4190
--echo #
 
4191
 
 
4192
let $MYSQLD_DATADIR= `select @@datadir`;
 
4193
# Manually make a 5.0 database from the template
 
4194
--mkdir $MYSQLD_DATADIR/a-b-c
 
4195
--copy_file $MYSQLD_DATADIR/db1/db.opt $MYSQLD_DATADIR/a-b-c/db.opt
 
4196
--mkdir $MYSQLD_DATADIR/a-b-c-d
 
4197
--copy_file $MYSQLD_DATADIR/db1/db.opt $MYSQLD_DATADIR/a-b-c-d/db.opt
 
4198
 
 
4199
--echo # Connection default
 
4200
connection default;
 
4201
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4202
--echo # Sending:
 
4203
--send ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME
 
4204
 
 
4205
--echo # Connection con2
 
4206
connection con2;
 
4207
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4208
--echo # Sending:
 
4209
# This should block.
 
4210
--send ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME
 
4211
 
 
4212
--echo # Connection con3
 
4213
connection con3;
 
4214
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4215
  WHERE state='Waiting for schema metadata lock'
 
4216
  AND info='ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME';
 
4217
--source include/wait_condition.inc
 
4218
# This should not block.
 
4219
ALTER DATABASE `#mysql50#a-b-c-d` UPGRADE DATA DIRECTORY NAME;
 
4220
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4221
 
 
4222
--echo # Connection default
 
4223
connection default;
 
4224
--echo # Reaping: ALTER DATABASE '#mysql50#a-b-c' UPGRADE DATA DIRECTORY NAME
 
4225
--reap
 
4226
 
 
4227
--echo # Connection con2
 
4228
connection con2;
 
4229
--echo # Reaping: ALTER DATABASE '#mysql50#a-b-c' UPGRADE DATA DIRECTORY NAME
 
4230
--error ER_BAD_DB_ERROR
 
4231
--reap
 
4232
DROP DATABASE `a-b-c`;
 
4233
DROP DATABASE `a-b-c-d`;
 
4234
 
 
4235
--echo # Test 4:
 
4236
--echo # DROP DATABASE blocks database DDL on the same database, but
 
4237
--echo # not database DDL on different databases. Tests X vs X lock.
 
4238
--echo #
 
4239
 
 
4240
--echo # Connection default
 
4241
connection default;
 
4242
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4243
--echo # Sending:
 
4244
--send DROP DATABASE db1
 
4245
 
 
4246
--echo # Connection con2
 
4247
connection con2;
 
4248
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4249
--echo # Sending:
 
4250
# This should block.
 
4251
--send DROP DATABASE db1
 
4252
 
 
4253
--echo # Connection con3
 
4254
connection con3;
 
4255
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4256
  WHERE state='Waiting for schema metadata lock' AND info='DROP DATABASE db1';
 
4257
--source include/wait_condition.inc
 
4258
# This should not block.
 
4259
CREATE DATABASE db2;
 
4260
ALTER DATABASE db2 DEFAULT CHARACTER SET utf8;
 
4261
DROP DATABASE db2;
 
4262
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4263
 
 
4264
--echo # Connection default
 
4265
connection default;
 
4266
--echo # Reaping: DROP DATABASE db1
 
4267
--reap
 
4268
 
 
4269
--echo # Connection con2
 
4270
connection con2;
 
4271
--echo # Reaping: DROP DATABASE db1
 
4272
--error ER_DB_DROP_EXISTS
 
4273
--reap
 
4274
 
 
4275
--echo # Connection default
 
4276
connection default;
 
4277
CREATE DATABASE db1;
 
4278
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4279
--echo # Sending:
 
4280
--send DROP DATABASE db1
 
4281
 
 
4282
--echo # Connection con2
 
4283
connection con2;
 
4284
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4285
--echo # Sending:
 
4286
# This should also block.
 
4287
--send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4288
 
 
4289
--echo # Connection con3
 
4290
connection con3;
 
4291
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4292
  WHERE state='Waiting for schema metadata lock'
 
4293
  AND info='ALTER DATABASE db1 DEFAULT CHARACTER SET utf8';
 
4294
--source include/wait_condition.inc
 
4295
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4296
 
 
4297
--echo # Connection default
 
4298
connection default;
 
4299
--echo # Reaping: DROP DATABASE db1
 
4300
--reap
 
4301
 
 
4302
--echo # Connection con2
 
4303
connection con2;
 
4304
--echo # Reaping: ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4305
# Error 1 is from ALTER DATABASE when the database does not exist.
 
4306
# Listing the error twice to prevent result diffences based on filename.
 
4307
--error 1,1
 
4308
--reap
 
4309
 
 
4310
 
 
4311
--echo # Test 5:
 
4312
--echo # Locked database name prevents CREATE of tables in that database.
 
4313
--echo # Tests X vs IX lock.
 
4314
--echo #
 
4315
 
 
4316
--echo # Connection default
 
4317
connection default;
 
4318
CREATE DATABASE db1;
 
4319
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4320
--echo # Sending:
 
4321
--send DROP DATABASE db1
 
4322
 
 
4323
--echo # Connection con2
 
4324
connection con2;
 
4325
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4326
--echo # Sending:
 
4327
# This should block.
 
4328
--send CREATE TABLE db1.t1 (a INT)
 
4329
 
 
4330
--echo # Connection con3
 
4331
connection con3;
 
4332
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4333
  WHERE state='Waiting for schema metadata lock' AND
 
4334
        info='CREATE TABLE db1.t1 (a INT)';
 
4335
--source include/wait_condition.inc
 
4336
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4337
 
 
4338
--echo # Connection default
 
4339
connection default;
 
4340
--echo # Reaping: DROP DATABASE db1
 
4341
--reap
 
4342
 
 
4343
--echo # Connection con2
 
4344
connection con2;
 
4345
--echo # Reaping: CREATE TABLE db1.t1 (a INT)
 
4346
--error ER_BAD_DB_ERROR
 
4347
--reap
 
4348
 
 
4349
--echo # Test 6:
 
4350
--echo # Locked database name prevents RENAME of tables to/from that database.
 
4351
--echo # Tests X vs IX lock.
 
4352
--echo #
 
4353
 
 
4354
--echo # Connection default
 
4355
connection default;
 
4356
CREATE DATABASE db1;
 
4357
CREATE TABLE db1.t1 (a INT);
 
4358
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4359
--echo # Sending:
 
4360
--send DROP DATABASE db1
 
4361
 
 
4362
--echo # Connection con2
 
4363
connection con2;
 
4364
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4365
--echo # Sending:
 
4366
# This should block.
 
4367
--send RENAME TABLE db1.t1 TO test.t1
 
4368
 
 
4369
--echo # Connection con3
 
4370
connection con3;
 
4371
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4372
  WHERE state='Waiting for schema metadata lock' AND
 
4373
        info='RENAME TABLE db1.t1 TO test.t1';
 
4374
--source include/wait_condition.inc
 
4375
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4376
 
 
4377
--echo # Connection default
 
4378
connection default;
 
4379
--echo # Reaping: DROP DATABASE db1
 
4380
--reap
 
4381
 
 
4382
--echo # Connection con2
 
4383
connection con2;
 
4384
--echo # Reaping: RENAME TABLE db1.t1 TO test.t1
 
4385
--error ER_FILE_NOT_FOUND, ER_FILE_NOT_FOUND
 
4386
--reap
 
4387
 
 
4388
--echo # Connection default
 
4389
connection default;
 
4390
CREATE DATABASE db1;
 
4391
CREATE TABLE test.t2 (a INT);
 
4392
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4393
--echo # Sending:
 
4394
--send DROP DATABASE db1
 
4395
 
 
4396
--echo # Connection con2
 
4397
connection con2;
 
4398
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4399
--echo # Sending:
 
4400
# This should block.
 
4401
--send RENAME TABLE test.t2 TO db1.t2
 
4402
 
 
4403
--echo # Connection con3
 
4404
connection con3;
 
4405
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4406
  WHERE state='Waiting for schema metadata lock' AND
 
4407
        info='RENAME TABLE test.t2 TO db1.t2';
 
4408
--source include/wait_condition.inc
 
4409
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4410
 
 
4411
--echo # Connection default
 
4412
connection default;
 
4413
--echo # Reaping: DROP DATABASE db1
 
4414
--reap
 
4415
 
 
4416
--echo # Connection con2
 
4417
connection con2;
 
4418
--echo # Reaping: RENAME TABLE test.t2 TO db1.t2
 
4419
# Error 7 is from RENAME TABLE where the target database does not exist.
 
4420
# Listing the error twice to prevent result diffences based on filename.
 
4421
--error 7, 7
 
4422
--reap
 
4423
DROP TABLE test.t2;
 
4424
 
 
4425
 
 
4426
--echo # Test 7:
 
4427
--echo # Locked database name prevents DROP of tables in that database.
 
4428
--echo # Tests X vs IX lock.
 
4429
--echo #
 
4430
 
 
4431
--echo # Connection default
 
4432
connection default;
 
4433
CREATE DATABASE db1;
 
4434
CREATE TABLE db1.t1 (a INT);
 
4435
SET DEBUG_SYNC= 'after_wait_locked_schema_name SIGNAL locked WAIT_FOR blocked';
 
4436
--echo # Sending:
 
4437
--send DROP DATABASE db1
 
4438
 
 
4439
--echo # Connection con2
 
4440
connection con2;
 
4441
SET DEBUG_SYNC= 'now WAIT_FOR locked';
 
4442
--echo # Sending:
 
4443
# This should block.
 
4444
--send DROP TABLE db1.t1
 
4445
 
 
4446
--echo # Connection con3
 
4447
connection con3;
 
4448
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4449
  WHERE state='Waiting for schema metadata lock' AND info='DROP TABLE db1.t1';
 
4450
--source include/wait_condition.inc
 
4451
SET DEBUG_SYNC= 'now SIGNAL blocked';
 
4452
 
 
4453
--echo # Connection default
 
4454
connection default;
 
4455
--echo # Reaping: DROP DATABASE db1
 
4456
--reap
 
4457
 
 
4458
--echo # Connection con2
 
4459
connection con2;
 
4460
--echo # Reaping: DROP TABLE db1.t1
 
4461
--error ER_BAD_TABLE_ERROR
 
4462
--reap
 
4463
 
 
4464
--echo # Connection default
 
4465
connection default;
 
4466
disconnect con2;
 
4467
disconnect con3;
 
4468
SET DEBUG_SYNC= 'RESET';
 
4469
 
 
4470
--echo #
 
4471
--echo # End of tests for schema-scope locks
 
4472
--echo #
 
4473
 
 
4474
--echo #
 
4475
--echo # Tests of granted global S lock (FLUSH TABLE WITH READ LOCK)
 
4476
--echo #
 
4477
 
 
4478
CREATE DATABASE db1;
 
4479
CREATE TABLE db1.t1(a INT);
 
4480
connect(con2, localhost, root);
 
4481
connect(con3, localhost, root);
 
4482
 
 
4483
--echo # Connection default
 
4484
connection default;
 
4485
FLUSH TABLE WITH READ LOCK;
 
4486
 
 
4487
--echo # Connection con2
 
4488
connection con2;
 
4489
# IX global lock should block
 
4490
--send CREATE TABLE db1.t2(a INT)
 
4491
 
 
4492
--echo # Connection default
 
4493
connection default;
 
4494
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4495
  WHERE state='Waiting for global read lock'
 
4496
  AND info='CREATE TABLE db1.t2(a INT)';
 
4497
--source include/wait_condition.inc
 
4498
UNLOCK TABLES;
 
4499
 
 
4500
--echo # Connection con2
 
4501
connection con2;
 
4502
--echo # Reaping CREATE TABLE db1.t2(a INT)
 
4503
--reap
 
4504
 
 
4505
--echo # Connection default
 
4506
connection default;
 
4507
FLUSH TABLE WITH READ LOCK;
 
4508
 
 
4509
--echo # Connection con2
 
4510
connection con2;
 
4511
# X global lock should block
 
4512
--send ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4513
 
 
4514
--echo # Connection default
 
4515
connection default;
 
4516
let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist
 
4517
  WHERE state='Waiting for global read lock'
 
4518
  AND info='ALTER DATABASE db1 DEFAULT CHARACTER SET utf8';
 
4519
--source include/wait_condition.inc
 
4520
UNLOCK TABLES;
 
4521
 
 
4522
--echo # Connection con2
 
4523
connection con2;
 
4524
--echo # Reaping ALTER DATABASE db1 DEFAULT CHARACTER SET utf8
 
4525
--reap
 
4526
 
 
4527
--echo # Connection default
 
4528
connection default;
 
4529
FLUSH TABLE WITH READ LOCK;
 
4530
 
 
4531
--echo # Connection con2
 
4532
connection con2;
 
4533
# S global lock should not block
 
4534
FLUSH TABLE WITH READ LOCK;
 
4535
UNLOCK TABLES;
 
4536
 
 
4537
--echo # Connection default
 
4538
connection default;
 
4539
UNLOCK TABLES;
 
4540
DROP DATABASE db1;
 
4541
disconnect con2;
 
4542
disconnect con3;
 
4543
 
 
4544
 
 
4545
--echo #
 
4546
--echo # Bug#56292 Deadlock with ALTER TABLE and MERGE tables
 
4547
--echo #
 
4548
 
 
4549
--disable_warnings
 
4550
DROP TABLE IF EXISTS t1, t2, m1;
 
4551
--enable_warnings
 
4552
 
 
4553
CREATE TABLE t1(a INT) engine=MyISAM;
 
4554
CREATE TABLE t2(a INT) engine=MyISAM;
 
4555
CREATE TABLE m1(a INT) engine=MERGE UNION=(t1, t2);
 
4556
 
 
4557
INSERT INTO t1 VALUES (1), (2);
 
4558
INSERT INTO t2 VALUES (3), (4);
 
4559
 
 
4560
connect(con1, localhost, root);
 
4561
connect(con2, localhost, root);
 
4562
 
 
4563
--echo # Connection con1
 
4564
connection con1;
 
4565
SET DEBUG_SYNC= 'mdl_upgrade_shared_lock_to_exclusive SIGNAL upgrade WAIT_FOR continue';
 
4566
--echo # Sending:
 
4567
--send ALTER TABLE m1 engine=MERGE UNION=(t2, t1)
 
4568
 
 
4569
--echo # Connection con2
 
4570
connection con2;
 
4571
--echo # Waiting for ALTER TABLE to try lock upgrade
 
4572
SET DEBUG_SYNC= 'now WAIT_FOR upgrade';
 
4573
--echo # Sending:
 
4574
--send DELETE FROM t2 WHERE a = 3
 
4575
 
 
4576
--echo # Connection default
 
4577
connection default;
 
4578
--echo # Check that DELETE is waiting on a metadata lock and not a table lock.
 
4579
let $wait_condition=
 
4580
  SELECT COUNT(*) = 1 FROM information_schema.processlist
 
4581
  WHERE state = "Waiting for table metadata lock" AND
 
4582
        info = "DELETE FROM t2 WHERE a = 3";
 
4583
--source include/wait_condition.inc
 
4584
--echo # Now that DELETE blocks on a metadata lock, we should be able to do
 
4585
--echo # SELECT * FROM m1 here. SELECT used to be blocked by a DELETE table
 
4586
--echo # lock request.
 
4587
SELECT * FROM m1;
 
4588
--echo # Resuming ALTER TABLE
 
4589
SET DEBUG_SYNC= 'now SIGNAL continue';
 
4590
 
 
4591
--echo # Connection con1
 
4592
connection con1;
 
4593
--echo # Reaping: ALTER TABLE m1 engine=MERGE UNION=(t2, t1)
 
4594
--reap
 
4595
--echo # Connection con2
 
4596
connection con2;
 
4597
--echo # Reaping: DELETE FROM t2 WHERE a = 3
 
4598
--reap
 
4599
--echo # Connection default
 
4600
connection default;
 
4601
DROP TABLE m1, t1, t2;
 
4602
SET DEBUG_SYNC= 'RESET';
 
4603
disconnect con1;
 
4604
disconnect con2;
 
4605
 
 
4606
 
 
4607
# Check that all connections opened by test cases in this file are really
 
4608
# gone so execution of other tests won't be affected by their presence.
 
4609
--source include/wait_until_count_sessions.inc