mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Backport of:
------------------------------------------------------------ revno: 2476.784.3 committer: davi@moksha.local timestamp: Tue 2007-10-02 21:27:31 -0300 message: Bug#25858 Some DROP TABLE under LOCK TABLES can cause deadlocks When a client (connection) holds a lock on a table and attempts to drop (obtain a exclusive lock) on a second table that is already held by a second client and the second client then attempts to drop the table that is held by the first client, leads to a circular wait deadlock. This scenario is very similar to trying to drop (or rename) a table while holding read locks and are correctly forbidden. The solution is to allow a drop table operation to continue only if the table being dropped is write (exclusively) locked, or if the table is temporary, or if the client is not holding any locks. Using this scheme prevents the creation of a circular chain in which each client is waiting for one table that the next client in the chain is holding. This is incompatible change, as can be seen by number of tests cases that needed to be fixed, but is consistent with respect to behavior of the different scenarios in which the circular wait might happen. mysql-test/r/drop.result: Test case result for Bug#25858 mysql-test/r/group_by.result: Fix test case result wrt drop table under lock tables -- unlock tables before dropping table. mysql-test/r/insert_notembedded.result: Fix test case result wrt drop table under lock tables -- unlock tables before dropping table mysql-test/r/lock.result: Fix test case result wrt drop table under lock tables -- unlock tables before dropping table. mysql-test/r/lock_multi.result: Fix test case result wrt drop table under lock tables -- unlock tables before dropping table. mysql-test/r/myisam.result: Fix test case result wrt drop table under lock tables -- unlock tables before dropping table. mysql-test/r/view.result: Fix test case result wrt drop table under lock tables -- unlock tables before dropping table. mysql-test/t/drop.test: Add test case for Bug#25858 mysql-test/t/group_by.test: Fix test case: unlock tables in preparation for a drop table. In some circumstances, dropping tables while holding locks leads to a deadlock. mysql-test/t/insert_notembedded.test: Fix test case: unlock tables in preparation for a drop table. In some circumstances, dropping tables while holding locks leads to a deadlock. mysql-test/t/lock.test: Fix test case: unlock tables in preparation for a drop table. In some circumstances, dropping tables while holding locks leads to a deadlock. mysql-test/t/lock_multi.test: Fix test case: unlock tables in preparation for a drop table. In some circumstances, dropping tables while holding locks leads to a deadlock. mysql-test/t/myisam.test: Fix test case: unlock tables in preparation for a drop table. In some circumstances, dropping tables while holding locks leads to a deadlock. mysql-test/t/query_cache_notembedded.test: Fix test case: unlock tables in preparation for a drop table. In some circumstances, dropping tables while holding locks leads to a deadlock. mysql-test/t/view.test: Fix test case: unlock tables in preparation for a drop table. In some circumstances, dropping tables while holding locks leads to a deadlock. sql/lock.cc: When trying to obtain a name lock under lock tables, ensure that the table is properly exclusively locked and fail otherwise.
This commit is contained in:
@ -124,6 +124,39 @@ disconnect addconroot1;
|
||||
--source include/wait_until_disconnected.inc
|
||||
connection default;
|
||||
|
||||
#
|
||||
# Bug#25858 Some DROP TABLE under LOCK TABLES can cause deadlocks
|
||||
#
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t1,t2;
|
||||
--enable_warnings
|
||||
create table t1 (a int);
|
||||
create table t2 (a int);
|
||||
lock table t1 read;
|
||||
--error ER_TABLE_NOT_LOCKED
|
||||
drop table t2;
|
||||
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
|
||||
drop table t1;
|
||||
unlock tables;
|
||||
drop table t1,t2;
|
||||
connect (addconroot, localhost, root,,);
|
||||
connection default;
|
||||
create table t1 (i int);
|
||||
create table t2 (i int);
|
||||
lock tables t1 read;
|
||||
connection addconroot;
|
||||
lock tables t2 read;
|
||||
--error ER_TABLE_NOT_LOCKED
|
||||
drop table t1;
|
||||
connection default;
|
||||
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
|
||||
drop table t1,t2;
|
||||
disconnect addconroot;
|
||||
connection default;
|
||||
unlock tables;
|
||||
drop table t1,t2;
|
||||
|
||||
--echo End of 5.0 tests
|
||||
|
||||
#
|
||||
|
@ -120,8 +120,9 @@ SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2
|
||||
SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY NULL;
|
||||
SELECT HIGH_PRIORITY cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY surname, firstname;
|
||||
|
||||
drop table t1,t2;
|
||||
drop table t2;
|
||||
unlock tables;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Test of group by bug in bugzilla
|
||||
|
@ -185,5 +185,6 @@ select * from t1;
|
||||
connection default;
|
||||
disconnect update;
|
||||
disconnect select;
|
||||
unlock tables;
|
||||
drop table t1;
|
||||
set low_priority_updates=default;
|
||||
|
@ -58,6 +58,9 @@ insert into t1 select index1,nr from t1;
|
||||
unlock tables;
|
||||
lock tables t1 write, t1 as t1_alias read;
|
||||
insert into t1 select index1,nr from t1 as t1_alias;
|
||||
--error ER_TABLE_NOT_LOCKED
|
||||
drop table t1,t2;
|
||||
unlock tables;
|
||||
drop table t1,t2;
|
||||
|
||||
#
|
||||
@ -90,7 +93,10 @@ delete t1 from t1,t2 where t1.a=t2.a;
|
||||
delete from t2 using t1,t2 where t1.a=t2.a;
|
||||
--error 1099
|
||||
delete t2 from t1,t2 where t1.a=t2.a;
|
||||
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
|
||||
drop table t1,t2;
|
||||
unlock tables;
|
||||
drop table t2,t1;
|
||||
|
||||
--echo End of 4.1 tests.
|
||||
|
||||
|
@ -76,6 +76,7 @@ update t1,t2 set c=a where b=d;
|
||||
connection reader;
|
||||
select c from t2;
|
||||
connection locker;
|
||||
unlock tables;
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
|
||||
|
@ -503,6 +503,7 @@ insert into t2 values(2,0);
|
||||
disconnect root;
|
||||
connection default;
|
||||
select straight_join * from t1,t2 force index (primary) where t1.a=t2.a;
|
||||
unlock tables;
|
||||
drop table t1,t2;
|
||||
#
|
||||
# Full key.
|
||||
@ -520,6 +521,7 @@ disconnect con1;
|
||||
connection default;
|
||||
SELECT t1.c1 AS t1c1, t2.c1 AS t2c1 FROM t1, t2
|
||||
WHERE t1.c1 = t2.c1 HAVING t1c1 != t2c1;
|
||||
UNLOCK TABLES;
|
||||
DROP TABLE t1,t2;
|
||||
|
||||
# End of 4.0 tests
|
||||
|
@ -99,6 +99,7 @@ connection root2;
|
||||
SELECT * FROM t1;
|
||||
connection root;
|
||||
SELECT * FROM t1;
|
||||
UNLOCK TABLES;
|
||||
drop table t1;
|
||||
connection default;
|
||||
disconnect root;
|
||||
|
@ -1017,6 +1017,9 @@ select * from v1;
|
||||
-- error ER_TABLE_NOT_LOCKED
|
||||
select * from t2;
|
||||
drop view v1;
|
||||
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
|
||||
drop table t1, t2;
|
||||
unlock tables;
|
||||
drop table t1, t2;
|
||||
|
||||
#
|
||||
|
Reference in New Issue
Block a user