List:Commits« Previous MessageNext Message »
From:Sergey Vojtovich Date:April 13 2010 11:10am
Subject:bzr commit into mysql-5.1-bugteam branch (svoj:3436) Bug#39053
View as plain text  
#At file:///home/svoj/devel/bzr-mysql/mysql-5.1-bugteam-bug39053/ based on revid:sergey.glukhov@stripped

 3436 Sergey Vojtovich	2010-04-13
      BUG#39053 - UNISTALL PLUGIN does not allow the storage engine
                  to cleanup open connections
      
      It was possible to UNINSTALL storage engine plugin when binding
      between THD object and storage engine is still active (e.g. in
      the middle of transaction).
      
      To avoid unclean deactivation (uninstall) of storage engine plugin
      in the middle of transaction, additional storage engine plugin
      lock is acquired by thd_set_ha_data().
      
      If ha_data is not null and storage engine plugin was not locked
      by thd_set_ha_data() in this connection before, storage engine
      plugin gets locked.
      
      If ha_data is null and storage engine plugin was locked by
      thd_set_ha_data() in this connection before, storage engine
      plugin lock gets released.
      
      If handlerton::close_connection() didn't reset ha_data, server does
      it immediately after calling handlerton::close_connection().
      
      Note that this is just a framework fix, storage engines must switch
      to thd_set_ha_data() from thd_ha_data() if they want to see fit.
     @ include/mysql/plugin.h
        As thd_{get|set}_ha_data() have some extra logic now, they
        must be implemented on server side.
     @ include/mysql/plugin.h.pp
        As thd_{get|set}_ha_data() have some extra logic now, they
        must be implemented on server side.
     @ sql/handler.cc
        Make sure ha_data is reset and ha_data lock is released.
     @ sql/sql_class.cc
        As thd_{get|set}_ha_data() have some extra logic now, they
        must be implemented on server side.
     @ sql/sql_class.h
        Added ha_data lock.

    modified:
      include/mysql/plugin.h
      include/mysql/plugin.h.pp
      sql/handler.cc
      sql/sql_class.cc
      sql/sql_class.h
=== modified file 'include/mysql/plugin.h'
--- a/include/mysql/plugin.h	2010-03-16 13:15:19 +0000
+++ b/include/mysql/plugin.h	2010-04-13 11:10:35 +0000
@@ -801,30 +801,37 @@ void mysql_query_cache_invalidate4(MYSQL
                                    const char *key, unsigned int key_length,
                                    int using_trx);
 
-#ifdef __cplusplus
-}
-#endif
 
-#ifdef __cplusplus
 /**
   Provide a handler data getter to simplify coding
 */
-inline
-void *
-thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton)
-{
-  return *thd_ha_data(thd, hton);
-}
+void *thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton);
+
 
 /**
   Provide a handler data setter to simplify coding
+
+  @details
+  Set ha_data pointer (storage engine per-connection information).
+
+  To avoid unclean deactivation (uninstall) of storage engine plugin
+  in the middle of transaction, additional storage engine plugin
+  lock is acquired.
+
+  If ha_data is not null and storage engine plugin was not locked
+  by thd_set_ha_data() in this connection before, storage engine
+  plugin gets locked.
+
+  If ha_data is null and storage engine plugin was locked by
+  thd_set_ha_data() in this connection before, storage engine
+  plugin lock gets released.
+
+  If handlerton::close_connection() didn't reset ha_data, server does
+  it immediately after calling handlerton::close_connection().
 */
-inline
-void
-thd_set_ha_data(const MYSQL_THD thd, const struct handlerton *hton,
-                const void *ha_data)
-{
-  *thd_ha_data(thd, hton)= (void*) ha_data;
+void thd_set_ha_data(MYSQL_THD thd, const struct handlerton *hton,
+                     const void *ha_data);
+#ifdef __cplusplus
 }
 #endif
 

=== modified file 'include/mysql/plugin.h.pp'
--- a/include/mysql/plugin.h.pp	2008-06-17 12:27:04 +0000
+++ b/include/mysql/plugin.h.pp	2010-04-13 11:10:35 +0000
@@ -137,3 +137,6 @@ void thd_get_xid(const void* thd, MYSQL_
 void mysql_query_cache_invalidate4(void* thd,
                                    const char *key, unsigned int key_length,
                                    int using_trx);
+void *thd_get_ha_data(const void* thd, const struct handlerton *hton);
+void thd_set_ha_data(void* thd, const struct handlerton *hton,
+                     const void *ha_data);

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2009-12-01 09:19:51 +0000
+++ b/sql/handler.cc	2010-04-13 11:10:35 +0000
@@ -601,9 +601,13 @@ static my_bool closecon_handlerton(THD *
     there's no need to rollback here as all transactions must
     be rolled back already
   */
-  if (hton->state == SHOW_OPTION_YES && hton->close_connection &&
-      thd_get_ha_data(thd, hton))
-    hton->close_connection(hton, thd);
+  if (hton->state == SHOW_OPTION_YES && thd_get_ha_data(thd, hton))
+  {
+    if (hton->close_connection)
+      hton->close_connection(hton, thd);
+    /* make sure ha_data is reset and ha_data_lock is released */
+    thd_set_ha_data(thd, hton, NULL);
+  }
   return FALSE;
 }
 

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2010-03-29 02:32:30 +0000
+++ b/sql/sql_class.cc	2010-04-13 11:10:35 +0000
@@ -284,6 +284,37 @@ void **thd_ha_data(const THD *thd, const
   return (void **) &thd->ha_data[hton->slot].ha_ptr;
 }
 
+
+/**
+  Provide a handler data getter to simplify coding
+*/
+extern "C"
+void *thd_get_ha_data(const THD *thd, const struct handlerton *hton)
+{
+  return *thd_ha_data(thd, hton);
+}
+
+
+/**
+  Provide a handler data setter to simplify coding
+  @see thd_set_ha_data() definition in plugin.h
+*/
+extern "C"
+void thd_set_ha_data(THD *thd, const struct handlerton *hton,
+                     const void *ha_data)
+{
+  if (ha_data && !thd->ha_data[hton->slot].lock)
+    thd->ha_data[hton->slot].lock=
+      ha_lock_engine(NULL, (handlerton*) hton);
+  else if (!ha_data && thd->ha_data[hton->slot].lock)
+  {
+    plugin_unlock(NULL, thd->ha_data[hton->slot].lock);
+    thd->ha_data[hton->slot].lock= NULL;
+  }
+  *thd_ha_data(thd, hton)= (void*) ha_data;
+}
+
+
 extern "C"
 long long thd_test_options(const THD *thd, long long test_options)
 {

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2010-03-29 02:32:30 +0000
+++ b/sql/sql_class.h	2010-04-13 11:10:35 +0000
@@ -1264,7 +1264,11 @@ struct Ha_data
     @sa trans_register_ha()
   */
   Ha_trx_info ha_info[2];
-
+  /**
+    NULL: engine is not bound to this thread
+    non-NULL: engine is bount to this thread, engine shutdown forbidden
+  */
+  plugin_ref lock;
   Ha_data() :ha_ptr(NULL) {}
 };
 


Attachment: [text/bzr-bundle] bzr/svoj@sun.com-20100413111035-1a1vwcd1vtouj2f6.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (svoj:3436) Bug#39053Sergey Vojtovich13 Apr
  • Re: bzr commit into mysql-5.1-bugteam branch (svoj:3436) Bug#39053Ingo Strüwing13 Apr
    • Re: bzr commit into mysql-5.1-bugteam branch (svoj:3436) Bug#39053Sergey Vojtovich14 Apr