[Groonga-mysql-commit] mroonga/mroonga [master] #741 make "uninstall plugin" possible

Back to archive index

null+****@clear***** null+****@clear*****
2010年 12月 20日 (月) 01:06:43 JST


Kentoku SHIBA	2010-12-19 16:06:43 +0000 (Sun, 19 Dec 2010)

  New Revision: aa7cdd126114dcdf3767a2b45675b7389fc8c657

  Log:
    #741 make "uninstall plugin" possible

  Copied files:
    test/sql/include/groonga_deinit.inc
      (from test/sql/t/flush_logs.test)
  Modified files:
    ha_mroonga.cc
    test/sql/t/binlog.test
    test/sql/t/btree.test
    test/sql/t/count_performance.test
    test/sql/t/create_table.test
    test/sql/t/delete.test
    test/sql/t/drop_database.test
    test/sql/t/drop_table.test
    test/sql/t/flush_logs.test
    test/sql/t/fulltext.test
    test/sql/t/hash.test
    test/sql/t/information_schema.test
    test/sql/t/insert.test
    test/sql/t/last_insert_grn_id.test
    test/sql/t/log_level.test
    test/sql/t/order_limit_performance.test
    test/sql/t/select_all.test
    test/sql/t/select_pkey.test
    test/sql/t/select_secondary_key.test
    test/sql/t/show_create_table.test
    test/sql/t/show_table_status.test
    test/sql/t/update.test

  Modified: ha_mroonga.cc (+64 -9)
===================================================================
--- ha_mroonga.cc    2010-11-24 14:25:51 +0000 (76fd6bb)
+++ ha_mroonga.cc    2010-12-19 16:06:43 +0000 (a9e82c7)
@@ -92,6 +92,19 @@ grn_logger_info mrn_logger_info = {
   NULL
 };
 
+/* global hashes and mutexes */
+HASH mrn_allocated_thds;
+pthread_mutex_t mrn_allocated_thds_mutex;
+uchar *mrn_allocated_thds_get_key(
+  THD *thd,
+  size_t *length,
+  my_bool not_used __attribute__ ((unused))
+) {
+  DBUG_ENTER("mrn_allocated_thds_get_key");
+  *length = sizeof(THD *);
+  DBUG_RETURN((uchar*) thd);
+}
+
 /* system functions */
 
 static void mrn_create_status()
@@ -183,7 +196,7 @@ my_bool last_insert_grn_id_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
 int last_insert_grn_id(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
 {
   THD *thd = current_thd;
-  st_mrn_slot_data *slot_data = (st_mrn_slot_data*) thd_get_ha_data(thd, mrn_hton_ptr);
+  st_mrn_slot_data *slot_data = (st_mrn_slot_data*) *thd_ha_data(thd, mrn_hton_ptr);
   if (slot_data == NULL) {
     return 0;
   }
@@ -323,7 +336,7 @@ int mrn_init(void *p)
   ctx = grn_ctx_open(0);
 
   if (pthread_mutex_init(&mrn_log_mutex, NULL) != 0) {
-    goto err;
+    goto err_log_mutex_init;
   }
   grn_logger_info_set(ctx, &mrn_logger_info);
   if (!(mrn_logfile = fopen(mrn_logfile_name, "a"))) {
@@ -351,13 +364,29 @@ int mrn_init(void *p)
 
   // init lock
   if ((pthread_mutex_init(&db_mutex, NULL) != 0)) {
-    goto err;
+    goto err_db_mutex_init;
+  }
+  if ((pthread_mutex_init(&mrn_allocated_thds_mutex, NULL) != 0)) {
+    goto err_allocated_thds_mutex_init;
+  }
+  if(
+    hash_init(&mrn_allocated_thds, system_charset_info, 32, 0, 0,
+                   (hash_get_key) mrn_allocated_thds_get_key, 0, 0)
+  ) {
+    goto error_allocated_thds_hash_init;
   }
 
   grn_ctx_fin(ctx);
   return 0;
 
+error_allocated_thds_hash_init:
+  pthread_mutex_destroy(&mrn_allocated_thds_mutex);
+err_allocated_thds_mutex_init:
+  pthread_mutex_destroy(&db_mutex);
+err_db_mutex_init:
 err:
+  pthread_mutex_destroy(&mrn_log_mutex);
+err_log_mutex_init:
   grn_ctx_fin(ctx);
   grn_fin();
   return -1;
@@ -365,11 +394,26 @@ err:
 
 int mrn_deinit(void *p)
 {
+  THD *thd = current_thd, *tmp_thd;
   grn_ctx *ctx;
   ctx = grn_ctx_open(0);
 
   GRN_LOG(ctx, GRN_LOG_NOTICE, "%s deinit", MRN_PACKAGE_STRING);
 
+  if (thd && thd_sql_command(thd) == SQLCOM_UNINSTALL_PLUGIN) {
+    pthread_mutex_lock(&mrn_allocated_thds_mutex);
+    while ((tmp_thd = (THD *) hash_element(&mrn_allocated_thds, 0)))
+    {
+      void *slot_ptr = *thd_ha_data(tmp_thd, mrn_hton_ptr);
+      if (slot_ptr) free(slot_ptr);
+      *thd_ha_data(tmp_thd, mrn_hton_ptr) = (void *) NULL;
+      hash_delete(&mrn_allocated_thds, (uchar *) tmp_thd);
+    }
+    pthread_mutex_unlock(&mrn_allocated_thds_mutex);
+  }
+
+  hash_free(&mrn_allocated_thds);
+  pthread_mutex_destroy(&mrn_allocated_thds_mutex);
   pthread_mutex_destroy(&mrn_log_mutex);
   pthread_mutex_destroy(&db_mutex);
   grn_hash_close(ctx, mrn_hash);
@@ -412,11 +456,16 @@ void mrn_drop_db(handlerton *hton, char *path)
 
 int mrn_close_connection(handlerton *hton, THD *thd)
 {
-  void *p = thd_get_ha_data(thd, mrn_hton_ptr);
-  if (p) free(p);
-  thd_set_ha_data(thd, hton, NULL);
+  void *p = *thd_ha_data(thd, mrn_hton_ptr);
+  if (p) {
+    free(p);
+    *thd_ha_data(thd, mrn_hton_ptr) = (void *) NULL;
+    pthread_mutex_lock(&mrn_allocated_thds_mutex);
+    hash_delete(&mrn_allocated_thds, (uchar*) thd);
+    pthread_mutex_unlock(&mrn_allocated_thds_mutex);
+  }
   return 0;
-} 
+}
 
 bool mrn_flush_logs(handlerton *hton)
 {
@@ -1460,12 +1509,18 @@ int ha_mroonga::write_row(uchar *buf)
   grn_obj_unlink(ctx, &colbuf);
 
   // for UDF last_insert_grn_id()
-  st_mrn_slot_data *slot_data = (st_mrn_slot_data*) thd_get_ha_data(thd, mrn_hton_ptr);
+  st_mrn_slot_data *slot_data = (st_mrn_slot_data*) *thd_ha_data(thd, mrn_hton_ptr);
   if (slot_data == NULL) {
     slot_data = (st_mrn_slot_data*) malloc(sizeof(st_mrn_slot_data)); 
+    *thd_ha_data(thd, mrn_hton_ptr) = (void *) slot_data;
+    pthread_mutex_lock(&mrn_allocated_thds_mutex);
+    if (my_hash_insert(&mrn_allocated_thds, (uchar*) thd))
+    {
+      DBUG_RETURN(HA_ERR_OUT_OF_MEM);
+    }
+    pthread_mutex_unlock(&mrn_allocated_thds_mutex);
   }
   slot_data->last_insert_rid = row_id;
-  thd_set_ha_data(thd, mrn_hton_ptr, slot_data);
 
   DBUG_RETURN(0);
 }

  Copied: test/sql/include/groonga_deinit.inc (+6 -5) 82%
===================================================================
--- test/sql/t/flush_logs.test    2010-11-24 14:25:51 +0000 (3ccd4de)
+++ test/sql/include/groonga_deinit.inc    2010-12-19 16:06:43 +0000 (e61eb6d)
@@ -1,4 +1,4 @@
-# Copyright(C) 2010 Tetsuro IKEDA
+# Copyright(C) 2010 Kentoku SHIBA
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -14,7 +14,8 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
---source suite/groonga/include/groonga.inc
-
-flush logs;
-
+disable_query_log;
+set storage_engine=MyISAM;
+UNINSTALL PLUGIN groonga_stats;
+UNINSTALL PLUGIN groonga;
+enable_query_log;

  Modified: test/sql/t/binlog.test (+2 -0)
===================================================================
--- test/sql/t/binlog.test    2010-11-24 14:25:51 +0000 (13c7b88)
+++ test/sql/t/binlog.test    2010-12-19 16:06:43 +0000 (8ecff04)
@@ -49,3 +49,5 @@ insert into t1 values(2,100);
 commit;
 select * from t1;
 drop table t1;
+
+source suite/groonga/include/groonga_deinit.inc;

  Modified: test/sql/t/btree.test (+2 -0)
===================================================================
--- test/sql/t/btree.test    2010-11-24 14:25:51 +0000 (5d9b190)
+++ test/sql/t/btree.test    2010-12-19 16:06:43 +0000 (2b59b6f)
@@ -29,3 +29,5 @@ select * from t1;
 flush tables;
 select * from t1;
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/count_performance.test (+2 -0)
===================================================================
--- test/sql/t/count_performance.test    2010-11-24 14:25:51 +0000 (8d7fd87)
+++ test/sql/t/count_performance.test    2010-12-19 16:06:43 +0000 (9b2b23a)
@@ -56,3 +56,5 @@ show status like 'groonga_count_skip';
 select count(*) from t1 force index(idx1) where c2 between 20 and 40;
 show status like 'groonga_count_skip';
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/create_table.test (+2 -0)
===================================================================
--- test/sql/t/create_table.test    2010-11-24 14:25:51 +0000 (9d85289)
+++ test/sql/t/create_table.test    2010-12-19 16:06:43 +0000 (2a09fd3)
@@ -150,3 +150,5 @@ drop table t1;
 create table t1 (_id int, c1 int, key (_id));
 create table t1 (_id int, c1 int, key (_id) using hash);
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/delete.test (+2 -0)
===================================================================
--- test/sql/t/delete.test    2010-11-24 14:25:51 +0000 (9fce4b4)
+++ test/sql/t/delete.test    2010-12-19 16:06:43 +0000 (ef09677)
@@ -74,3 +74,5 @@ select * from t1;
 delete from t1 where _id = 2;
 select * from t1;
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/drop_database.test (+2 -0)
===================================================================
--- test/sql/t/drop_database.test    2010-11-24 14:25:51 +0000 (e3bcea9)
+++ test/sql/t/drop_database.test    2010-12-19 16:06:43 +0000 (131355e)
@@ -35,3 +35,5 @@ create table t1 (c1 int primary key, c2 varchar(255)) default charset utf8;
 create table t2 (c1 int primary key, c2 varchar(255)) default charset utf8;
 drop table t1, t2;
 drop database groonga;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/drop_table.test (+2 -0)
===================================================================
--- test/sql/t/drop_table.test    2010-11-24 14:25:51 +0000 (2225bd6)
+++ test/sql/t/drop_table.test    2010-12-19 16:06:43 +0000 (0792238)
@@ -27,3 +27,5 @@ create table t3 (c1 int primary key, c2 int, c3 int);
 drop table t1;
 drop table t2;
 drop table t3;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/flush_logs.test (+1 -0)
===================================================================
--- test/sql/t/flush_logs.test    2010-11-24 14:25:51 +0000 (3ccd4de)
+++ test/sql/t/flush_logs.test    2010-12-19 16:06:43 +0000 (1a441dc)
@@ -18,3 +18,4 @@
 
 flush logs;
 
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/fulltext.test (+2 -0)
===================================================================
--- test/sql/t/fulltext.test    2010-11-24 14:25:51 +0000 (5074849)
+++ test/sql/t/fulltext.test    2010-12-19 16:06:43 +0000 (851aa23)
@@ -97,3 +97,5 @@ select * from t1 where c2 = 10 and not match(c3) against("uu");
 select * from t1 where c2 >= 15 and not match(c3) against("uu");
 select * from t1 where c2 < 15 and not match(c3) against("uu");
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/hash.test (+2 -0)
===================================================================
--- test/sql/t/hash.test    2010-11-24 14:25:51 +0000 (de30b29)
+++ test/sql/t/hash.test    2010-12-19 16:06:43 +0000 (c6615ef)
@@ -63,3 +63,5 @@ select * from t1;
 select * from t1 where _id = 2;
 select * from t1 where _id = 20;
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/information_schema.test (+2 -0)
===================================================================
--- test/sql/t/information_schema.test    2010-11-24 14:25:51 +0000 (a2c0385)
+++ test/sql/t/information_schema.test    2010-12-19 16:06:43 +0000 (ae2a00d)
@@ -17,3 +17,5 @@
 --source suite/groonga/include/groonga.inc
 
 select count(*) from information_schema.plugins where plugin_name = "groonga";
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/insert.test (+2 -0)
===================================================================
--- test/sql/t/insert.test    2010-11-24 14:25:51 +0000 (c5d00b9)
+++ test/sql/t/insert.test    2010-12-19 16:06:43 +0000 (65f8650)
@@ -95,3 +95,5 @@ insert into t1 (c1,_score) values (5,2);
 insert into t1 (c1,_id,_score) values (6,1,2);
 select * from t1;
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/last_insert_grn_id.test (+2 -0)
===================================================================
--- test/sql/t/last_insert_grn_id.test    2010-11-24 14:25:51 +0000 (bc81833)
+++ test/sql/t/last_insert_grn_id.test    2010-12-19 16:06:43 +0000 (05daf9c)
@@ -44,3 +44,5 @@ select last_insert_grn_id(1);
 drop table t1;
 
 drop function last_insert_grn_id;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/log_level.test (+1 -0)
===================================================================
--- test/sql/t/log_level.test    2010-11-24 14:25:51 +0000 (4624216)
+++ test/sql/t/log_level.test    2010-12-19 16:06:43 +0000 (9e3c616)
@@ -54,3 +54,4 @@ set global groonga_log_level=dummy;
 --error 1229
 set session groonga_log_level=NOTICE;
 
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/order_limit_performance.test (+2 -0)
===================================================================
--- test/sql/t/order_limit_performance.test    2010-11-24 14:25:51 +0000 (57cd1c1)
+++ test/sql/t/order_limit_performance.test    2010-12-19 16:06:43 +0000 (d65a01b)
@@ -60,3 +60,5 @@ show status like 'groonga_fast_order_limit';
 select c3, _id from t1 where match(c3) against("ii") order by _id limit 1;
 show status like 'groonga_fast_order_limit';
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/select_all.test (+2 -0)
===================================================================
--- test/sql/t/select_all.test    2010-11-24 14:25:51 +0000 (86c2905)
+++ test/sql/t/select_all.test    2010-12-19 16:06:43 +0000 (64ecff3)
@@ -96,3 +96,5 @@ select * from t1;
 select * from t1 where _id < 3;
 select * from t1 where _id >= 3;
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/select_pkey.test (+2 -0)
===================================================================
--- test/sql/t/select_pkey.test    2010-11-24 14:25:51 +0000 (ca95369)
+++ test/sql/t/select_pkey.test    2010-12-19 16:06:43 +0000 (8b032b1)
@@ -36,3 +36,5 @@ select * from t1 where c1=5;
 select * from t1 where c1=6;
 
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/select_secondary_key.test (+2 -0)
===================================================================
--- test/sql/t/select_secondary_key.test    2010-11-24 14:25:51 +0000 (74ec231)
+++ test/sql/t/select_secondary_key.test    2010-12-19 16:06:43 +0000 (9916328)
@@ -47,3 +47,5 @@ select * from t1 force index(idx1) where c2 < 'e';
 select * from t1 force index(idx1) where c2 > 'e';
 select * from t1 force index(idx1) where c2 between 'c' and 'h';
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/show_create_table.test (+2 -0)
===================================================================
--- test/sql/t/show_create_table.test    2010-11-24 14:25:51 +0000 (ea1a49c)
+++ test/sql/t/show_create_table.test    2010-12-19 16:06:43 +0000 (743e840)
@@ -31,3 +31,5 @@ drop table t1;
 create table t1 (c1 int primary key, c2 varchar(100));
 show create table t1;
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/show_table_status.test (+2 -0)
===================================================================
--- test/sql/t/show_table_status.test    2010-11-24 14:25:51 +0000 (db3223d)
+++ test/sql/t/show_table_status.test    2010-12-19 16:06:43 +0000 (90ee984)
@@ -29,3 +29,5 @@ show table status;
 show table status like 't2';
 
 drop table t1,t2;
+
+--source suite/groonga/include/groonga_deinit.inc

  Modified: test/sql/t/update.test (+2 -0)
===================================================================
--- test/sql/t/update.test    2010-11-24 14:25:51 +0000 (f676950)
+++ test/sql/t/update.test    2010-12-19 16:06:43 +0000 (6abae11)
@@ -98,3 +98,5 @@ select * from t1;
 update t1 set c1 = 200 where _id = 2;
 select * from t1;
 drop table t1;
+
+--source suite/groonga/include/groonga_deinit.inc




Groonga-mysql-commit メーリングリストの案内
Back to archive index