List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:February 9 2009 1:20pm
Subject:bzr commit into mysql-5.1-bugteam branch (davi:2793) Bug#41110 Bug#41112
View as plain text  
# At a local mysql-5.1-bugteam repository of davi

 2793 Davi Arnaut	2009-02-09
      Bug#41110: crash with handler command when used concurrently with alter table
      Bug#41112: crash in mysql_ha_close_table/get_lock_data with alter table
      
      The problem is that the server wasn't handling robustly failures
      to re-open a table during a HANDLER .. READ statement. If the
      table needed to be re-opened due to it's storage engine being
      altered to one that don't support HANDLER, a reference (dangling
      pointer) to a closed table could be left in place and accessed in
      later attempts to fetch from the table using the handler. Also,
      if the server failed to set a error message if the re-open
      failed. These problems could lead to server crashes or hangs.
      
      The solution is to remove any references to a closed table and
      to set a error if reopening a table during a HANDLER .. READ
      statement fails.
modified:
  mysql-test/include/handler.inc
  mysql-test/r/handler_innodb.result
  mysql-test/r/handler_myisam.result
  sql/sql_handler.cc

per-file messages:
  mysql-test/include/handler.inc
    Add test case for Bug#41110 and Bug#41112
  mysql-test/r/handler_innodb.result
    Add test case result for Bug#41110 and Bug#41112
  mysql-test/r/handler_myisam.result
    Add test case result for Bug#41110 and Bug#41112
  sql/sql_handler.cc
    Remove redundant reopen check.
    Set errors even if reopening table.
    Reset TABLE_LIST::table reference on the error path, table is closed.
=== modified file 'mysql-test/include/handler.inc'
--- a/mysql-test/include/handler.inc	2007-11-20 17:17:53 +0000
+++ b/mysql-test/include/handler.inc	2009-02-09 13:20:02 +0000
@@ -692,3 +692,29 @@ unlock tables;
 drop table t1;
 --error ER_UNKNOWN_TABLE
 handler t1 read a next;
+
+#
+# Bug#41110: crash with handler command when used concurrently with alter table
+# Bug#41112: crash in mysql_ha_close_table/get_lock_data with alter table
+#
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (a int);
+insert into t1 values (1);
+handler t1 open;
+connect(con1,localhost,root,,);
+send alter table t1 engine=memory;
+connection default;
+let $wait_condition=
+  select count(*) = 1 from information_schema.processlist
+  where state = "rename result table" and info = "alter table t1 engine=memory";
+--source include/wait_condition.inc
+--error ER_ILLEGAL_HA
+handler t1 read a next;
+handler t1 close;
+connection con1;
+--reap
+drop table t1;
+connection default;

=== modified file 'mysql-test/r/handler_innodb.result'
--- a/mysql-test/r/handler_innodb.result	2008-08-11 18:02:03 +0000
+++ b/mysql-test/r/handler_innodb.result	2009-02-09 13:20:02 +0000
@@ -730,3 +730,12 @@ unlock tables;
 drop table t1;
 handler t1 read a next;
 ERROR 42S02: Unknown table 't1' in HANDLER
+drop table if exists t1;
+create table t1 (a int);
+insert into t1 values (1);
+handler t1 open;
+alter table t1 engine=memory;
+handler t1 read a next;
+ERROR HY000: Table storage engine for 't1' doesn't have this option
+handler t1 close;
+drop table t1;

=== modified file 'mysql-test/r/handler_myisam.result'
--- a/mysql-test/r/handler_myisam.result	2007-11-20 17:17:53 +0000
+++ b/mysql-test/r/handler_myisam.result	2009-02-09 13:20:02 +0000
@@ -728,3 +728,12 @@ unlock tables;
 drop table t1;
 handler t1 read a next;
 ERROR 42S02: Unknown table 't1' in HANDLER
+drop table if exists t1;
+create table t1 (a int);
+insert into t1 values (1);
+handler t1 open;
+alter table t1 engine=memory;
+handler t1 read a next;
+ERROR HY000: Table storage engine for 't1' doesn't have this option
+handler t1 close;
+drop table t1;

=== modified file 'sql/sql_handler.cc'
--- a/sql/sql_handler.cc	2008-02-19 12:58:08 +0000
+++ b/sql/sql_handler.cc	2009-02-09 13:20:02 +0000
@@ -177,8 +177,7 @@ static void mysql_ha_close_table(THD *th
     'reopen' is set when a handler table is to be re-opened. In this case,
     'tables' is the pointer to the hashed TABLE_LIST object which has been
     saved on the original open.
-    'reopen' is also used to suppress the sending of an 'ok' message or
-    error messages.
+    'reopen' is also used to suppress the sending of an 'ok' message.
 
   RETURN
     FALSE OK
@@ -214,8 +213,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST 
                     strlen(tables->alias) + 1))
     {
       DBUG_PRINT("info",("duplicate '%s'", tables->alias));
-      if (! reopen)
-        my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias);
+      my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias);
       goto err;
     }
   }
@@ -259,8 +257,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST 
   /* There can be only one table in '*tables'. */
   if (! (tables->table->file->ha_table_flags() & HA_CAN_SQL_HANDLER))
   {
-    if (! reopen)
-      my_error(ER_ILLEGAL_HA, MYF(0), tables->alias);
+    my_error(ER_ILLEGAL_HA, MYF(0), tables->alias);
     goto err;
   }
 
@@ -307,6 +304,7 @@ err:
     my_free((char*) hash_tables, MYF(0));
   if (tables->table)
     mysql_ha_close_table(thd, tables, FALSE);
+  tables->table= NULL;
   DBUG_PRINT("exit",("ERROR"));
   DBUG_RETURN(TRUE);
 }

Thread
bzr commit into mysql-5.1-bugteam branch (davi:2793) Bug#41110 Bug#41112Davi Arnaut9 Feb
  • Re: bzr commit into mysql-5.1-bugteam branch (davi:2793) Bug#41110Bug#41112Konstantin Osipov21 Feb