List:Commits« Previous MessageNext Message »
From:Jon Olav Hauglid Date:November 10 2009 8:27am
Subject:bzr commit into mysql-6.0-codebase-bugfixing branch (jon.hauglid:3702)
Bug#48248
View as plain text  
#At file:///export/home/z/mysql-6.0-codebase-bugfixing-bug48248/ based on revid:epotemkin@stripped

 3702 Jon Olav Hauglid	2009-11-10
      Bug #48248 assert in MDL_ticket::upgrade_shared_lock_to_exclusive
      
      The assert would happen if REPAIR TABLE was used on a table already
      locked by LOCK TABLES READ. REPAIR mistakenly tried to upgrade the
      read-lock to exclusive, thereby triggering the assert.
      
      The cause of the problem was that REPAIR TABLE ignored errors 
      from opening and locking tables. This is by design, as REPAIR
      can be used to broken tables that cannot be opened. However,
      repair also ignored logical errors such as the inability to
      exclusivly lock a table due to conflicting LOCK TABLES.
      
      This patch fixes the problem by not ignoring errors from
      opening and locking tables if inside LOCK TABLES mode.
      In LOCK TABLES we already know that the table can be opened,
      so that the failure to open must be a logical error.
      
      Test added to repair.test.

    modified:
      mysql-test/r/lock.result
      mysql-test/r/repair.result
      mysql-test/r/view.result
      mysql-test/t/repair.test
      sql/sql_table.cc
=== modified file 'mysql-test/r/lock.result'
--- a/mysql-test/r/lock.result	2009-10-12 09:08:34 +0000
+++ b/mysql-test/r/lock.result	2009-11-10 08:27:24 +0000
@@ -41,7 +41,7 @@ lock tables t1 write;
 check table t2;
 Table	Op	Msg_type	Msg_text
 test.t2	check	Error	Table 't2' was not locked with LOCK TABLES
-test.t2	check	error	Corrupt
+test.t2	check	status	Operation failed
 insert into t1 select index1,nr from t1;
 ERROR HY000: Table 't1' was not locked with LOCK TABLES
 unlock tables;

=== modified file 'mysql-test/r/repair.result'
--- a/mysql-test/r/repair.result	2009-04-14 14:29:45 +0000
+++ b/mysql-test/r/repair.result	2009-11-10 08:27:24 +0000
@@ -157,3 +157,15 @@ REPAIR TABLE tt1 USE_FRM;
 Table	Op	Msg_type	Msg_text
 tt1	repair	error	Cannot repair temporary table from .frm file
 DROP TABLE tt1;
+#
+# Bug #48248 assert in MDL_ticket::upgrade_shared_lock_to_exclusive
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(a INT);
+LOCK TABLES t1 READ;
+REPAIR TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	Error	Table 't1' was locked with a READ lock and can't be updated
+test.t1	repair	status	Operation failed
+UNLOCK TABLES;
+DROP TABLE t1;

=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2009-11-02 16:33:35 +0000
+++ b/mysql-test/r/view.result	2009-11-10 08:27:24 +0000
@@ -1955,15 +1955,15 @@ CHECK TABLE v1, v2, v3, v4, v5, v6;
 Table	Op	Msg_type	Msg_text
 test.v1	check	Error	FUNCTION test.f1 does not exist
 test.v1	check	Error	View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
-test.v1	check	error	Corrupt
+test.v1	check	status	Operation failed
 test.v2	check	status	OK
 test.v3	check	Error	FUNCTION test.f1 does not exist
 test.v3	check	Error	View 'test.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
-test.v3	check	error	Corrupt
+test.v3	check	status	Operation failed
 test.v4	check	status	OK
 test.v5	check	Error	FUNCTION test.f1 does not exist
 test.v5	check	Error	View 'test.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
-test.v5	check	error	Corrupt
+test.v5	check	status	Operation failed
 test.v6	check	status	OK
 create function f1 () returns int return (select max(col1) from t1);
 DROP TABLE t1;

=== modified file 'mysql-test/t/repair.test'
--- a/mysql-test/t/repair.test	2008-08-04 14:30:50 +0000
+++ b/mysql-test/t/repair.test	2009-11-10 08:27:24 +0000
@@ -158,3 +158,18 @@ CREATE TEMPORARY TABLE tt1 (c1 INT);
 REPAIR TABLE tt1 USE_FRM;
 DROP TABLE tt1;
 
+
+--echo #
+--echo # Bug #48248 assert in MDL_ticket::upgrade_shared_lock_to_exclusive
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1(a INT);
+LOCK TABLES t1 READ;
+REPAIR TABLE t1;
+
+UNLOCK TABLES;
+DROP TABLE t1;

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-11-09 11:58:51 +0000
+++ b/sql/sql_table.cc	2009-11-10 08:27:24 +0000
@@ -4519,6 +4519,7 @@ static bool mysql_admin_table(THD* thd, 
     char table_name[NAME_LEN*2+2];
     char* db = table->db;
     bool fatal_error=0;
+    bool open_error;
 
     DBUG_PRINT("admin", ("table: '%s'.'%s'", table->db, table->table_name));
     DBUG_PRINT("admin", ("extra_open_options: %u", extra_open_options));
@@ -4546,12 +4547,22 @@ static bool mysql_admin_table(THD* thd, 
       if (view_operator_func == NULL)
         table->required_type=FRMTYPE_TABLE;
 
-      open_and_lock_tables_derived(thd, table, TRUE,
-                                   MYSQL_OPEN_TAKE_UPGRADABLE_MDL);
+      open_error= open_and_lock_tables_derived(thd, table, TRUE,
+                                               MYSQL_OPEN_TAKE_UPGRADABLE_MDL);
       thd->no_warnings_for_error= 0;
       table->next_global= save_next_global;
       table->next_local= save_next_local;
       thd->open_options&= ~extra_open_options;
+      /*
+        Under locked tables, we know that the table can be opened,
+        so any errors opening the table are logical errors.
+        In these cases it does not make sense to try to repair.
+      */
+      if (open_error && thd->locked_tables_mode)
+      {
+        result_code= HA_ADMIN_FAILED;
+        goto send_result;
+      }
 #ifdef WITH_PARTITION_STORAGE_ENGINE
       if (table->table)
       {


Attachment: [text/bzr-bundle] bzr/jon.hauglid@sun.com-20091110082724-mm4b2lumf6a1eg3c.bundle
Thread
bzr commit into mysql-6.0-codebase-bugfixing branch (jon.hauglid:3702)Bug#48248Jon Olav Hauglid10 Nov