MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Jon Olav Hauglid Date:August 19 2009 2:51pm
Subject:bzr commit into mysql-5.4 branch (jon.hauglid:2870) Bug#45949
View as plain text  
#At file:///export/home/z/mysql-next-bugfixing-bug45949-two/ based on revid:kostja@stripped

 2870 Jon Olav Hauglid	2009-08-19
      Bug #45949 Assertion `!tables->table' in open_tables() on 
                 ALTER + INSERT DELAYED
      
      The assertion was caused by improperly closing tables when 
      INSERT DELAYED needed to reopen tables. This patch replaces
      the call to close_thread_tables with close_tables_for_reopen
      which fixes the problem.
      
      The only way I was able to trigger the reopen code path and 
      thus the assertion, was if ALTER TABLE killed the delayed
      insert thread and the delayed insert thread was able to enter
      the reopen code path before it noticed that thd->killed had
      been set. Note that in these cases reopen will always fail 
      since open_table() will check thd->killed and return. This patch
      therefore adds two more thd->killed checks to minimize the 
      chance of entering the reopen code path without hope for success.
      
      The patch also changes it so that if the delayed insert is killed
      using KILL_CONNECTION, the error message that is copied to the
      connection thread is ER_QUERY_INTERRUPTED rather than 
      ER_SERVER_SHUTDOWN. This means that if INSERT DELAYED fails, 
      the user will now see "Query execution was interrupted" rather
      than the misleading "Server shutdown in progress".
      
      No test case is supplied. This is for two reasons:
      1) Unable to reproduce the error without having the delayed insert
      thread in a killed state which means that reopen is futile and
      was not supposed to be attempted.
      2) Difficulty of using sync points in other threads than 
      the connection thread.
      The patch has been successfully tested with the RQG and the grammar
      supplied in the bug description.

    modified:
      sql/sql_insert.cc
=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2009-08-13 14:29:55 +0000
+++ b/sql/sql_insert.cc	2009-08-19 14:51:21 +0000
@@ -1988,6 +1988,11 @@ bool delayed_get_table(THD *thd, TABLE_L
       }
       pthread_mutex_unlock(&di->mutex);
       thd_proc_info(thd, "got old table");
+      if (thd->killed)
+      {
+        di->unlock();
+        goto end_create;
+      }
       if (di->thd.killed)
       {
         if (di->thd.is_error())
@@ -1995,20 +2000,19 @@ bool delayed_get_table(THD *thd, TABLE_L
           /*
             Copy the error message. Note that we don't treat fatal
             errors in the delayed thread as fatal errors in the
-            main thread. Use of my_message will enable stored
-            procedures continue handlers.
+            main thread. If delayed thread was killed, we don't
+            want to send "Server shutdown in progress" in the
+            INSERT THREAD.
           */
-          my_message(di->thd.stmt_da->sql_errno(), di->thd.stmt_da->message(),
-                     MYF(0));
-	}
-	di->unlock();
+          if (di->thd.stmt_da->sql_errno() == ER_SERVER_SHUTDOWN)
+            my_message(ER_QUERY_INTERRUPTED, ER(ER_QUERY_INTERRUPTED), MYF(0));
+          else
+            my_message(di->thd.stmt_da->sql_errno(), di->thd.stmt_da->message(),
+                       MYF(0));
+        }
+        di->unlock();
         goto end_create;
       }
-      if (thd->killed)
-      {
-	di->unlock();
-	goto end_create;
-      }
       pthread_mutex_lock(&LOCK_delayed_insert);
       delayed_threads.append(di);
       pthread_mutex_unlock(&LOCK_delayed_insert);
@@ -2075,8 +2079,11 @@ TABLE *Delayed_insert::get_local_table(T
       goto error;
     if (dead)
     {
-      my_message(thd.stmt_da->sql_errno(), thd.stmt_da->message(), MYF(0));
-      goto error;
+      /* Don't copy over "Server shutdown in progress". */
+      if (thd.stmt_da->sql_errno() == ER_SERVER_SHUTDOWN)
+        my_message(ER_QUERY_INTERRUPTED, ER(ER_QUERY_INTERRUPTED), MYF(0));
+      else
+        my_message(thd.stmt_da->sql_errno(), thd.stmt_da->message(), MYF(0));
     }
   }
   share= table->s;
@@ -2426,7 +2433,7 @@ pthread_handler_t handle_delayed_insert(
 
   for (;;)
   {
-    if (thd->killed == THD::KILL_CONNECTION)
+    if (thd->killed)
     {
       uint lock_count;
       /*
@@ -2489,7 +2496,7 @@ pthread_handler_t handle_delayed_insert(
     }
     thd_proc_info(&(di->thd), 0);
 
-    if (di->tables_in_use && ! thd->lock)
+    if (di->tables_in_use && ! thd->lock && !thd->killed)
     {
       bool need_reopen;
       /*
@@ -2506,14 +2513,15 @@ pthread_handler_t handle_delayed_insert(
                                           MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK,
                                           &need_reopen)))
       {
-        if (need_reopen)
+        if (need_reopen && !thd->killed)
         {
           /*
             We were waiting to obtain TL_WRITE_DELAYED (probably due to
             someone having or requesting TL_WRITE_ALLOW_READ) and got
             aborted. Try to reopen table and if it fails die.
           */
-          close_thread_tables(thd);
+          TABLE_LIST *tl_ptr = &di->table_list;
+          close_tables_for_reopen(thd, &tl_ptr);
           di->table= 0;
           if (di->open_and_lock_table())
           {


Attachment: [text/bzr-bundle] bzr/jon.hauglid@sun.com-20090819145121-46k2r8gou2493kn1.bundle
Thread
bzr commit into mysql-5.4 branch (jon.hauglid:2870) Bug#45949Jon Olav Hauglid19 Aug