List:Commits« Previous MessageNext Message »
From:antony Date:April 18 2007 9:17am
Subject:bk commit into 5.1 tree (acurtis:1.2579)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of antony. When antony does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-04-18 00:17:05-07:00, acurtis@stripped +1 -0
  WL#2936
    Fix for ndb initialization deadlock.
    Changes so that LOCK_plugin is released before calling plugin initialization function
    so that deadlock is avoided should the plugin create THD objects.
    Plugin installation is still serialized.

  sql/sql_plugin.cc@stripped, 2007-04-18 00:17:01-07:00, acurtis@stripped +34 -0
    WL2936
      Changes so that LOCK_plugin is released before calling plugin initialization
function
      so that deadlock is avoided should the plugin create THD objects.
      Plugin installation is still serialized.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	acurtis
# Host:	ltamd64.xiphis.org
# Root:	/home/antony/work2/mysql-5.1-wl2936

--- 1.49/sql/sql_plugin.cc	2007-04-18 00:17:19 -07:00
+++ 1.50/sql/sql_plugin.cc	2007-04-18 00:17:19 -07:00
@@ -97,6 +97,8 @@
 static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];
 /* we are always manipulating ref count, so a rwlock is unneccessary */
 static pthread_mutex_t LOCK_plugin;
+static pthread_cond_t COND_plugin;
+static THD *plugin_update_thd= 0;
 static bool initialized= 0;
 static bool reap_needed= false;
 
@@ -974,6 +976,13 @@
   DBUG_ENTER("plugin_initialize");
 
   safe_mutex_assert_owner(&LOCK_plugin);
+  /*
+    A little bit of voodoo here: During plugin subsystem initialization,
+	current_thd will return NULL. After mysqld startup is complete, later
+	calls to mysql_install_plugin will be set to current THD.
+   */
+  DBUG_ASSERT(plugin_update_thd == current_thd);
+  pthread_mutex_unlock(&LOCK_plugin);
 
   if (plugin_type_initialize[plugin->plugin->type])
   {
@@ -981,6 +990,7 @@
     {
       sql_print_error("Plugin '%s' registration as a %s failed.",
                       plugin->name.str,
plugin_type_names[plugin->plugin->type].str);
+      pthread_mutex_lock(&LOCK_plugin);
       goto err;
     }
   }
@@ -990,10 +1000,12 @@
     {
       sql_print_error("Plugin '%s' init function returned error.",
                       plugin->name.str);
+      pthread_mutex_lock(&LOCK_plugin);
       goto err;
     }
   }
 
+  pthread_mutex_lock(&LOCK_plugin);
   plugin->state= PLUGIN_IS_READY;
 
   if (plugin->plugin->status_vars)
@@ -1086,6 +1098,7 @@
 
 
   pthread_mutex_init(&LOCK_plugin, MY_MUTEX_INIT_FAST);
+  pthread_cond_init(&COND_plugin, NULL);
 
   if (my_init_dynamic_array(&plugin_dl_array,
                             sizeof(struct st_plugin_dl),16,16) ||
@@ -1533,6 +1546,7 @@
     pthread_mutex_unlock(&LOCK_plugin);
 
     initialized= 0;
+    pthread_cond_destroy(&COND_plugin);
     pthread_mutex_destroy(&LOCK_plugin);
 
     my_afree(plugins);
@@ -1581,6 +1595,11 @@
     DBUG_RETURN(TRUE);
 
   pthread_mutex_lock(&LOCK_plugin);
+  DBUG_ASSERT(thd != plugin_update_thd);
+  while (plugin_update_thd)
+    pthread_cond_wait(&COND_plugin, &LOCK_plugin);
+  plugin_update_thd= thd;
+  
   rw_wrlock(&LOCK_system_variables_hash);
   error= plugin_add(thd->mem_root, name, dl, &argc, NULL, REPORT_TO_USER);
   rw_unlock(&LOCK_system_variables_hash);
@@ -1606,6 +1625,8 @@
     goto deinit;
   }
 
+  plugin_update_thd= 0;
+  pthread_cond_signal(&COND_plugin);
   pthread_mutex_unlock(&LOCK_plugin);
   DBUG_RETURN(FALSE);
 deinit:
@@ -1613,6 +1634,8 @@
   reap_needed= true;
   reap_plugins();
 err:
+  plugin_update_thd= 0;
+  pthread_cond_signal(&COND_plugin);
   pthread_mutex_unlock(&LOCK_plugin);
   DBUG_RETURN(TRUE);
 }
@@ -1634,6 +1657,11 @@
     DBUG_RETURN(TRUE);
 
   pthread_mutex_lock(&LOCK_plugin);
+  DBUG_ASSERT(thd != plugin_update_thd);
+  while (plugin_update_thd)
+    pthread_cond_wait(&COND_plugin, &LOCK_plugin);
+  plugin_update_thd= thd;
+  
   if (!(plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
   {
     my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str);
@@ -1669,8 +1697,14 @@
       DBUG_RETURN(TRUE);
     }
   }
+  
+  plugin_update_thd= 0;
+  pthread_cond_signal(&COND_plugin);  
   DBUG_RETURN(FALSE);
+
 err:
+  plugin_update_thd= 0;
+  pthread_cond_signal(&COND_plugin);
   pthread_mutex_unlock(&LOCK_plugin);
   DBUG_RETURN(TRUE);
 }
Thread
bk commit into 5.1 tree (acurtis:1.2579)antony18 Apr