List:Internals« Previous MessageNext Message »
From:svoj Date:September 27 2005 5:28pm
Subject:bk commit into 5.0 tree (svoj:1.1913)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of svoj. When svoj 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
  1.1913 05/09/27 20:28:04 svoj@stripped +4 -0
  WL#2575 - Fulltext: Parser plugin for FTS
  - Plugin reference counter added.
  - Plugin state (FREED/DELETED/UNINITIALIZED/READY) added.
  - UNINSTALL PLUGIN handler added.

  sql/table.cc
    1.181 05/09/27 20:28:00 svoj@stripped +9 -1
    Add a reference to parser plugin when table is opened.
    Remove a reference when table is closed.

  sql/sql_yacc.yy
    1.417 05/09/27 20:28:00 svoj@stripped +1 -1
    Add a reference to plugin.

  sql/sql_plugin.h
    1.7 05/09/27 20:28:00 svoj@stripped +12 -1
    Plugin reference counter added.
    plugin_find renamed to plugin_lock and adds now reference to plugin.
    plugin_unlock removes reference added by plugin_find.
    Added plugin state (FREED/DELETED/UNINITIALIZED/READY).

  sql/sql_plugin.cc
    1.11 05/09/27 20:27:59 svoj@stripped +89 -13
    Plugin reference counter added.
    plugin_find renamed to plugin_lock and adds now reference to plugin.
    plugin_unlock removes reference added by plugin_find.
    Added plugin state (FREED/DELETED/UNINITIALIZED/READY).
    UNINSTALL PLUGIN handler added.

# 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:	svoj
# Host:	svoj-laptop.mysql.com
# Root:	/home/svoj/devel/mysql/CNET/mysql-5.0

--- 1.416/sql/sql_yacc.yy	2005-09-23 20:43:31 +05:00
+++ 1.417/sql/sql_yacc.yy	2005-09-27 20:28:00 +05:00
@@ -2836,7 +2836,7 @@
 	| WITH PARSER_SYM IDENT_sys
           {
             struct st_plugin_int *plugin;
-            if ((plugin= plugin_find(&$3, MYSQL_FTPARSER_PLUGIN)))
+            if ((plugin= plugin_lock(&$3, MYSQL_FTPARSER_PLUGIN)))
               $$= plugin;
             else
             {

--- 1.180/sql/table.cc	2005-09-22 19:56:27 +05:00
+++ 1.181/sql/table.cc	2005-09-27 20:28:00 +05:00
@@ -368,7 +368,7 @@
         }
         parser_name.str= next_chunk;
         parser_name.length= strlen(next_chunk);
-        keyinfo->parser= plugin_find(&parser_name, MYSQL_FTPARSER_PLUGIN);
+        keyinfo->parser= plugin_lock(&parser_name, MYSQL_FTPARSER_PLUGIN);
         if (! keyinfo->parser)
         {
           my_free(buff, MYF(0));
@@ -966,9 +966,17 @@
 int closefrm(register TABLE *table)
 {
   int error=0;
+  uint idx;
+  KEY *key_info;
   DBUG_ENTER("closefrm");
   if (table->db_stat)
     error=table->file->close();
+  key_info= table->key_info;
+  for (idx= table->s->keys; idx; idx--, key_info++)
+  {
+    if (key_info->flags & HA_USES_PARSER)
+      plugin_unlock(&key_info->parser->name);
+  }
   my_free((char*) table->alias, MYF(MY_ALLOW_ZERO_PTR));
   table->alias= 0;
   if (table->field)

--- 1.10/sql/sql_plugin.cc	2005-09-23 19:49:37 +05:00
+++ 1.11/sql/sql_plugin.cc	2005-09-27 20:27:59 +05:00
@@ -206,7 +206,8 @@
   {
     struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
                                                struct st_plugin_int *);
-    if ((type < 0 || type == tmp->plugin->type) &&
+    if (tmp->state == PLUGIN_IS_READY &&
+        (type < 0 || type == tmp->plugin->type) &&
         ! my_strnncoll(system_charset_info,
                        (const uchar *)name->str, name->length,
                        (const uchar *)tmp->name.str, tmp->name.length))
@@ -216,12 +217,13 @@
 }
 
 
-struct st_plugin_int *plugin_find(LEX_STRING *name, int type)
+struct st_plugin_int *plugin_lock(LEX_STRING *name, int type)
 {
   struct st_plugin_int *rc;
   DBUG_ENTER("plugin_find");
-  rw_rdlock(&THR_LOCK_plugin);
-  rc= plugin_find_internal(name, type);
+  rw_wrlock(&THR_LOCK_plugin);
+  if ((rc= plugin_find_internal(name, type)))
+    rc->ref_count++;
   rw_unlock(&THR_LOCK_plugin);
   DBUG_RETURN(rc);
 }
@@ -254,6 +256,8 @@
       tmp.plugin= plugin;
       tmp.name.str= (char *)plugin->name;
       tmp.name.length= name_len;
+      tmp.ref_count= 0;
+      tmp.state= PLUGIN_IS_UNINITIALIZED;
       if (insert_dynamic(&plugin_array, (gptr)&tmp))
       {
         if (report & REPORT_TO_USER)
@@ -282,12 +286,13 @@
   {
     struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
                                                struct st_plugin_int *);
-    if (! my_strnncoll(system_charset_info,
+    if (tmp->state != PLUGIN_IS_FREED &&
+        ! my_strnncoll(system_charset_info,
                        (const uchar *)name->str, name->length,
                        (const uchar *)tmp->name.str, tmp->name.length))
     {
       plugin_dl_del(&tmp->plugin_dl->dl);
-      bzero(tmp, sizeof(struct st_plugin_int));
+      tmp->state= PLUGIN_IS_FREED;
       break;
     }
   }
@@ -295,6 +300,25 @@
 }
 
 
+void plugin_unlock(LEX_STRING *name)
+{
+  struct st_plugin_int *plugin;
+  DBUG_ENTER("plugin_release");
+  rw_wrlock(&THR_LOCK_plugin);
+  plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN);
+  DBUG_ASSERT(plugin && plugin->ref_count);
+  plugin->ref_count--;
+  if (plugin->state == PLUGIN_IS_DELETED && ! plugin->ref_count)
+  {
+    if (plugin->plugin->deinit)
+      plugin->plugin->deinit();
+    plugin_del(name);
+  }
+  rw_unlock(&THR_LOCK_plugin);
+  DBUG_VOID_RETURN;
+}
+
+
 static void plugin_call_initializer(void)
 {
   uint i;
@@ -303,7 +327,7 @@
   {
     struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
                                                struct st_plugin_int *);
-    if (tmp->plugin->init)
+    if (tmp->state == PLUGIN_IS_UNINITIALIZED && tmp->plugin->init)
     {
       DBUG_PRINT("info", ("Initializing plugin: '%s'", tmp->name.str));
       if (tmp->plugin->init())
@@ -315,6 +339,8 @@
         plugin_del(&tmp->name);
       }
     }
+    if (tmp->state == PLUGIN_IS_UNINITIALIZED)
+      tmp->state= PLUGIN_IS_READY;
   }
   DBUG_VOID_RETURN;
 }
@@ -328,14 +354,18 @@
   {
     struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
                                                struct st_plugin_int *);
-    if (tmp->plugin && tmp->plugin->deinit)
+    if (tmp->state == PLUGIN_IS_READY)
     {
-      DBUG_PRINT("info", ("Deinitializing plugin: '%s'", tmp->name.str));
-      if (tmp->plugin->deinit())
+      if (tmp->plugin->deinit)
       {
-        DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
-                               tmp->name.str))
+        DBUG_PRINT("info", ("Deinitializing plugin: '%s'", tmp->name.str));
+        if (tmp->plugin->deinit())
+        {
+          DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
+                                 tmp->name.str))
+        }
       }
+      tmp->state= PLUGIN_IS_UNINITIALIZED;
     }
   }
   DBUG_VOID_RETURN;
@@ -461,6 +491,7 @@
       my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str, ER(ER_UNKNOWN_ERROR));
       goto err;
     }
+    tmp->state= PLUGIN_IS_READY;
   }
   if (! (table = open_ltable(thd, &tables, TL_WRITE)))
     goto deinit;
@@ -486,5 +517,50 @@
 
 my_bool mysql_uninstall_plugin(THD *thd, LEX_STRING *name)
 {
-  return FALSE;
+  TABLE *table;
+  TABLE_LIST tables;
+  struct st_plugin_int *plugin;
+  DBUG_ENTER("mysql_uninstall_plugin");
+  rw_wrlock(&THR_LOCK_plugin);
+  if (! (plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
+  {
+    my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str);
+    goto err;
+  }
+  if (plugin->ref_count)
+  {
+    plugin->state= PLUGIN_IS_DELETED;
+    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
+                 "Plugin is not deleted, waiting on tables.");
+  }
+  else
+  {
+    if (plugin->plugin->deinit)
+      plugin->plugin->deinit();
+    plugin_del(name);
+  }
+  bzero(&tables, sizeof(tables));
+  tables.db= (char *)"mysql";
+  tables.table_name= tables.alias= (char *)"plugin";
+  if (! (table= open_ltable(thd, &tables, TL_WRITE)))
+    goto err;
+  table->field[0]->store(name->str, name->length, system_charset_info);
+  table->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
+  if (! table->file->index_read_idx(table->record[0], 0,
+                                    (byte *)table->field[0]->ptr,
+                                    table->key_info[0].key_length,
+                                    HA_READ_KEY_EXACT))
+  {
+    int error;
+    if ((error= table->file->delete_row(table->record[0])))
+    {
+      table->file->print_error(error, MYF(0));
+      goto err;
+    }
+  }
+  rw_unlock(&THR_LOCK_plugin);
+  DBUG_RETURN(FALSE);
+err:
+  rw_unlock(&THR_LOCK_plugin);
+  DBUG_RETURN(TRUE);
 }

--- 1.6/sql/sql_plugin.h	2005-09-22 19:56:27 +05:00
+++ 1.7/sql/sql_plugin.h	2005-09-27 20:28:00 +05:00
@@ -17,6 +17,14 @@
 #ifndef _sql_plugin_h
 #define _sql_plugin_h
 #include <plugin.h>
+enum enum_plugin_state
+{
+  PLUGIN_IS_FREED= 0,
+  PLUGIN_IS_DELETED,
+  PLUGIN_IS_UNINITIALIZED,
+  PLUGIN_IS_READY
+};
+
 struct st_plugin_dl
 {
   LEX_STRING dl;
@@ -31,12 +39,15 @@
   LEX_STRING name;
   struct st_mysql_plugin *plugin;
   struct st_plugin_dl *plugin_dl;
+  enum enum_plugin_state state;
+  uint ref_count;
 };
 
 extern char *opt_plugin_dir;
 extern void plugin_init(void);
 extern void plugin_free(void);
-extern st_plugin_int *plugin_find(LEX_STRING *name, int type);
+extern st_plugin_int *plugin_lock(LEX_STRING *name, int type);
+extern void plugin_unlock(LEX_STRING *name);
 extern my_bool mysql_install_plugin(THD *thd, LEX_STRING *name, LEX_STRING *dl);
 extern my_bool mysql_uninstall_plugin(THD *thd, LEX_STRING *name);
 #endif
Thread
bk commit into 5.0 tree (svoj:1.1913)svoj27 Sep