[Groonga-mysql-commit] mroonga/mroonga [master] added support for "flush logs".

Back to archive index

null+****@clear***** null+****@clear*****
2010年 11月 23日 (火) 11:40:13 JST


Tetsuro IKEDA	2010-11-23 02:40:13 +0000 (Tue, 23 Nov 2010)

  New Revision: 8fba656b6e97498f9d164e19d4675a55246dde55

  Log:
    added support for "flush logs".

  Added files:
    test/sql/r/flush_logs.result
    test/sql/t/flush_logs.test
  Modified files:
    ha_mroonga.cc
    ha_mroonga.h

  Modified: ha_mroonga.cc (+20 -0)
===================================================================
--- ha_mroonga.cc    2010-11-22 00:49:16 +0000 (e06ad88)
+++ ha_mroonga.cc    2010-11-23 02:40:13 +0000 (1e9dfe7)
@@ -50,6 +50,7 @@ extern "C" {
 grn_obj *mrn_db;
 grn_hash *mrn_hash;
 pthread_mutex_t db_mutex;
+pthread_mutex_t mrn_log_mutex;
 _ft_vft mrn_ft_vft = {
   NULL, // mrn_ft_read_next
   mrn_ft_find_relevance,
@@ -73,9 +74,11 @@ void mrn_logger_func(int level, const char *time, const char *title,
 {
   const char slev[] = " EACewnid-";
   if (mrn_logfile_opened) {
+    pthread_mutex_lock(&mrn_log_mutex);
     fprintf(mrn_logfile, "%s|%c|%08x|%s\n", time,
             *(slev + level), (uint)pthread_self(), msg);
     fflush(mrn_logfile);
+    pthread_mutex_unlock(&mrn_log_mutex);
   }
 }
 
@@ -267,6 +270,7 @@ int mrn_init(void *p)
   hton->flags = 0;
   hton->drop_database = mrn_drop_db;
   hton->close_connection = mrn_close_connection;
+  hton->flush_logs = mrn_flush_logs;
   mrn_hton_ptr = hton;
 
   // init groonga
@@ -276,6 +280,9 @@ int mrn_init(void *p)
 
   ctx = grn_ctx_open(0);
 
+  if (pthread_mutex_init(&mrn_log_mutex, NULL) != 0) {
+    goto err;
+  }
   grn_logger_info_set(ctx, &mrn_logger_info);
   if (!(mrn_logfile = fopen(mrn_logfile_name, "a"))) {
     goto err;
@@ -319,6 +326,7 @@ int mrn_deinit(void *p)
 
   GRN_LOG(ctx, GRN_LOG_NOTICE, "%s deinit", MRN_PACKAGE_STRING);
 
+  pthread_mutex_destroy(&mrn_log_mutex);
   pthread_mutex_destroy(&db_mutex);
   grn_hash_close(ctx, mrn_hash);
   grn_obj_unlink(ctx, mrn_db);
@@ -366,6 +374,18 @@ int mrn_close_connection(handlerton *hton, THD *thd)
   return 0;
 } 
 
+bool mrn_flush_logs(handlerton *hton)
+{
+  bool result = 0;
+  if (mrn_logfile_opened) {
+    pthread_mutex_lock(&mrn_log_mutex);
+    fclose(mrn_logfile);
+    mrn_logfile = fopen(mrn_logfile_name, "a");
+    pthread_mutex_unlock(&mrn_log_mutex);
+  }
+  return result;
+}
+
 grn_builtin_type mrn_get_type(grn_ctx *ctx, int mysql_field_type)
 {
   switch (mysql_field_type) {

  Modified: ha_mroonga.h (+1 -0)
===================================================================
--- ha_mroonga.h    2010-11-22 00:49:16 +0000 (daa00ee)
+++ ha_mroonga.h    2010-11-23 02:40:13 +0000 (249cb6e)
@@ -56,6 +56,7 @@ int mrn_deinit(void *hton);
 handler *mrn_handler_create(handlerton *hton, TABLE_SHARE *share, MEM_ROOT *root);
 void mrn_drop_db(handlerton *hton, char *path);
 int mrn_close_connection(handlerton *hton, THD *thd);
+bool mrn_flush_logs(handlerton *hton); 
 float mrn_ft_find_relevance(FT_INFO *handler, uchar *record, uint length);
 float mrn_ft_get_relevance(FT_INFO *handler);
 void mrn_ft_close_search(FT_INFO *handler);

  Added: test/sql/r/flush_logs.result (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/r/flush_logs.result    2010-11-23 02:40:13 +0000 (449f643)
@@ -0,0 +1 @@
+flush logs;

  Added: test/sql/t/flush_logs.test (+20 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/t/flush_logs.test    2010-11-23 02:40:13 +0000 (3ccd4de)
@@ -0,0 +1,20 @@
+# Copyright(C) 2010 Tetsuro IKEDA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# 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;
+




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