MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:svoj Date:October 24 2005 11:39am
Subject:bk commit into 5.0 tree (svoj:1.2010)
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.2010 05/10/24 16:39:34 svoj@stripped +2 -0
  WL#2575 - Fulltext: Parser plugin for FTS
  Hash for each type of plugin.
  Fixed a bug in sql_yacc.yy - parser name must be allocated.

  sql/sql_yacc.yy
    1.434 05/10/24 16:39:19 svoj@stripped +1 -1
    Allocate memory for fulltext parser name LEX_STRING.

  sql/sql_plugin.cc
    1.15 05/10/24 16:39:18 svoj@stripped +71 -27
    Grouped by type plugins are now hashed.

# 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.433/sql/sql_yacc.yy	2005-10-20 14:04:04 +05:00
+++ 1.434/sql/sql_yacc.yy	2005-10-24 16:39:19 +05:00
@@ -2847,7 +2847,7 @@
 	| WITH PARSER_SYM IDENT_sys
           {
             if (plugin_is_ready(&$3, MYSQL_FTPARSER_PLUGIN))
-              $$= &$3;
+              $$= (LEX_STRING *)sql_memdup(&$3, sizeof(LEX_STRING));
             else
             {
               my_error(ER_FUNCTION_NOT_DEFINED, MYF(0), $3.str);

--- 1.14/sql/sql_plugin.cc	2005-10-14 17:40:15 +05:00
+++ 1.15/sql/sql_plugin.cc	2005-10-24 16:39:18 +05:00
@@ -27,6 +27,7 @@
 
 static DYNAMIC_ARRAY plugin_dl_array;
 static DYNAMIC_ARRAY plugin_array;
+static HASH plugin_hash[MYSQL_MAX_PLUGIN];
 static rw_lock_t THR_LOCK_plugin;
 static bool initialized= 0;
 
@@ -203,17 +204,19 @@
   DBUG_ENTER("plugin_find_internal");
   if (! initialized)
     DBUG_RETURN(0);
-  for (i= 0; i < plugin_array.elements; i++)
+  if (type == MYSQL_ANY_PLUGIN)
   {
-    struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
-                                               struct st_plugin_int *);
-    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))
-      DBUG_RETURN(tmp);
+    for (i= 0; i < MYSQL_MAX_PLUGIN; i++)
+    {
+      struct st_plugin_int *plugin= (st_plugin_int *)
+        hash_search(&plugin_hash[i], name->str, name->length);
+      if (plugin) 
+        DBUG_RETURN(plugin);
+    }
   }
+  else
+    DBUG_RETURN((st_plugin_int *)
+        hash_search(&plugin_hash[type], name->str, name->length));
   DBUG_RETURN(0);
 }
 
@@ -221,9 +224,11 @@
 my_bool plugin_is_ready(LEX_STRING *name, int type)
 {
   my_bool rc= FALSE;
+  struct st_plugin_int *plugin;
   DBUG_ENTER("plugin_is_ready");
   rw_rdlock(&THR_LOCK_plugin);
-  if (plugin_find_internal(name, type))
+  if ((plugin= plugin_find_internal(name, type)) &&
+      plugin->state == PLUGIN_IS_READY)
     rc= TRUE;
   rw_unlock(&THR_LOCK_plugin);
   DBUG_RETURN(rc);
@@ -236,7 +241,12 @@
   DBUG_ENTER("plugin_find");
   rw_wrlock(&THR_LOCK_plugin);
   if ((rc= plugin_find_internal(name, type)))
-    rc->ref_count++;
+  {
+    if (rc->state == PLUGIN_IS_READY)
+      rc->ref_count++;
+    else
+      rc= 0;
+  }
   rw_unlock(&THR_LOCK_plugin);
   DBUG_RETURN(rc);
 }
@@ -258,10 +268,11 @@
   if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
     DBUG_RETURN(TRUE);
   /* Find plugin by name */
-  for (plugin= tmp.plugin_dl->plugins; plugin->type; plugin++)
+  for (plugin= tmp.plugin_dl->plugins; plugin->info; plugin++)
   {
     uint name_len= strlen(plugin->name);
-    if (! my_strnncoll(system_charset_info,
+    if (plugin->type >= 0 && plugin->type < MYSQL_MAX_PLUGIN &&
+        ! my_strnncoll(system_charset_info,
                        (const uchar *)name->str, name->length,
                        (const uchar *)plugin->name,
                        name_len))
@@ -277,7 +288,21 @@
           my_error(ER_OUTOFMEMORY, MYF(0), sizeof(struct st_plugin_int));
         if (report & REPORT_TO_LOG)
           sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_int));
-        break;
+        goto err;
+      }
+      if (my_hash_insert(&plugin_hash[plugin->type],
+                         (byte*)dynamic_element(&plugin_array,
+                                                plugin_array.elements - 1,
+                                                struct st_plugin_int *)))
+      {
+        struct st_plugin_int *tmp_plugin= dynamic_element(&plugin_array,
+            plugin_array.elements - 1, struct st_plugin_int *);
+        tmp_plugin->state= PLUGIN_IS_FREED;
+        if (report & REPORT_TO_USER)
+          my_error(ER_OUTOFMEMORY, MYF(0), sizeof(struct st_plugin_int));
+        if (report & REPORT_TO_LOG)
+          sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_int));
+        goto err;
       }
       DBUG_RETURN(FALSE);
     }
@@ -286,6 +311,7 @@
     my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), name->str);
   if (report & REPORT_TO_LOG)
     sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), name->str);
+err:
   plugin_dl_del(dl);
   DBUG_RETURN(TRUE);
 }
@@ -294,20 +320,13 @@
 static void plugin_del(LEX_STRING *name)
 {
   uint i;
+  struct st_plugin_int *plugin;
   DBUG_ENTER("plugin_del");
-  for (i= 0; i < plugin_array.elements; i++)
+  if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
   {
-    struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
-                                               struct st_plugin_int *);
-    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);
-      tmp->state= PLUGIN_IS_FREED;
-      break;
-    }
+    hash_delete(&plugin_hash[plugin->plugin->type], (byte*)plugin);
+    plugin_dl_del(&plugin->plugin_dl->dl);
+    plugin->state= PLUGIN_IS_FREED;
   }
   DBUG_VOID_RETURN;
 }
@@ -383,12 +402,21 @@
 }
 
 
+static byte *get_hash_key(const byte *buff, uint *length,
+                   my_bool not_used __attribute__((unused)))
+{
+  struct st_plugin_int *plugin= (st_plugin_int *)buff;
+  *length= (uint)plugin->name.length;
+  return((byte *)plugin->name.str);
+}
+
+
 void plugin_init(void)
 {
   TABLE_LIST tables;
   TABLE *table;
   READ_RECORD read_record_info;
-  int error;
+  int error, i;
   MEM_ROOT mem;
   DBUG_ENTER("plugin_init");
   if (initialized)
@@ -405,6 +433,18 @@
     delete_dynamic(&plugin_array);
     DBUG_VOID_RETURN;
   }
+  for (i= 0; i < MYSQL_MAX_PLUGIN; i++)
+  {
+    if (hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
+                  get_hash_key, NULL, 0))
+    {
+      sql_print_error("Can't allocate memory for plugin structures");
+      delete new_thd;
+      delete_dynamic(&plugin_dl_array);
+      delete_dynamic(&plugin_array);
+      DBUG_VOID_RETURN;
+    }
+  }
   init_sql_alloc(&mem, 1024, 0);
   initialized= 1;
   new_thd->store_globals();
@@ -420,6 +460,8 @@
     sql_print_error("Can't open the mysql.plugin table. Please run the mysql_install_db script to create it.");
     delete_dynamic(&plugin_dl_array);
     delete_dynamic(&plugin_array);
+    for (i= 0; i < MYSQL_MAX_PLUGIN; i++)
+      hash_free(&plugin_hash[i]);
     goto end;
   }
   table= tables.table;
@@ -456,6 +498,8 @@
   uint i;
   DBUG_ENTER("plugin_free");
   plugin_call_deinitializer();
+  for (i= 0; i < MYSQL_MAX_PLUGIN; i++)
+    hash_free(&plugin_hash[i]);
   delete_dynamic(&plugin_array);
   for (i= 0; i < plugin_dl_array.elements; i++)
   {
Thread
bk commit into 5.0 tree (svoj:1.2010)svoj24 Oct