List:Maria Storage Engine« Previous MessageNext Message »
From:Michael Widenius Date:October 4 2008 5:38pm
Subject:bzr commit into MySQL/Maria:mysql-maria branch (monty:2672) Bug#39226
View as plain text  
#At bzr+ssh://bk-internal.mysql.com/bzrroot/server/mysql-maria/

 2672 Michael Widenius	2008-10-04
      Fix for bug#39226 Maria: crash with FLUSH TABLES WITH READ LOCK after LOCK TABLES
      
      The problem was that we didn't inform the handler that we are going to close tables
      that are locked and may have (at least in mearia) be part of an active transaction
modified:
  include/my_base.h
  mysql-test/r/maria.result
  mysql-test/t/maria.test
  sql/ha_partition.cc
  sql/sql_base.cc
  storage/maria/ma_extra.c

per-file messages:
  include/my_base.h
    Added HA_EXTRA_PREPARE_FOR_FORCED_CLOSE for signaling the handler that the file will be forced closed
  mysql-test/r/maria.result
    Test case
  mysql-test/t/maria.test
    Test case
  sql/ha_partition.cc
    Added support for the new extra flag: HA_EXTRA_PREPARE_FOR_FORCED_CLOSE
  sql/sql_base.cc
    Call HA_EXTRA_PREPARE_FOR_FORCED_CLOSE for tables that are locked but we are going to force close without doing a commit
  storage/maria/ma_extra.c
    If HA_EXTRA_PREPARE_FOR_FORCED_CLOSE is called and the table is part of a transaction,
    remove the table from beeing part of a transaction. This is safe as this is only used
    as part of flush tables or when the table is not part of a transaction
=== modified file 'include/my_base.h'
--- a/include/my_base.h	2008-06-26 05:18:28 +0000
+++ b/include/my_base.h	2008-10-04 17:37:54 +0000
@@ -195,7 +195,9 @@ enum ha_extra_function {
     begin and end of a statement.
   */
   HA_EXTRA_ATTACH_CHILDREN,
-  HA_EXTRA_DETACH_CHILDREN
+  HA_EXTRA_DETACH_CHILDREN,
+  /* Inform handler we will force a close as part of flush */
+  HA_EXTRA_PREPARE_FOR_FORCED_CLOSE
 };
 
 /* Compatible option, to be deleted in 6.0 */

=== modified file 'mysql-test/r/maria.result'
--- a/mysql-test/r/maria.result	2008-10-04 16:35:21 +0000
+++ b/mysql-test/r/maria.result	2008-10-04 17:37:54 +0000
@@ -2289,3 +2289,9 @@ insert into t1 values (1);
 alter table t1 partition by list (s1) (partition p1 values in (2));
 ERROR HY000: Table has no partition for value 1
 drop table t1;
+create table t1 (c1 int);
+create table t2 (c1 int);
+lock table t1 read, t2 read;
+flush tables with read lock;
+unlock tables;
+drop table t1, t2;

=== modified file 'mysql-test/t/maria.test'
--- a/mysql-test/t/maria.test	2008-10-04 16:35:21 +0000
+++ b/mysql-test/t/maria.test	2008-10-04 17:37:54 +0000
@@ -1585,3 +1585,13 @@ insert into t1 values (1);
 --error ER_NO_PARTITION_FOR_GIVEN_VALUE
 alter table t1 partition by list (s1) (partition p1 values in (2));
 drop table t1;
+
+#
+# Bug #39226 Maria: crash with FLUSH TABLES WITH READ LOCK after LOCK TABLES
+
+create table t1 (c1 int);
+create table t2 (c1 int);
+lock table t1 read, t2 read;
+flush tables with read lock;
+unlock tables;
+drop table t1, t2;

=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2008-10-04 16:35:21 +0000
+++ b/sql/ha_partition.cc	2008-10-04 17:37:54 +0000
@@ -4935,6 +4935,7 @@ int ha_partition::extra(enum ha_extra_fu
   case HA_EXTRA_KEYREAD:
   case HA_EXTRA_NO_KEYREAD:
   case HA_EXTRA_FLUSH:
+  case HA_EXTRA_PREPARE_FOR_FORCED_CLOSE:
     DBUG_RETURN(loop_extra(operation));
 
     /* Category 2), used by non-MyISAM handlers */

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2008-09-26 13:49:51 +0000
+++ b/sql/sql_base.cc	2008-10-04 17:37:54 +0000
@@ -3509,6 +3509,11 @@ static void close_old_data_files(THD *th
           if (ulcktbl->lock_count)
           {
             /*
+              Inform handler that we will do a close even if the table may be
+              locked or part of a transaction
+            */
+            table->file->extra(HA_EXTRA_PREPARE_FOR_FORCED_CLOSE);
+            /*
               Wake up threads waiting for table-level lock on this table
               so they won't sneak in when we will temporarily remove our
               lock on it. This will also give them a chance to close their

=== modified file 'storage/maria/ma_extra.c'
--- a/storage/maria/ma_extra.c	2008-08-18 22:21:22 +0000
+++ b/storage/maria/ma_extra.c	2008-10-04 17:37:54 +0000
@@ -371,6 +371,16 @@ int maria_extra(MARIA_HA *info, enum ha_
     pthread_mutex_unlock(&THR_LOCK_maria);
     break;
   }
+  case HA_EXTRA_PREPARE_FOR_FORCED_CLOSE:
+    if (info->trn)
+    {
+      pthread_mutex_lock(&share->intern_lock);
+      _ma_remove_table_from_trnman(share, info->trn);
+      /* Ensure we don't point to the deleted data in trn */
+      info->state= info->state_start= &share->state.state;
+      pthread_mutex_unlock(&share->intern_lock);    
+    }
+    break;
   case HA_EXTRA_FLUSH:
     if (!share->temporary)
       error= _ma_flush_table_files(info, MARIA_FLUSH_DATA | MARIA_FLUSH_INDEX,

Thread
bzr commit into MySQL/Maria:mysql-maria branch (monty:2672) Bug#39226Michael Widenius4 Oct
  • Re: bzr commit into MySQL/Maria:mysql-maria branch (monty:2672)Bug#39226Guilhem Bichot6 Oct
    • Re: bzr commit into MySQL/Maria:mysql-maria branch (monty:2672)Bug#39226Michael Widenius31 Oct