~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- source include/not_embedded.inc
 
2
--disable_warnings
 
3
drop table if exists t1,t2;
 
4
--enable_warnings
 
5
 
 
6
# Test to see if select will get the lock ahead of low priority update
 
7
 
 
8
connect (locker,localhost,root,,);
 
9
connect (reader,localhost,root,,);
 
10
connect (writer,localhost,root,,);
 
11
 
 
12
connection locker;
 
13
create table t1(n int);
 
14
insert into t1 values (1);
 
15
lock tables t1 write;
 
16
connection writer;
 
17
send update low_priority t1 set n = 4;
 
18
connection reader;
 
19
let $wait_condition=
 
20
  select count(*) = 1 from information_schema.processlist
 
21
  where state = "Table lock" and info = "update low_priority t1 set n = 4";
 
22
--source include/wait_condition.inc
 
23
send select n from t1;
 
24
connection locker;
 
25
let $wait_condition=
 
26
  select count(*) = 1 from information_schema.processlist
 
27
  where state = "Table lock" and info = "select n from t1";
 
28
--source include/wait_condition.inc
 
29
unlock tables;
 
30
connection writer;
 
31
reap;
 
32
connection reader;
 
33
reap;
 
34
drop table t1;
 
35
 
 
36
connection locker;
 
37
create table t1(n int);
 
38
insert into t1 values (1);
 
39
lock tables t1 read;
 
40
connection writer;
 
41
send update low_priority t1 set n = 4;
 
42
connection reader;
 
43
let $wait_condition=
 
44
  select count(*) = 1 from information_schema.processlist
 
45
  where state = "Table lock" and info = "update low_priority t1 set n = 4";
 
46
--source include/wait_condition.inc
 
47
select n from t1;
 
48
connection locker;
 
49
unlock tables;
 
50
connection writer;
 
51
reap;
 
52
drop table t1;
 
53
 
 
54
#
 
55
# Test problem when using locks with multi-updates
 
56
# It should not block when multi-update is reading on a read-locked table
 
57
#
 
58
 
 
59
connection locker;
 
60
create table t1 (a int, b int);
 
61
create table t2 (c int, d int);
 
62
insert into t1 values(1,1);
 
63
insert into t1 values(2,2);
 
64
insert into t2 values(1,2);
 
65
lock table t1 read;
 
66
connection writer;
 
67
update t1,t2 set c=a where b=d;
 
68
connection reader;
 
69
select c from t2;
 
70
connection locker;
 
71
unlock tables;
 
72
drop table t1;
 
73
drop table t2;
 
74
 
 
75
#
 
76
# Test problem when using locks on many tables and droping a table that
 
77
# is to-be-locked by another thread
 
78
#
 
79
#
 
80
connection locker;
 
81
create table t1 (a int);
 
82
create table t2 (a int);
 
83
lock table t1 write, t2 write;
 
84
connection reader;
 
85
send insert t1 select * from t2;
 
86
connection locker;
 
87
let $wait_condition=
 
88
  select count(*) = 1 from information_schema.processlist
 
89
  where state = "Table lock" and info = "insert t1 select * from t2";
 
90
--source include/wait_condition.inc
 
91
drop table t2;
 
92
connection reader;
 
93
--error 1146
 
94
reap;
 
95
connection locker;
 
96
drop table t1;
 
97
 
 
98
#
 
99
# Same test as above, but with the dropped table locked twice
 
100
#
 
101
 
 
102
connection locker;
 
103
create table t1 (a int);
 
104
create table t2 (a int);
 
105
lock table t1 write, t2 write, t1 as t1_2 write, t2 as t2_2 write;
 
106
connection reader;
 
107
send insert t1 select * from t2;
 
108
connection locker;
 
109
let $wait_condition=
 
110
  select count(*) = 1 from information_schema.processlist
 
111
  where state = "Table lock" and info = "insert t1 select * from t2";
 
112
--source include/wait_condition.inc
 
113
drop table t2;
 
114
connection reader;
 
115
--error 1146
 
116
reap;
 
117
connection locker;
 
118
drop table t1;
 
119
 
 
120
 
 
121
--echo End of 4.1 tests
 
122
 
 
123
#
 
124
# BUG#9998 - MySQL client hangs on USE "database"
 
125
#
 
126
create table t1(a int);
 
127
lock tables t1 write;
 
128
connection reader;
 
129
show columns from t1;
 
130
connection locker;
 
131
unlock tables;
 
132
drop table t1;
 
133
 
 
134
#
 
135
# Test if CREATE TABLE with LOCK TABLE deadlocks.
 
136
#
 
137
connection writer;
 
138
CREATE TABLE t1 (c1 int);
 
139
LOCK TABLE t1 WRITE;
 
140
#
 
141
# This waits until t1 is unlocked.
 
142
connection locker;
 
143
send FLUSH TABLES WITH READ LOCK;
 
144
#
 
145
connection writer;
 
146
let $wait_condition=
 
147
  select count(*) = 1 from information_schema.processlist
 
148
  where state = "Flushing tables" and info = "FLUSH TABLES WITH READ LOCK";
 
149
--source include/wait_condition.inc
 
150
# This must not block.
 
151
CREATE TABLE t2 (c1 int);
 
152
UNLOCK TABLES;
 
153
#
 
154
# This awakes now.
 
155
connection locker;
 
156
reap;
 
157
UNLOCK TABLES;
 
158
#
 
159
connection default;
 
160
DROP TABLE t1, t2;
 
161
#
 
162
# Test if CREATE TABLE SELECT with LOCK TABLE deadlocks.
 
163
#
 
164
connection writer;
 
165
CREATE TABLE t1 (c1 int);
 
166
LOCK TABLE t1 WRITE;
 
167
#
 
168
# This waits until t1 is unlocked.
 
169
connection locker;
 
170
send FLUSH TABLES WITH READ LOCK;
 
171
#
 
172
# This must not block.
 
173
connection writer;
 
174
let $wait_condition=
 
175
  select count(*) = 1 from information_schema.processlist
 
176
  where state = "Flushing tables" and info = "FLUSH TABLES WITH READ LOCK";
 
177
--source include/wait_condition.inc
 
178
--error 1100
 
179
CREATE TABLE t2 AS SELECT * FROM t1;
 
180
UNLOCK TABLES;
 
181
#
 
182
# This awakes now.
 
183
connection locker;
 
184
reap;
 
185
UNLOCK TABLES;
 
186
#
 
187
connection default;
 
188
DROP TABLE t1;
 
189
 
 
190
#
 
191
# Bug#19815 - CREATE/RENAME/DROP DATABASE can deadlock on a global read lock
 
192
#
 
193
connect (con1,localhost,root,,);
 
194
connect (con2,localhost,root,,);
 
195
#
 
196
connection con1;
 
197
CREATE DATABASE mysqltest_1;
 
198
FLUSH TABLES WITH READ LOCK;
 
199
#
 
200
# With bug in place: acquire LOCK_mysql_create_table and
 
201
# wait in wait_if_global_read_lock().
 
202
connection con2;
 
203
send DROP DATABASE mysqltest_1;
 
204
#
 
205
# With bug in place: try to acquire LOCK_mysql_create_table...
 
206
# When fixed: Reject dropping db because of the read lock.
 
207
connection con1;
 
208
let $wait_condition=
 
209
  select count(*) = 1 from information_schema.processlist
 
210
  where state = "Waiting for release of readlock"
 
211
  and info = "DROP DATABASE mysqltest_1";
 
212
--source include/wait_condition.inc
 
213
--error ER_CANT_UPDATE_WITH_READLOCK
 
214
DROP DATABASE mysqltest_1;
 
215
UNLOCK TABLES;
 
216
#
 
217
connection con2;
 
218
reap;
 
219
#
 
220
connection default;
 
221
disconnect con1;
 
222
disconnect con2;
 
223
# This must have been dropped by connection 2 already,
 
224
# which waited until the global read lock was released.
 
225
--error ER_DB_DROP_EXISTS
 
226
DROP DATABASE mysqltest_1;
 
227
 
 
228
#
 
229
# Bug #17264: MySQL Server freeze
 
230
#
 
231
connection locker;
 
232
# Disable warnings to allow test to run also without InnoDB
 
233
--disable_warnings
 
234
create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb;
 
235
--enable_warnings
 
236
lock tables t1 write;
 
237
connection writer;
 
238
send alter table t1 auto_increment=0;
 
239
connection reader;
 
240
let $wait_condition=
 
241
  select count(*) = 1 from information_schema.processlist
 
242
  where state = "Table lock" and info = "alter table t1 auto_increment=0";
 
243
--source include/wait_condition.inc
 
244
send alter table t1 auto_increment=0;
 
245
connection locker;
 
246
let $wait_condition=
 
247
  select count(*) = 2 from information_schema.processlist
 
248
  where state = "Table lock" and info = "alter table t1 auto_increment=0";
 
249
--source include/wait_condition.inc
 
250
unlock tables;
 
251
connection writer;
 
252
reap;
 
253
connection reader;
 
254
reap;
 
255
connection locker;
 
256
drop table t1;
 
257
#
 
258
--echo End of 5.0 tests
 
259
 
 
260
#
 
261
# Bug #21281 "Pending write lock is incorrectly removed when its
 
262
#             statement being KILLed"
 
263
#
 
264
create table t1 (i int);
 
265
connection locker;
 
266
lock table t1 read;
 
267
connection writer;
 
268
--send update t1 set i= 10;
 
269
connection reader;
 
270
let $wait_condition=
 
271
  select count(*) = 1 from information_schema.processlist
 
272
  where state = "Table lock" and info = "update t1 set i= 10";
 
273
--source include/wait_condition.inc
 
274
--send select * from t1;
 
275
connection default;
 
276
let $wait_condition=
 
277
  select count(*) = 1 from information_schema.processlist
 
278
  where state = "Table lock" and info = "select * from t1";
 
279
--source include/wait_condition.inc
 
280
let $ID= `select id from information_schema.processlist where state = "Table lock" and info = "update t1 set i= 10"`;
 
281
--replace_result $ID ID
 
282
eval kill query $ID;
 
283
connection reader;
 
284
--reap
 
285
connection writer;
 
286
--error ER_QUERY_INTERRUPTED 
 
287
--reap
 
288
connection locker;
 
289
unlock tables;
 
290
connection default;
 
291
drop table t1;
 
292
 
 
293
#
 
294
# Bug#25856 - HANDLER table OPEN in one connection lock DROP TABLE in another one
 
295
#
 
296
--disable_warnings
 
297
drop table if exists t1;
 
298
--enable_warnings
 
299
create table t1 (a int) ENGINE=MEMORY;
 
300
--echo --> client 2
 
301
connection locker;
 
302
--error 1031
 
303
handler t1 open;
 
304
--echo --> client 1
 
305
connection default;
 
306
drop table t1;
 
307
 
 
308
#
 
309
# Bug#32395 Alter table under a impending global read lock causes a server crash
 
310
#
 
311
 
 
312
#
 
313
# Test ALTER TABLE under LOCK TABLES and FLUSH TABLES WITH READ LOCK
 
314
#
 
315
 
 
316
--disable_warnings
 
317
drop table if exists t1;
 
318
--enable_warnings
 
319
create table t1 (i int);
 
320
connect (flush,localhost,root,,test,,);
 
321
connection default;
 
322
--echo connection: default
 
323
lock tables t1 write;
 
324
connection flush;
 
325
--echo connection: flush
 
326
--send flush tables with read lock;
 
327
connection default;
 
328
--echo connection: default
 
329
let $wait_condition=
 
330
  select count(*) = 1 from information_schema.processlist
 
331
  where state = "Flushing tables";
 
332
--source include/wait_condition.inc
 
333
alter table t1 add column j int;
 
334
connect (insert,localhost,root,,test,,);
 
335
connection insert;
 
336
--echo connection: insert
 
337
let $wait_condition=
 
338
  select count(*) = 1 from information_schema.processlist
 
339
  where state = "Flushing tables";
 
340
--source include/wait_condition.inc
 
341
--send insert into t1 values (1,2);
 
342
--echo connection: default
 
343
connection default;
 
344
let $wait_condition=
 
345
  select count(*) = 1 from information_schema.processlist
 
346
  where state = "Waiting for release of readlock";
 
347
--source include/wait_condition.inc
 
348
unlock tables;
 
349
connection flush;
 
350
--echo connection: flush
 
351
--reap
 
352
let $wait_condition=
 
353
  select count(*) = 1 from information_schema.processlist
 
354
  where state = "Waiting for release of readlock";
 
355
--source include/wait_condition.inc
 
356
select * from t1;
 
357
unlock tables;
 
358
connection insert;
 
359
--reap
 
360
connection default;
 
361
let $wait_condition=
 
362
  select count(*) = 1 from t1;
 
363
--source include/wait_condition.inc
 
364
select * from t1;
 
365
drop table t1;
 
366
disconnect flush;
 
367
disconnect insert;
 
368
 
 
369
#
 
370
# Test that FLUSH TABLES under LOCK TABLES protects write locked tables
 
371
# from a impending FLUSH TABLES WITH READ LOCK
 
372
#
 
373
 
 
374
--disable_warnings
 
375
drop table if exists t1;
 
376
--enable_warnings
 
377
create table t1 (i int);
 
378
connect (flush,localhost,root,,test,,);
 
379
connection default;
 
380
--echo connection: default
 
381
lock tables t1 write;
 
382
connection flush;
 
383
--echo connection: flush
 
384
--send flush tables with read lock;
 
385
connection default;
 
386
--echo connection: default
 
387
let $wait_condition=
 
388
  select count(*) = 1 from information_schema.processlist
 
389
  where state = "Flushing tables";
 
390
--source include/wait_condition.inc
 
391
flush tables;
 
392
let $wait_condition=
 
393
  select count(*) = 1 from information_schema.processlist
 
394
  where state = "Flushing tables";
 
395
--source include/wait_condition.inc
 
396
unlock tables;
 
397
let $wait_condition=
 
398
  select count(*) = 0 from information_schema.processlist
 
399
  where state = "Flushing tables";
 
400
--source include/wait_condition.inc
 
401
connection flush;
 
402
--reap
 
403
connection default;
 
404
disconnect flush;
 
405
drop table t1;
 
406
 
 
407
#
 
408
# Bug#30331: Table_locks_waited shows inaccurate values
 
409
#
 
410
 
 
411
--disable_warnings
 
412
drop table if exists t1,t2;
 
413
--enable_warnings
 
414
create table t1 (a int);
 
415
flush status;
 
416
lock tables t1 read;
 
417
let $tlwa= `show status like 'Table_locks_waited'`;
 
418
connect (waiter,localhost,root,,);
 
419
connection waiter;
 
420
send insert into t1 values(1);
 
421
connection default;
 
422
let $wait_condition=
 
423
  select count(*) = 1 from information_schema.processlist
 
424
  where state = "Table lock" and info = "insert into t1 values(1)";
 
425
--source include/wait_condition.inc
 
426
let $tlwb= `show status like 'Table_locks_waited'`;
 
427
unlock tables;
 
428
drop table t1;
 
429
disconnect waiter;
 
430
connection default;
 
431
--disable_query_log
 
432
eval SET @tlwa= SUBSTRING_INDEX('$tlwa', '      ', -1);
 
433
eval SET @tlwb= SUBSTRING_INDEX('$tlwb', '      ', -1);
 
434
--enable_query_log
 
435
select @tlwa < @tlwb;
 
436
 
 
437
--echo End of 5.1 tests
 
438
 
 
439
#
 
440
# Test that DROP TABLES does not wait for a impending FLUSH TABLES
 
441
# WITH READ LOCK
 
442
#
 
443
 
 
444
--disable_warnings
 
445
drop table if exists t1;
 
446
--enable_warnings
 
447
create table t1 (i int);
 
448
connect (flush,localhost,root,,test,,);
 
449
connection default;
 
450
--echo connection: default
 
451
lock tables t1 write;
 
452
connection flush;
 
453
--echo connection: flush
 
454
--send flush tables with read lock;
 
455
connection default;
 
456
--echo connection: default
 
457
let $wait_condition=
 
458
  select count(*) = 1 from information_schema.processlist
 
459
  where state = "Flushing tables";
 
460
--source include/wait_condition.inc
 
461
flush tables;
 
462
let $wait_condition=
 
463
  select count(*) = 1 from information_schema.processlist
 
464
  where state = "Flushing tables";
 
465
--source include/wait_condition.inc
 
466
drop table t1;
 
467
let $wait_condition=
 
468
  select count(*) = 0 from information_schema.processlist
 
469
  where state = "Flushing tables";
 
470
--source include/wait_condition.inc
 
471
connection flush;
 
472
--reap
 
473
connection default;
 
474
disconnect flush;