From 7a580ce991dca7d0cf950c61b2b8d7796641788a Mon Sep 17 00:00:00 2001 From: "vva@eagle.mysql.r18.ru" <> Date: Thu, 1 Apr 2004 22:47:09 +0500 Subject: [PATCH] fixed BUG #2397 "RENAME TABLES is not blocked by FLUSH TABLES WITH READ LOCK" (added waiting for global_read_lock in mysql_rename_tables) --- mysql-test/r/rename.result | 14 ++++++++++++++ mysql-test/t/rename.test | 24 ++++++++++++++++++++++++ sql/sql_rename.cc | 3 +++ 3 files changed, 41 insertions(+) diff --git a/mysql-test/r/rename.result b/mysql-test/r/rename.result index e422fbe49c1..9bcf1bc7f97 100644 --- a/mysql-test/r/rename.result +++ b/mysql-test/r/rename.result @@ -39,3 +39,17 @@ select * from t3; drop table if exists t1,t2,t3,t4; Warnings: Note 1051 Unknown table 't4' +CREATE TABLE t1 (a int); +CREATE TABLE t3 (a int); +FLUSH TABLES WITH READ LOCK; + RENAME TABLE t1 TO t2, t3 to t4; +show tables; +Tables_in_test +t1 +t3 +UNLOCK TABLES; +show tables; +Tables_in_test +t2 +t4 +drop table t2, t4; diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test index 48a9cb401d9..bea0641ad23 100644 --- a/mysql-test/t/rename.test +++ b/mysql-test/t/rename.test @@ -35,3 +35,27 @@ select * from t3; # This should give a warning for t4 drop table if exists t1,t2,t3,t4; + +# +# Test-case for Bug #2397 RENAME TABLES is not blocked by +# FLUSH TABLES WITH READ LOCK +# + +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); + +connection con1; +CREATE TABLE t1 (a int); +CREATE TABLE t3 (a int); +connection con2; +FLUSH TABLES WITH READ LOCK; +connection con1; +send RENAME TABLE t1 TO t2, t3 to t4; +connection con2; +sleep 1; +show tables; +UNLOCK TABLES; +sleep 1; +show tables; + +drop table t2, t4; diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 6cff90ff613..7793e7236c0 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -46,6 +46,8 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list) DBUG_RETURN(1); } + if (wait_if_global_read_lock(thd,0)) + DBUG_RETURN(1); VOID(pthread_mutex_lock(&LOCK_open)); if (lock_table_names(thd, table_list)) goto err; @@ -93,6 +95,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list) err: pthread_mutex_unlock(&LOCK_open); + start_waiting_global_read_lock(thd); DBUG_RETURN(error); }