List:Commits« Previous MessageNext Message »
From:Sergei Golubchik Date:January 4 2006 10:03am
Subject:bk commit into 5.1 tree (serg:1.2020)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of serg. When serg 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.2020 06/01/04 11:02:53 serg@stripped +8 -0
  WL#2935 - SHOW STATUS support in plugins

  sql/structs.h
    1.58 06/01/04 11:02:38 serg@stripped +2 -20
    WL#2935 - SHOW STATUS support in plugins

  sql/sql_show.cc
    1.296 06/01/04 11:02:38 serg@stripped +98 -9
    WL#2935 - SHOW STATUS support in plugins

  sql/sql_plugin.h
    1.5 06/01/04 11:02:37 serg@stripped +9 -1
    WL#2935 - SHOW STATUS support in plugins

  sql/sql_plugin.cc
    1.9 06/01/04 11:02:37 serg@stripped +53 -31
    WL#2935 - SHOW STATUS support in plugins

  sql/mysqld.cc
    1.513 06/01/04 11:02:37 serg@stripped +29 -24
    bug: plugin_free must be called even with --skip-grants
    add_status_vars()/free_status_vars(), remove unused SHOW_xxx_CONST

  sql/mysql_priv.h
    1.363 06/01/04 11:02:37 serg@stripped +9 -7
    WL#2935 - SHOW STATUS support in plugins
    add_status_vars(), remove_status_vars()

  plugin/fulltext/plugin_example.c
    1.2 06/01/04 11:02:37 serg@stripped +17 -1
    WL#2935 - SHOW STATUS support in plugins
    example

  include/plugin.h
    1.7 06/01/04 11:02:37 serg@stripped +21 -1
    WL#2935 - SHOW STATUS support in plugins

# 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:	serg
# Host:	serg.mylan
# Root:	/usr/home/serg/Abk/mysql-5.1

--- 1.362/sql/mysql_priv.h	Sat Dec 31 09:23:08 2005
+++ 1.363/sql/mysql_priv.h	Wed Jan  4 11:02:37 2006
@@ -292,7 +292,7 @@ extern CHARSET_INFO *national_charset_in
 #define OPTION_SETUP_TABLES_DONE        (LL(1) << 30) // intern
 /* If not set then the thread will ignore all warnings with level notes. */
 #define OPTION_SQL_NOTES                (LL(1) << 31) // THD, user
-/* 
+/*
   Force the used temporary table to be a MyISAM table (because we will use
   fulltext functions when reading from it.
 */
@@ -322,7 +322,7 @@ extern CHARSET_INFO *national_charset_in
 #define MODE_DB2			2048
 #define MODE_MAXDB			4096
 #define MODE_NO_KEY_OPTIONS             8192
-#define MODE_NO_TABLE_OPTIONS           16384 
+#define MODE_NO_TABLE_OPTIONS           16384
 #define MODE_NO_FIELD_OPTIONS           32768
 #define MODE_MYSQL323                   65536
 #define MODE_MYSQL40                    (MODE_MYSQL323*2)
@@ -513,13 +513,11 @@ void free_items(Item *item);
 void cleanup_items(Item *item);
 class THD;
 void close_thread_tables(THD *thd, bool locked=0, bool skip_derived=0);
-bool check_one_table_access(THD *thd, ulong privilege,
-			   TABLE_LIST *tables);
+bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables);
 bool check_routine_access(THD *thd,ulong want_access,char *db,char *name,
 			  bool is_proc, bool no_errors);
 bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table);
-bool check_merge_table_access(THD *thd, char *db,
-			      TABLE_LIST *table_list);
+bool check_merge_table_access(THD *thd, char *db, TABLE_LIST *table_list);
 bool check_some_routine_access(THD *thd, const char *db, const char *name, bool is_proc);
 bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
 bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);
@@ -884,6 +882,10 @@ void calc_sum_of_all_status(STATUS_VAR *
 void append_definer(THD *thd, String *buffer, const LEX_STRING *definer_user,
                     const LEX_STRING *definer_host);
 
+int add_status_vars(show_var_st *list);
+void remove_status_vars(show_var_st *list);
+void init_status_vars();
+void free_status_vars();
 
 /* information schema */
 extern LEX_STRING information_schema_name;
@@ -1269,7 +1271,7 @@ extern I_List<NAMED_LIST> key_caches;
 extern MY_BITMAP temp_pool;
 extern String my_empty_string;
 extern const String my_null_string;
-extern SHOW_VAR init_vars[],status_vars[], internal_vars[];
+extern show_var_st init_vars[],status_vars[], internal_vars[];
 extern struct system_variables global_system_variables;
 extern struct system_variables max_system_variables;
 extern struct system_status_var global_status_var;

--- 1.512/sql/mysqld.cc	Mon Jan  2 15:40:59 2006
+++ 1.513/sql/mysqld.cc	Wed Jan  4 11:02:37 2006
@@ -1154,18 +1154,19 @@ void clean_up(bool print_message)
   set_var_free();
   free_charsets();
   (void) ha_panic(HA_PANIC_CLOSE);	/* close all tables and logs */
+#ifdef HAVE_DLOPEN
   if (!opt_noacl)
   {
-#ifdef HAVE_DLOPEN
     udf_free();
-#endif
-    plugin_free();
   }
+#endif
+  plugin_free();
   if (tc_log)
     tc_log->close();
   xid_cache_free();
   delete_elements(&key_caches, (void (*)(const char*, gptr)) free_key_cache);
   multi_keycache_free();
+  free_status_vars();
   end_thr_alarm(1);			/* Free allocated memory */
 #ifdef USE_RAID
   end_raid();
@@ -2670,12 +2671,15 @@ static int init_common_variables(const c
   mysql_log.init_pthread_objects();
   mysql_slow_log.init_pthread_objects();
   mysql_bin_log.init_pthread_objects();
-  
+
   if (gethostname(glob_hostname,sizeof(glob_hostname)-4) < 0)
     strmov(glob_hostname,"mysql");
   strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5);
   strmov(fn_ext(pidfile_name),".pid");		// Add proper extension
 
+  if (add_status_vars(status_vars))
+    return 1; // the error was already reported
+
   if (plugin_init())
   {
     sql_print_error("Failed to init plugins.");
@@ -3557,7 +3561,7 @@ we force server id to 2, but this MySQL 
 #ifndef __NETWARE__
     (void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
 #endif /* __NETWARE__ */
-    
+
     if (!opt_bootstrap)
       (void) my_delete(pidfile_name,MYF(MY_WME));	// Not needed anymore
 
@@ -3575,6 +3579,7 @@ we force server id to 2, but this MySQL 
     udf_init();
 #endif
   }
+  init_status_vars();
   if (opt_bootstrap) /* If running with bootstrap, do not start replication. */
     opt_skip_slave_start= 1;
   /*
@@ -6547,7 +6552,7 @@ struct show_var_st status_vars[]= {
   {"Com_drop_index",	       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_INDEX]), SHOW_LONG_STATUS},
   {"Com_drop_table",	       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_TABLE]), SHOW_LONG_STATUS},
   {"Com_drop_user",	       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_DROP_USER]), SHOW_LONG_STATUS},
-  {"Com_execute_sql",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_EXECUTE]), SHOW_LONG_STATUS}, 
+  {"Com_execute_sql",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_EXECUTE]), SHOW_LONG_STATUS},
   {"Com_flush",		       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_FLUSH]), SHOW_LONG_STATUS},
   {"Com_grant",		       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_GRANT]), SHOW_LONG_STATUS},
   {"Com_ha_close",	       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_HA_CLOSE]), SHOW_LONG_STATUS},
@@ -6626,14 +6631,14 @@ struct show_var_st status_vars[]= {
   {"Com_xa_rollback",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_ROLLBACK]),SHOW_LONG_STATUS},
   {"Com_xa_start",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_XA_START]),SHOW_LONG_STATUS},
   {"Compression",              (char*) &show_net_compression, SHOW_FUNC},
-  {"Connections",              (char*) &thread_id,              SHOW_LONG_CONST},
+  {"Connections",              (char*) &thread_id,              SHOW_LONG_NOFLUSH},
   {"Created_tmp_disk_tables",  (char*) offsetof(STATUS_VAR, created_tmp_disk_tables), SHOW_LONG_STATUS},
   {"Created_tmp_files",	       (char*) &my_tmp_file_created,	SHOW_LONG},
   {"Created_tmp_tables",       (char*) offsetof(STATUS_VAR, created_tmp_tables), SHOW_LONG_STATUS},
   {"Delayed_errors",           (char*) &delayed_insert_errors,  SHOW_LONG},
-  {"Delayed_insert_threads",   (char*) &delayed_insert_threads, SHOW_LONG_CONST},
+  {"Delayed_insert_threads",   (char*) &delayed_insert_threads, SHOW_LONG_NOFLUSH},
   {"Delayed_writes",           (char*) &delayed_insert_writes,  SHOW_LONG},
-  {"Flush_commands",           (char*) &refresh_version,        SHOW_LONG_CONST},
+  {"Flush_commands",           (char*) &refresh_version,        SHOW_LONG_NOFLUSH},
   {"Handler_commit",           (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS},
   {"Handler_delete",           (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS},
   {"Handler_discover",         (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS},
@@ -6650,11 +6655,11 @@ struct show_var_st status_vars[]= {
   {"Handler_update",           (char*) offsetof(STATUS_VAR, ha_update_count), SHOW_LONG_STATUS},
   {"Handler_write",            (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
 #ifdef WITH_INNOBASE_STORAGE_ENGINE
-  {"Innodb_",                  (char*) &show_innodb_vars, SHOW_FUNC},
+  {"Innodb",                   (char*) &show_innodb_vars, SHOW_FUNC},
 #endif /* WITH_INNOBASE_STORAGE_ENGINE */
   {"Key_blocks_not_flushed",   (char*) offsetof(KEY_CACHE, global_blocks_changed), SHOW_KEY_CACHE_LONG},
-  {"Key_blocks_unused",        (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_CONST_LONG},
-  {"Key_blocks_used",          (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_CONST_LONG},
+  {"Key_blocks_unused",        (char*) offsetof(KEY_CACHE, blocks_unused), SHOW_KEY_CACHE_LONG},
+  {"Key_blocks_used",          (char*) offsetof(KEY_CACHE, blocks_used), SHOW_KEY_CACHE_LONG},
   {"Key_read_requests",        (char*) offsetof(KEY_CACHE, global_cache_r_requests), SHOW_KEY_CACHE_LONGLONG},
   {"Key_reads",                (char*) offsetof(KEY_CACHE, global_cache_read), SHOW_KEY_CACHE_LONGLONG},
   {"Key_write_requests",       (char*) offsetof(KEY_CACHE, global_cache_w_requests), SHOW_KEY_CACHE_LONGLONG},
@@ -6662,23 +6667,23 @@ struct show_var_st status_vars[]= {
   {"Last_query_cost",          (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
   {"Max_used_connections",     (char*) &max_used_connections,  SHOW_LONG},
 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
-  {"Ndb_",                     (char*) &ndb_status_variables,   SHOW_ARRAY},
+  {"Ndb",                      (char*) &ndb_status_variables,   SHOW_ARRAY},
 #endif /* WITH_NDBCLUSTER_STORAGE_ENGINE */
-  {"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use,    SHOW_LONG_CONST},
-  {"Open_files",               (char*) &my_file_opened,         SHOW_LONG_CONST},
-  {"Open_streams",             (char*) &my_stream_opened,       SHOW_LONG_CONST},
+  {"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use,    SHOW_LONG_NOFLUSH},
+  {"Open_files",               (char*) &my_file_opened,         SHOW_LONG_NOFLUSH},
+  {"Open_streams",             (char*) &my_stream_opened,       SHOW_LONG_NOFLUSH},
   {"Open_table_definitions",   (char*) &show_table_definitions, SHOW_FUNC},
   {"Open_tables",              (char*) &show_open_tables,       SHOW_FUNC},
   {"Opened_tables",            (char*) offsetof(STATUS_VAR, opened_tables), SHOW_LONG_STATUS},
 #ifdef HAVE_QUERY_CACHE
-  {"Qcache_free_blocks",       (char*) &query_cache.free_memory_blocks, SHOW_LONG_CONST},
-  {"Qcache_free_memory",       (char*) &query_cache.free_memory, SHOW_LONG_CONST},
+  {"Qcache_free_blocks",       (char*) &query_cache.free_memory_blocks, SHOW_LONG_NOFLUSH},
+  {"Qcache_free_memory",       (char*) &query_cache.free_memory, SHOW_LONG_NOFLUSH},
   {"Qcache_hits",              (char*) &query_cache.hits,       SHOW_LONG},
   {"Qcache_inserts",           (char*) &query_cache.inserts,    SHOW_LONG},
   {"Qcache_lowmem_prunes",     (char*) &query_cache.lowmem_prunes, SHOW_LONG},
   {"Qcache_not_cached",        (char*) &query_cache.refused,    SHOW_LONG},
-  {"Qcache_queries_in_cache",  (char*) &query_cache.queries_in_cache, SHOW_LONG_CONST},
-  {"Qcache_total_blocks",      (char*) &query_cache.total_blocks, SHOW_LONG_CONST},
+  {"Qcache_queries_in_cache",  (char*) &query_cache.queries_in_cache, SHOW_LONG_NOFLUSH},
+  {"Qcache_total_blocks",      (char*) &query_cache.total_blocks, SHOW_LONG_NOFLUSH},
 #endif /*HAVE_QUERY_CACHE*/
   {"Questions",                (char*) &show_question,            SHOW_FUNC},
 #ifdef HAVE_REPLICATION
@@ -6732,10 +6737,10 @@ struct show_var_st status_vars[]= {
   {"Tc_log_page_size",         (char*) &tc_log_page_size,       SHOW_LONG},
   {"Tc_log_page_waits",        (char*) &tc_log_page_waits,      SHOW_LONG},
 #endif
-  {"Threads_cached",           (char*) &cached_thread_count,    SHOW_LONG_CONST},
-  {"Threads_connected",        (char*) &thread_count,           SHOW_INT_CONST},
-  {"Threads_created",	       (char*) &thread_created,		SHOW_LONG_CONST},
-  {"Threads_running",          (char*) &thread_running,         SHOW_INT_CONST},
+  {"Threads_cached",           (char*) &cached_thread_count,    SHOW_LONG_NOFLUSH},
+  {"Threads_connected",        (char*) &thread_count,           SHOW_INT},
+  {"Threads_created",	       (char*) &thread_created,		SHOW_LONG_NOFLUSH},
+  {"Threads_running",          (char*) &thread_running,         SHOW_INT},
   {"Uptime",                   (char*) &show_starttime,         SHOW_FUNC},
   {NullS, NullS, SHOW_LONG}
 };

--- 1.295/sql/sql_show.cc	Mon Jan  2 15:41:00 2006
+++ 1.296/sql/sql_show.cc	Wed Jan  4 11:02:38 2006
@@ -1516,6 +1516,94 @@ void mysqld_list_processes(THD *thd,cons
   Status functions
 *****************************************************************************/
 
+static DYNAMIC_ARRAY all_status_vars;
+static bool status_vars_inited=0;
+static int show_var_cmp(const void *var1,const void *var2)
+{
+  return strcmp(((show_var_st*)var1)->name, ((show_var_st*)var2)->name);
+}
+
+/*
+  Adds an array of show_var_st entries to the output of SHOW STATUS
+*/
+int add_status_vars(show_var_st *list)
+{
+  int res=1;
+  if (status_vars_inited)
+    pthread_mutex_lock(&LOCK_status);
+  if (!all_status_vars.buffer &&
+      my_init_dynamic_array(&all_status_vars, sizeof(show_var_st), 200, 20))
+    goto err;
+  while (list->name)
+    insert_dynamic(&all_status_vars, (gptr)list++);
+  /* make sure the list is null-terminated */
+  insert_dynamic(&all_status_vars, (gptr)list);
+  VOID(pop_dynamic(&all_status_vars));
+  if (status_vars_inited)
+    sort_dynamic(&all_status_vars, show_var_cmp);
+  res=0;
+err:
+  if (status_vars_inited)
+    pthread_mutex_unlock(&LOCK_status);
+  return res;
+}
+
+/*
+  this is to optimize startup. as no threads are running, and add_status_vars
+  is expected to be called many times, we don't take a mutex and don't sort the
+  array on each call. instead it is sorted at the end of startup
+*/
+void init_status_vars()
+{
+  status_vars_inited=1;
+  sort_dynamic(&all_status_vars, show_var_cmp);
+}
+
+/* catch-all cleanup function, cleans up everything no matter what */
+void free_status_vars()
+{
+  delete_dynamic(&all_status_vars);
+}
+
+/*
+  Removes an array of show_var_st entries to the output of SHOW STATUS
+
+  NOTE
+    The function assumes that all_status_vars is sorted
+*/
+void remove_status_vars(show_var_st *list)
+{
+  pthread_mutex_lock(&LOCK_status);
+  show_var_st *all=dynamic_element(&all_status_vars, 0, show_var_st *);
+  int a=0,b=all_status_vars.elements,c=(a+b)/2, res;
+
+  for (; list->name; list++)
+  {
+    for (a=0, b=all_status_vars.elements; b-a > 1; c=(a+b)/2)
+    {
+      res=show_var_cmp(list, all+c);
+      if (res < 0)
+        b=c;
+      else if (res > 0)
+        a=c;
+      else break;
+    }
+    if (res == 0)
+      all[c].type= SHOW_UNDEF;
+  }
+  for (a=b=0; b < all_status_vars.elements; b++)
+    if (all[b].type != SHOW_UNDEF)
+      all[a++]=all[b];
+  if (a)
+  {
+    bzero(all+a, sizeof(all[a]));
+    all_status_vars.elements=a;
+  }
+  else
+    delete_dynamic(&all_status_vars);
+  pthread_mutex_unlock(&LOCK_status);
+}
+
 static bool show_status_array(THD *thd, const char *wild,
                               show_var_st *variables,
                               enum enum_var_type value_type,
@@ -1534,6 +1622,8 @@ static bool show_status_array(THD *thd, 
   null_lex_str.length= 0;
 
   prefix_end=strnmov(name_buffer, prefix, sizeof(name_buffer)-1);
+  if (*prefix)
+    *prefix_end++='_';
   len=name_buffer + sizeof(name_buffer) - prefix_end;
 
   for (; variables->name; variables++)
@@ -1542,7 +1632,7 @@ static bool show_status_array(THD *thd, 
     name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
 
     for (var=variables; var->type == SHOW_FUNC; var= &tmp)
-      ((show_var_func)(var->value))(thd, &tmp, buff);
+      ((mysql_show_var_func)(var->value))(thd, &tmp, buff);
 
     SHOW_TYPE show_type=var->type;
     if (show_type == SHOW_ARRAY)
@@ -1578,11 +1668,10 @@ static bool show_status_array(THD *thd, 
           break;
         }
         case SHOW_LONG_STATUS:
-        case SHOW_LONG_CONST_STATUS:
           value= ((char *) status_var + (ulong) value);
           /* fall through */
         case SHOW_LONG:
-        case SHOW_LONG_CONST:
+        case SHOW_LONG_NOFLUSH: // the difference lies in refresh_status()
           end= int10_to_str(*(long*) value, buff, 10);
           break;
         case SHOW_LONGLONG:
@@ -1597,7 +1686,6 @@ static bool show_status_array(THD *thd, 
         case SHOW_MY_BOOL:
           end= strmov(buff, *(my_bool*) value ? "ON" : "OFF");
           break;
-        case SHOW_INT_CONST:
         case SHOW_INT:
           end= int10_to_str((long) *(uint32*) value, buff, 10);
           break;
@@ -1623,7 +1711,6 @@ static bool show_status_array(THD *thd, 
           break;
         }
         case SHOW_KEY_CACHE_LONG:
-        case SHOW_KEY_CACHE_CONST_LONG:
           value= (char*) dflt_key_cache + (ulong)value;
           end= int10_to_str(*(long*) value, buff, 10);
           break;
@@ -3357,7 +3444,7 @@ int fill_variables(THD *thd, TABLE_LIST 
   LEX *lex= thd->lex;
   const char *wild= lex->wild ? lex->wild->ptr() : NullS;
   pthread_mutex_lock(&LOCK_global_system_variables);
-  res= show_status_array(thd, wild, init_vars, 
+  res= show_status_array(thd, wild, init_vars,
                          lex->option_type, 0, "", tables->table);
   pthread_mutex_unlock(&LOCK_global_system_variables);
   DBUG_RETURN(res);
@@ -3374,8 +3461,10 @@ int fill_status(THD *thd, TABLE_LIST *ta
   pthread_mutex_lock(&LOCK_status);
   if (lex->option_type == OPT_GLOBAL)
     calc_sum_of_all_status(&tmp);
-  res= show_status_array(thd, wild, status_vars, OPT_GLOBAL,
-                         (lex->option_type == OPT_GLOBAL ? 
+  res= show_status_array(thd, wild,
+                         (show_var_st *)all_status_vars.buffer,
+                         OPT_GLOBAL,
+                         (lex->option_type == OPT_GLOBAL ?
                           &tmp: &thd->status_var), "",tables->table);
   pthread_mutex_unlock(&LOCK_status);
   DBUG_RETURN(res);
@@ -4146,7 +4235,7 @@ ST_FIELD_INFO plugin_fields_info[]=
   {"PLUGIN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name"},
   {"PLUGIN_VERSION", 20, MYSQL_TYPE_STRING, 0, 0, 0},
   {"PLUGIN_STATUS", 10, MYSQL_TYPE_STRING, 0, 0, "Status"},
-  {"PLUGIN_TYPE", 10, MYSQL_TYPE_STRING, 0, 0, "Type"},
+  {"PLUGIN_TYPE", 80, MYSQL_TYPE_STRING, 0, 0, "Type"},
   {"PLUGIN_TYPE_VERSION", 20, MYSQL_TYPE_STRING, 0, 0, 0},
   {"PLUGIN_LIBRARY", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Library"},
   {"PLUGIN_LIBRARY_VERSION", 20, MYSQL_TYPE_STRING, 0, 1, 0},

--- 1.57/sql/structs.h	Mon Jan  2 15:41:00 2006
+++ 1.58/sql/structs.h	Wed Jan  4 11:02:38 2006
@@ -169,32 +169,14 @@ typedef struct st_known_date_time_format
   const char *time_format;
 } KNOWN_DATE_TIME_FORMAT;
 
-
-enum SHOW_TYPE
-{
-  SHOW_UNDEF,
-  SHOW_LONG, SHOW_LONGLONG, SHOW_INT, SHOW_CHAR, SHOW_CHAR_PTR,
-  SHOW_DOUBLE_STATUS, SHOW_BOOL, SHOW_MY_BOOL,
-  SHOW_LONG_CONST, SHOW_INT_CONST, SHOW_HAVE, SHOW_SYS, SHOW_HA_ROWS,
-  SHOW_ARRAY, SHOW_FUNC,
-  SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_CONST_LONG, SHOW_KEY_CACHE_LONGLONG,
-  SHOW_LONG_STATUS, SHOW_LONG_CONST_STATUS
-};
+#define SHOW_TYPE enum enum_mysql_show_type
+#define show_var_st st_mysql_show_var
 
 enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED};
 
 extern const char *show_comp_option_name[];
 
 typedef int *(*update_var)(THD *, struct show_var_st *);
-
-typedef struct show_var_st {
-  const char *name;
-  char *value;
-  SHOW_TYPE type;
-} SHOW_VAR;
-
-#define SHOW_VAR_FUNC_BUFF_SIZE 1024
-typedef int (*show_var_func)(THD *, struct show_var_st *, char *);
 
 typedef struct	st_lex_user {
   LEX_STRING user, host, password;

--- 1.6/include/plugin.h	Sun Jan  1 16:43:17 2006
+++ 1.7/include/plugin.h	Wed Jan  4 11:02:37 2006
@@ -41,7 +41,26 @@
 int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \
 int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \
 struct st_mysql_plugin _mysql_plugin_declarations_[]= {
-#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0}}
+#define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0}}
+
+/*
+  declarations for SHOW STATUS support in plugins
+*/
+enum enum_mysql_show_type
+{
+  SHOW_UNDEF, SHOW_BOOL, SHOW_MY_BOOL, SHOW_INT, SHOW_LONG,
+  SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR,
+  SHOW_ARRAY, SHOW_FUNC
+};
+
+struct st_mysql_show_var {
+  const char *name;
+  char *value;
+  enum enum_mysql_show_type type;
+};
+
+#define SHOW_VAR_FUNC_BUFF_SIZE 1024
+typedef int (*mysql_show_var_func)(void *, struct st_mysql_show_var*, char *);
 
 /*
   Plugin description structure.
@@ -57,6 +76,7 @@ struct st_mysql_plugin
   int (*init)(void);    /* the function to invoke when plugin is loaded */
   int (*deinit)(void);  /* the function to invoke when plugin is unloaded */
   uint version;         /* plugin version (for SHOW PLUGINS)            */
+  struct st_mysql_show_var *status_vars;
 };
 
 /*************************************************************************

--- 1.8/sql/sql_plugin.cc	Sun Jan  1 16:43:18 2006
+++ 1.9/sql/sql_plugin.cc	Wed Jan  4 11:02:37 2006
@@ -94,7 +94,8 @@ static st_plugin_dl *plugin_dl_insert_or
 
 static inline void free_plugin_mem(struct st_plugin_dl *p)
 {
-  dlclose(p->handle);
+  if (p->handle)
+    dlclose(p->handle);
   my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
   if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
     my_free((gptr)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
@@ -196,6 +197,10 @@ static st_plugin_dl *plugin_dl_add(LEX_S
         sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), sizeof_st_plugin_sym);
       DBUG_RETURN(0);
 #else
+      /*
+        when the following assert starts failing, we'll have to switch
+        to the upper branch of the #ifdef
+      */
       DBUG_ASSERT(min_plugin_interface_version == 0);
       sizeof_st_plugin=(int)offsetof(struct st_mysql_plugin, version);
 #endif
@@ -226,7 +231,7 @@ static st_plugin_dl *plugin_dl_add(LEX_S
         /* fall through */
       case 0x0001:
         cur[i].version=old->version;
-        // cur[i].status_vars=old->status_vars;
+        cur[i].status_vars=old->status_vars;
         /* fall through */
       case 0x0000:
         cur[i].type=old->type;
@@ -320,7 +325,7 @@ static struct st_plugin_int *plugin_find
     {
       struct st_plugin_int *plugin= (st_plugin_int *)
         hash_search(&plugin_hash[i], (const byte *)name->str, name->length);
-      if (plugin) 
+      if (plugin)
         DBUG_RETURN(plugin);
     }
   }
@@ -382,6 +387,13 @@ static st_plugin_int *plugin_insert_or_r
                               struct st_plugin_int *));
 }
 
+static inline void err_oom(int report)
+{
+  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));
+}
 
 static my_bool plugin_add(LEX_STRING *name, LEX_STRING *dl, int report)
 {
@@ -429,21 +441,20 @@ static my_bool plugin_add(LEX_STRING *na
       tmp.name.length= name_len;
       tmp.ref_count= 0;
       tmp.state= PLUGIN_IS_UNINITIALIZED;
-      if (! (tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
+      if (plugin->status_vars)
       {
-        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;
+        show_var_st array[2]={
+          {plugin->name, (char*)plugin->status_vars, SHOW_ARRAY},
+          {0, 0, SHOW_UNDEF}
+        };
+        if (add_status_vars(array)) // add_status_vars makes a copy
+          goto err;
       }
+      if (! (tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
+        goto err;
       if (my_hash_insert(&plugin_hash[plugin->type], (byte*)tmp_plugin_ptr))
       {
         tmp_plugin_ptr->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);
@@ -454,6 +465,14 @@ static my_bool plugin_add(LEX_STRING *na
   if (report & REPORT_TO_LOG)
     sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), name->str);
 err:
+  if (plugin->status_vars)
+  {
+    show_var_st array[2]={
+      {plugin->name, (char*)plugin->status_vars, SHOW_ARRAY},
+      {0, 0, SHOW_UNDEF}
+    };
+    remove_status_vars(array);
+  }
   plugin_dl_del(dl);
   DBUG_RETURN(TRUE);
 }
@@ -466,6 +485,14 @@ static void plugin_del(LEX_STRING *name)
   DBUG_ENTER("plugin_del");
   if ((plugin= plugin_find_internal(name, MYSQL_ANY_PLUGIN)))
   {
+    if (plugin->plugin->status_vars)
+    {
+      show_var_st array[2]={
+        {plugin->plugin->name, (char*)plugin->plugin->status_vars, SHOW_ARRAY},
+        {0, 0, SHOW_UNDEF}
+      };
+      remove_status_vars(array);
+    }
     hash_delete(&plugin_hash[plugin->plugin->type], (byte*)plugin);
     plugin_dl_del(&plugin->plugin_dl->dl);
     plugin->state= PLUGIN_IS_FREED;
@@ -494,7 +521,7 @@ void plugin_unlock(struct st_plugin_int 
 static int plugin_initialize(struct st_plugin_int *plugin)
 {
   DBUG_ENTER("plugin_initialize");
-  
+
   if (plugin->plugin->init)
   {
     if (plugin->plugin->init())
@@ -506,7 +533,7 @@ static int plugin_initialize(struct st_p
       goto err;
     }
   }
-  
+
   switch (plugin->plugin->type)
   {
   case MYSQL_STORAGE_ENGINE_PLUGIN:
@@ -605,11 +632,11 @@ int plugin_init(void)
                   get_hash_key, NULL, 0))
       goto err;
   }
-  
+
   initialized= 1;
 
   DBUG_RETURN(0);
-  
+
 err:
   DBUG_RETURN(1);
 }
@@ -651,9 +678,9 @@ void plugin_load(void)
   MEM_ROOT mem;
   THD *new_thd;
   DBUG_ENTER("plugin_load");
-  
+
   DBUG_ASSERT(initialized);
-  
+
   if (!(new_thd= new THD))
   {
     sql_print_error("Can't allocate memory for plugin structures");
@@ -716,12 +743,7 @@ void plugin_free(void)
   {
     struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
                                               struct st_plugin_dl *);
-#ifdef HAVE_DLOPEN
-    if (tmp->handle)
-    {
-      free_plugin_mem(tmp);
-    }
-#endif
+    free_plugin_mem(tmp);
   }
   delete_dynamic(&plugin_dl_array);
   if (initialized)
@@ -746,7 +768,7 @@ my_bool mysql_install_plugin(THD *thd, L
   tables.table_name= tables.alias= (char *)"plugin";
   if (check_table_access(thd, INSERT_ACL, &tables, 0))
     DBUG_RETURN(TRUE);
-    
+
   /* need to open before acquiring THR_LOCK_plugin or it will deadlock */
   if (! (table = open_ltable(thd, &tables, TL_WRITE)))
     DBUG_RETURN(TRUE);
@@ -755,7 +777,7 @@ my_bool mysql_install_plugin(THD *thd, L
   if (plugin_add(name, dl, REPORT_TO_USER))
     goto err;
   tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN);
-  
+
   if (plugin_initialize(tmp))
   {
     my_error(ER_CANT_INITIALIZE_UDF, MYF(0), name->str,
@@ -774,7 +796,7 @@ my_bool mysql_install_plugin(THD *thd, L
     table->file->print_error(error, MYF(0));
     goto deinit;
   }
-  
+
   rw_unlock(&THR_LOCK_plugin);
   DBUG_RETURN(FALSE);
 deinit:
@@ -815,7 +837,7 @@ my_bool mysql_uninstall_plugin(THD *thd,
     my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str);
     goto err;
   }
-  
+
   if (plugin->ref_count)
   {
     plugin->state= PLUGIN_IS_DELETED;
@@ -858,13 +880,13 @@ my_bool plugin_foreach(THD *thd, plugin_
   struct st_plugin_int *plugin;
   DBUG_ENTER("mysql_uninstall_plugin");
   rw_rdlock(&THR_LOCK_plugin);
-  
+
   if (type == MYSQL_ANY_PLUGIN)
   {
     for (idx= 0; idx < plugin_array.elements; idx++)
     {
       plugin= dynamic_element(&plugin_array, idx, struct st_plugin_int *);
-      
+
       /* FREED records may have garbage pointers */
       if ((plugin->state != PLUGIN_IS_FREED) &&
           func(thd, plugin, arg))

--- 1.4/sql/sql_plugin.h	Thu Dec 29 21:24:07 2005
+++ 1.5/sql/sql_plugin.h	Wed Jan  4 11:02:37 2006
@@ -17,7 +17,15 @@
 #ifndef _sql_plugin_h
 #define _sql_plugin_h
 
+/*
+  the following #define adds server-only members to enum_mysql_show_type,
+  that is defined in plugin.h
+*/
+#define SHOW_FUNC    SHOW_FUNC, SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG, \
+                     SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_HAVE,   \
+                     SHOW_HA_ROWS, SHOW_SYS, SHOW_LONG_NOFLUSH
 #include <plugin.h>
+#undef SHOW_FUNC
 
 #define MYSQL_ANY_PLUGIN         -1
 
@@ -65,7 +73,7 @@ extern my_bool mysql_uninstall_plugin(TH
 
 extern my_bool plugin_register_builtin(struct st_mysql_plugin *plugin);
 
-typedef my_bool (plugin_foreach_func)(THD *thd, 
+typedef my_bool (plugin_foreach_func)(THD *thd,
                                       st_plugin_int *plugin,
                                       void *arg);
 extern my_bool plugin_foreach(THD *thd, plugin_foreach_func *func,

--- 1.1/plugin/fulltext/plugin_example.c	Wed Dec 28 13:05:21 2005
+++ 1.2/plugin/fulltext/plugin_example.c	Wed Jan  4 11:02:37 2006
@@ -18,6 +18,8 @@
 #include <m_ctype.h>
 #include <plugin.h>
 
+long number_of_calls=0; /* for SHOW STATUS, see below */
+
 /*
   Simple full-text parser plugin that acts as a replacement for the
   built-in full-text parser:
@@ -167,6 +169,8 @@ int simple_parser_parse(MYSQL_FTPARSER_P
 {
   char *end, *start, *docend= param->doc + param->length;
 
+  number_of_calls++;
+
   for (end= start= param->doc;; end++)
   {
     if (end == docend)
@@ -198,6 +202,16 @@ static struct st_mysql_ftparser simple_p
   simple_parser_deinit              /* parser deinit function */
 };
 
+/*
+  Plugin status variables for SHOW STATUS
+*/
+
+struct st_mysql_show_var simple_status[]=
+{
+  {"static",     "just a static text",     SHOW_CHAR},
+  {"called",     (char *)&number_of_calls, SHOW_LONG},
+  {0,0,0}
+};
 
 /*
   Plugin library descriptor
@@ -211,6 +225,8 @@ mysql_declare_plugin
   "MySQL AB",                 /* author                          */
   "Simple Full-Text Parser",  /* description                     */
   simple_parser_plugin_init,  /* init function (when loaded)     */
-  simple_parser_plugin_deinit /* deinit function (when unloaded) */
+  simple_parser_plugin_deinit,/* deinit function (when unloaded) */
+  0x0001,                     /* version                         */
+  &simple_status              /* status variables                */
 }
 mysql_declare_plugin_end;
Thread
bk commit into 5.1 tree (serg:1.2020)Sergei Golubchik4 Jan