mariadb/mysql-test/t/drop.test
Jon Olav Hauglid c7bcb28f0c Bug #49988 MDL deadlocks with mysql_create_db, reload_acl_and_cache
This was a deadlock between LOCK TABLES/CREATE DATABASE in one connection
and DROP DATABASE in another. It only happened if the table locked by 
LOCK TABLES was in the database to be dropped. The deadlock is similar
to the one in Bug#48940, but with LOCK TABLES instead of an active
transaction.

The order of events needed to trigger the deadlock was:
1) Connection 1 locks table db1.t1 using LOCK TABLES. It will now
have a metadata lock on the table name.
2) Connection 2 issues DROP DATABASE db1. This will wait inside
the MDL subsystem for the lock on db1.t1 to go away. While waiting, it
will hold the LOCK_mysql_create_db mutex.
3) Connection 1 issues CREATE DATABASE (database name irrelevant).
This will hang trying to lock the same mutex. Since this is the connection
holding the metadata lock blocking Connection 2, we have a deadlock.

This deadlock would also happen for earlier trees without MDL, but 
there DROP DATABASE would wait for a table to be removed from the
table definition cache.

This patch fixes the problem by prohibiting CREATE DATABASE in LOCK TABLES
mode. In the example above, this prevents Connection 1 from hanging trying
to get the LOCK_mysql_create_db mutex. Note that other commands that use
LOCK_mysql_create_db (ALTER/DROP DATABASE) are already prohibited in 
LOCK TABLES mode.

Incompatible change: CREATE DATABASE is now disallowed in LOCK TABLES mode.

Test case added to schema.test.


mysql-test/t/drop.test:
  Updates the test for Bug#21216 by swapping the order of CREATE DATABASE
  and LOCK TABLES. This is now needed as CREATE DATABASE is prohibited in
  LOCK TABLES mode.
mysql-test/t/schema.test:
  Test case for Bug#49988 added.
  Also fixes a problem with the test for Bug#48940 where the result 
  would differ for embedded server.
2010-01-12 16:15:21 +01:00

258 lines
6.8 KiB
Text

# Initialise
--disable_warnings
drop table if exists t1;
drop database if exists mysqltest;
# If earlier test failed
drop database if exists client_test_db;
--enable_warnings
--error 1051
drop table t1;
create table t1(n int);
insert into t1 values(1);
create temporary table t1( n int);
insert into t1 values(2);
--error 1050
create table t1(n int);
drop table t1;
select * from t1;
# now test for a bug in drop database - it is important that the name
# of the table is the same as the name of the database - in the original
# code this triggered a bug
create database mysqltest;
drop database if exists mysqltest;
create database mysqltest;
create table mysqltest.mysqltest (n int);
insert into mysqltest.mysqltest values (4);
select * from mysqltest.mysqltest;
--enable_info
drop database if exists mysqltest;
--disable_info
create database mysqltest;
#
# drop many tables - bug#3891
# we'll do it in mysqltest db, to be able to use longer table names
# (tableN instead on tN)
#
use mysqltest;
--error 1051
drop table table1, table2, table3, table4, table5, table6,
table7, table8, table9, table10, table11, table12, table13,
table14, table15, table16, table17, table18, table19, table20,
table21, table22, table23, table24, table25, table26, table27,
table28;
--error 1051
drop table table1, table2, table3, table4, table5, table6,
table7, table8, table9, table10, table11, table12, table13,
table14, table15, table16, table17, table18, table19, table20,
table21, table22, table23, table24, table25, table26, table27,
table28, table29, table30;
use test;
drop database mysqltest;
# test drop/create database and FLUSH TABLES WITH READ LOCK
flush tables with read lock;
--error 1209,1223
create database mysqltest;
unlock tables;
create database mysqltest;
show databases;
flush tables with read lock;
--error 1208,1223
drop database mysqltest;
unlock tables;
drop database mysqltest;
show databases;
--error 1008
drop database mysqltest;
# test create table and FLUSH TABLES WITH READ LOCK
drop table t1;
flush tables with read lock;
--error 1223
create table t1(n int);
unlock tables;
create table t1(n int);
show tables;
drop table t1;
# End of 4.1 tests
#
# Test for bug#21216 "Simultaneous DROP TABLE and SHOW OPEN TABLES causes
# server to crash". Crash (caused by failed assertion in 5.0 or by null
# pointer dereference in 5.1) happened when one ran SHOW OPEN TABLES
# while concurrently doing DROP TABLE (or RENAME TABLE, CREATE TABLE LIKE
# or any other command that takes name-lock) in other connection.
#
# Also includes test for similar bug#12212 "Crash that happens during
# removing of database name from cache" reappeared in 5.1 as bug#19403
# In its case crash happened when one concurrently executed DROP DATABASE
# and one of name-locking command.
#
--disable_warnings
drop database if exists mysqltest;
drop table if exists t1;
--enable_warnings
create table t1 (i int);
create database mysqltest;
lock tables t1 read;
connect (addconroot1, localhost, root,,);
--send drop table t1
connect (addconroot2, localhost, root,,);
# Server should not crash in any of the following statements
--disable_result_log
show open tables;
--enable_result_log
--send drop database mysqltest
connection default;
select 1;
unlock tables;
connection addconroot1;
--reap
connection addconroot2;
--reap
disconnect addconroot2;
--source include/wait_until_disconnected.inc
connection addconroot1;
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
#
# Bug#30152 MySQLD crash duing alter table causes DROP DATABASE to FAIL due to temp file
#
create database mysql_test;
create table mysql_test.t1(f1 int);
create table mysql_test.`#sql-347f_7` (f1 int);
create table mysql_test.`#sql-347f_8` (f1 int);
drop table mysql_test.`#sql-347f_8`;
let $MYSQLD_DATADIR= `select @@datadir`;
copy_file $MYSQLD_DATADIR/mysql_test/t1.frm $MYSQLD_DATADIR/mysql_test/#sql-347f_6.frm;
drop database mysql_test;
###########################################################################
--echo
--echo # --
--echo # -- Bug#29958: Weird message on DROP DATABASE if mysql.proc does not
--echo # -- exist.
--echo # --
--disable_warnings
DROP DATABASE IF EXISTS mysql_test;
--enable_warnings
CREATE DATABASE mysql_test;
let $MYSQLD_DATADIR= `select @@datadir`;
--let $proc_frm = $MYSQLD_DATADIR/mysql/proc.frm
--let $proc_MYD = $MYSQLD_DATADIR/mysql/proc.MYD
--let $proc_MYI = $MYSQLD_DATADIR/mysql/proc.MYI
--let $copy_of_proc_frm = $MYSQLTEST_VARDIR/tmp/bug29958.copy.frm
--let $copy_of_proc_MYD = $MYSQLTEST_VARDIR/tmp/bug29958.copy.MYD
--let $copy_of_proc_MYI = $MYSQLTEST_VARDIR/tmp/bug29958.copy.MYI
--copy_file $proc_frm $copy_of_proc_frm
--copy_file $proc_MYD $copy_of_proc_MYD
--copy_file $proc_MYI $copy_of_proc_MYI
DROP TABLE mysql.proc;
DROP DATABASE mysql_test;
--copy_file $copy_of_proc_frm $proc_frm
--copy_file $copy_of_proc_MYD $proc_MYD
--copy_file $copy_of_proc_MYI $proc_MYI
--remove_file $copy_of_proc_frm
--remove_file $copy_of_proc_MYD
--remove_file $copy_of_proc_MYI
--echo
--echo # --
--echo # -- End of Bug#29958.
--echo # --
###########################################################################
--echo
#
# Bug#26703: DROP DATABASE fails if database contains a #mysql50# table with backticks
#
create database mysqltestbug26703;
use mysqltestbug26703;
create table `#mysql50#abc``def` ( id int );
--error ER_WRONG_TABLE_NAME
create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
create table `#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
--error ER_WRONG_TABLE_NAME
create table `#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (a int);
use test;
drop database mysqltestbug26703;
--echo End of 5.1 tests
###########################################################################
--echo
--echo # --
--echo # -- Bug#37431 (DROP TABLE does not report errors correctly).
--echo # --
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--error ER_BAD_TABLE_ERROR
DROP TABLE t1;
SHOW WARNINGS;
--echo
--echo # --
--echo # -- End of Bug#37431.
--echo # --