List:Commits« Previous MessageNext Message »
From:Dmitry Lenev Date:February 25 2009 11:37am
Subject:bzr commit into mysql-6.0 branch (dlenev:2728) Bug#39674
View as plain text  
#At file:///home/dlenev/src/bzr/mysql-6.0-bg39674/

 2728 Dmitry Lenev	2009-02-25
      Fix for bug #39674 "On shutdown mdl_destroy() called before
      plugin_shutdown()".
      
      Attempt to shutdown PBXT engine plugin led to assertion failure 
      caused by using already destroyed mutex in metadata locking 
      subsystem.
      
      This problem stemmed from the fact that we MDL subsystem and
      table definition cache were deinitialized before plugin shutdown 
      while PBXT plugin during its shutdown process accessed tables and 
      therefore expected them to be in working shape.
      
      This patch solves this problem by moving deinitialization of
      these two subsystems after plugins are shut down.
      
      No test case is provided since such test case would require
      using PBXT or other plugin which accesses tables during its 
      shutdown process.
modified:
  sql/mysql_priv.h
  sql/mysqld.cc
  sql/sql_base.cc

per-file messages:
  sql/mysql_priv.h
    Introduced table_def_start_shutdown() function which informs
    table definition cache that shutdown process has been started
    so it has to keep number of TABLE and TABLE_SHARE objects minimal
    in order to reduce number of references to pluggable engines.
  sql/mysqld.cc
    Destroy table definition cache and meta-data locking subsystem 
    after shutting down plugins. This allows plugins to work with
    tables during their shutdown.
    Since table definition cache hold references to storage engine
    plugins we have to remove unused tables from it before shutting
    down plugins and keep number of these references minimal during
    the process (by immediately removing tables opened during this
    process from the table definition cache).
  sql/sql_base.cc
    Introduced table_def_start_shutdown() function which informs
    table definition cache that shutdown process has been started
    so it has to keep number of TABLE and TABLE_SHARE objects
    minimal in order to reduce number of references to pluggable
    engines. 
    This allows to smoothly shutdown such plugins without completely 
    prohibiting access to tables/table definition cache while
    shutting down other plugins.
=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2009-02-04 12:34:03 +0000
+++ b/sql/mysql_priv.h	2009-02-25 11:37:09 +0000
@@ -1122,6 +1122,7 @@ bool compare_record(TABLE *table);
 bool append_file_to_dir(THD *thd, const char **filename_ptr, 
                         const char *table_name);
 bool table_def_init(void);
+void table_def_start_shutdown(void);
 void table_def_free(void);
 void assign_new_table_id(TABLE_SHARE *share);
 uint cached_open_tables(void);

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-02-04 12:34:03 +0000
+++ b/sql/mysqld.cc	2009-02-25 11:37:09 +0000
@@ -1350,9 +1350,7 @@ void clean_up(bool print_message)
   grant_free();
 #endif
   query_cache_destroy();
-  table_def_free();
   hostname_cache_free();
-  mdl_destroy();
   item_user_lock_free();
   lex_free();				/* Free some memory */
   item_create_cleanup();
@@ -1367,6 +1365,7 @@ void clean_up(bool print_message)
 #ifndef EMBEDDED_LIBRARY
   backup_shutdown();
 #endif
+  table_def_start_shutdown();
   plugin_shutdown();
   ha_end();
   if (tc_log)
@@ -1374,6 +1373,8 @@ void clean_up(bool print_message)
   delegates_destroy();
   xid_cache_free();
   wt_end();
+  table_def_free();
+  mdl_destroy();
   delete_elements(&key_caches, (void (*)(const char*, uchar*)) free_key_cache);
   multi_keycache_free();
   sp_cache_end();

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-02-05 12:49:39 +0000
+++ b/sql/sql_base.cc	2009-02-25 11:37:09 +0000
@@ -107,6 +107,7 @@ TABLE *unused_tables;
 HASH table_def_cache;
 static TABLE_SHARE *oldest_unused_share, end_of_unused_share;
 static bool table_def_inited= 0;
+static bool table_def_shutdown_in_progress= 0;
 
 static bool check_and_update_table_version(THD *thd, TABLE_LIST *tables,
                                            TABLE_SHARE *table_share);
@@ -268,13 +269,36 @@ bool table_def_init(void)
 }
 
 
+/**
+  Notify table definition cache that process of shutting down server
+  has started so it has to keep number of TABLE and TABLE_SHARE objects
+  minimal in order to reduce number of references to pluggable engines.
+*/
+
+void table_def_start_shutdown(void)
+{
+  if (table_def_inited)
+  {
+    pthread_mutex_lock(&LOCK_open);
+    /* Free all cached but unused TABLEs and TABLE_SHAREs first. */
+    close_cached_tables(NULL, NULL, TRUE, FALSE);
+    /*
+      Ensure that TABLE and TABLE_SHARE objects which are created for
+      tables that are open during process of plugins' shutdown are
+      immediately released. This keeps number of references to engine
+      plugins minimal and allows shutdown to proceed smoothly.
+    */
+    table_def_shutdown_in_progress= TRUE;
+    pthread_mutex_unlock(&LOCK_open);
+  }
+}
+
+
 void table_def_free(void)
 {
   DBUG_ENTER("table_def_free");
   if (table_def_inited)
   {
-    /* Free all open TABLEs first. */
-    close_cached_tables(NULL, NULL, FALSE, FALSE);
     table_def_inited= 0;
     /* Free table definitions. */
     my_hash_free(&table_def_cache);
@@ -633,7 +657,8 @@ void release_table_share(TABLE_SHARE *sh
 
   if (!--share->ref_count)
   {
-    if (share->version != refresh_version)
+    if (share->version != refresh_version ||
+        table_def_shutdown_in_progress)
       to_be_deleted=1;
     else
     {
@@ -1493,7 +1518,8 @@ bool close_thread_table(THD *thd, TABLE 
 
   table->mdl_lock_data= 0;
   if (table->needs_reopen() ||
-      thd->version != refresh_version || !table->db_stat)
+      thd->version != refresh_version || !table->db_stat ||
+      table_def_shutdown_in_progress)
   {
     free_cache_entry(table);
     found_old_table=1;

Thread
bzr commit into mysql-6.0 branch (dlenev:2728) Bug#39674Dmitry Lenev25 Feb
  • Re: bzr commit into mysql-6.0 branch (dlenev:2728) Bug#39674Sergei Golubchik18 Mar