List:Commits« Previous MessageNext Message »
From:Jon Olav Hauglid Date:February 8 2012 1:10pm
Subject:bzr push into mysql-trunk branch (jon.hauglid:3861 to 3862) Bug#13417754
View as plain text  
 3862 Jon Olav Hauglid	2012-02-08
      Bug#13417754 ASSERT IN ROW_DROP_DATABASE_FOR_MYSQL DURING DROP SCHEMA
      
      This assert could be triggered if an InnoDB table was being moved
      to a different database using ALTER TABLE ... RENAME, while this
      database concurrently was being dropped by DROP DATABASE.
      
      The reason for the problem was that no metadata lock was taken
      on the target database by ALTER TABLE ... RENAME.
      DROP DATABASE was therefore not blocked and could remove
      the database while ALTER TABLE ... RENAME was executing. This
      could cause the assert in InnoDB to be triggered.
      
      This patch fixes the problem by taking a IX metadata lock on
      the target database before ALTER TABLE ... RENAME starts
      moving a table to a different database.
      
      Note that this problem did not occur with RENAME TABLE which
      already takes the correct metadata locks.
      
      Also note that this patch slightly changes the behavior of
      ALTER TABLE ... RENAME. Before, the statement would abort and
      return an error if a lock on the target table name could not
      be taken immediately. With this patch, ALTER TABLE ... RENAME
      will instead block and wait until the lock can be taken 
      (or until we get a lock timeout). This also means that it is
      possible to get ER_LOCK_DEADLOCK errors in this situation
      since we allow ALTER TABLE ... RENAME to wait and not just
      abort immediately.
      
      Test case added to innodb_mysql_sync.test.

    modified:
      mysql-test/r/innodb_mysql_sync.result
      mysql-test/t/innodb_mysql_sync.test
      sql/sql_table.cc
      storage/innobase/handler/ha_innodb.cc
 3861 Vasil Dimov	2012-02-08
      Fix compilation warning with GCC 4.6:
      
      sql_show.cc: In function 'int store_create_info(THD*, TABLE_LIST*, String*, HA_CREATE_INFO*, bool)':
      sql_show.cc:1429:8: error: variable 'show_table_options' set but not used [-Werror=unused-but-set-variable]

    modified:
      sql/sql_show.cc
=== modified file 'mysql-test/r/innodb_mysql_sync.result'
--- a/mysql-test/r/innodb_mysql_sync.result	2011-06-01 12:24:51 +0000
+++ b/mysql-test/r/innodb_mysql_sync.result	2012-02-08 13:10:23 +0000
@@ -186,3 +186,29 @@ a	b
 1	12345
 2	23456
 DROP TABLE t1;
+#
+# Bug#13417754 ASSERT IN ROW_DROP_DATABASE_FOR_MYSQL DURING DROP SCHEMA
+#
+DROP TABLE IF EXISTS t1;
+DROP DATABASE IF EXISTS db1;
+CREATE TABLE t1(a int) engine=InnoDB;
+CREATE DATABASE db1;
+# Connection con1
+SET DEBUG_SYNC= 'after_innobase_rename_table SIGNAL locked WAIT_FOR continue';
+# Sending:
+ALTER TABLE t1 RENAME db1.t1;
+# Connection con2
+SET DEBUG_SYNC= 'now WAIT_FOR locked';
+# DROP DATABASE db1 should now be blocked by ALTER TABLE
+# Sending:
+DROP DATABASE db1;
+# Connection default
+# Check that DROP DATABASE is blocked by IX lock on db1
+# Resume ALTER TABLE
+SET DEBUG_SYNC= 'now SIGNAL continue';
+# Connection con1
+# Reaping: ALTER TABLE t1 RENAME db1.t1;
+# Connection con2
+# Reaping: DROP DATABASE db1
+# Connection default;
+SET DEBUG_SYNC= 'RESET';

=== modified file 'mysql-test/t/innodb_mysql_sync.test'
--- a/mysql-test/t/innodb_mysql_sync.test	2011-06-01 12:24:51 +0000
+++ b/mysql-test/t/innodb_mysql_sync.test	2012-02-08 13:10:23 +0000
@@ -304,6 +304,62 @@ DROP TABLE t1;
 disconnect con1;
 
 
+--echo #
+--echo # Bug#13417754 ASSERT IN ROW_DROP_DATABASE_FOR_MYSQL DURING DROP SCHEMA
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP DATABASE IF EXISTS db1;
+--enable_warnings
+
+CREATE TABLE t1(a int) engine=InnoDB;
+CREATE DATABASE db1;
+
+connect(con1, localhost, root);
+connect(con2, localhost, root);
+
+--echo # Connection con1
+connection con1;
+SET DEBUG_SYNC= 'after_innobase_rename_table SIGNAL locked WAIT_FOR continue';
+--echo # Sending:
+--send ALTER TABLE t1 RENAME db1.t1
+
+--echo # Connection con2
+connection con2;
+SET DEBUG_SYNC= 'now WAIT_FOR locked';
+--echo # DROP DATABASE db1 should now be blocked by ALTER TABLE
+--echo # Sending:
+--send DROP DATABASE db1
+
+--echo # Connection default
+connection default;
+--echo # Check that DROP DATABASE is blocked by IX lock on db1
+let $wait_condition=
+  SELECT COUNT(*) = 1 FROM information_schema.processlist
+  WHERE state = "Waiting for schema metadata lock" and
+        info = "DROP DATABASE db1";
+--source include/wait_condition.inc
+--echo # Resume ALTER TABLE
+SET DEBUG_SYNC= 'now SIGNAL continue';
+
+--echo # Connection con1
+connection con1;
+--echo # Reaping: ALTER TABLE t1 RENAME db1.t1;
+--reap
+
+--echo # Connection con2
+connection con2;
+--echo # Reaping: DROP DATABASE db1
+--reap
+
+--echo # Connection default;
+connection default;
+SET DEBUG_SYNC= 'RESET';
+disconnect con1;
+disconnect con2;
+
+
 # Check that all connections opened by test cases in this file are really
 # gone so execution of other tests won't be affected by their presence.
 --source include/wait_until_count_sessions.inc

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2012-02-07 23:33:54 +0000
+++ b/sql/sql_table.cc	2012-02-08 13:10:23 +0000
@@ -6206,8 +6206,26 @@ bool mysql_alter_table(THD *thd,char *ne
       }
       else
       {
+        MDL_request_list mdl_requests;
+        MDL_request target_db_mdl_request;
+
         target_mdl_request.init(MDL_key::TABLE, new_db, new_name,
                                 MDL_EXCLUSIVE, MDL_TRANSACTION);
+        mdl_requests.push_front(&target_mdl_request);
+
+        /*
+          If we are moving the table to a different database, we also
+          need IX lock on the database name so that the target database
+          is protected by MDL while the table is moved.
+        */
+        if (new_db != db)
+        {
+          target_db_mdl_request.init(MDL_key::SCHEMA, new_db, "",
+                                     MDL_INTENTION_EXCLUSIVE,
+                                     MDL_TRANSACTION);
+          mdl_requests.push_front(&target_db_mdl_request);
+        }
+
         /*
           Global intention exclusive lock must have been already acquired when
           table to be altered was open, so there is no need to do it here.
@@ -6216,14 +6234,10 @@ bool mysql_alter_table(THD *thd,char *ne
                                                    "", "",
                                                    MDL_INTENTION_EXCLUSIVE));
 
-        if (thd->mdl_context.try_acquire_lock(&target_mdl_request))
+        if (thd->mdl_context.acquire_locks(&mdl_requests,
+                                           thd->variables.lock_wait_timeout))
           DBUG_RETURN(TRUE);
-        if (target_mdl_request.ticket == NULL)
-        {
-          /* Table exists and is locked by some thread. */
-	  my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
-	  DBUG_RETURN(TRUE);
-        }
+
         DEBUG_SYNC(thd, "locked_table_name");
         /*
           Table maybe does not exist, but we got an exclusive lock

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2012-02-06 11:04:33 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2012-02-08 13:10:23 +0000
@@ -35,6 +35,7 @@ this program; if not, write to the Free
 			// EXPLAIN_FILENAME_MAX_EXTRA_LENGTH
 
 #include <sql_acl.h>	// PROCESS_ACL
+#include <debug_sync.h> // DEBUG_SYNC
 #include <mysys_err.h>
 #include <mysql/innodb_priv.h>
 
@@ -9475,6 +9476,8 @@ ha_innobase::rename_table(
 
 	error = innobase_rename_table(trx, from, to, TRUE);
 
+	DEBUG_SYNC(thd, "after_innobase_rename_table");
+
 	/* Tell the InnoDB server that there might be work for
 	utility threads: */
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (jon.hauglid:3861 to 3862) Bug#13417754Jon Olav Hauglid8 Feb