[Groonga-commit] ranguba/rroonga at 71f30d9 [master] Add Groonga::Flushable#flush to bind grn_obj_flush_recursive()

Back to archive index

Masafumi Yokoyama null+****@clear*****
Fri Jul 10 15:22:53 JST 2015


Masafumi Yokoyama	2015-07-10 15:22:53 +0900 (Fri, 10 Jul 2015)

  New Revision: 71f30d9bbb9dd232f571bcb840b248f2367a3cd2
  https://github.com/ranguba/rroonga/commit/71f30d9bbb9dd232f571bcb840b248f2367a3cd2

  Message:
    Add Groonga::Flushable#flush to bind grn_obj_flush_recursive()
    
    GitHub #100, #101
    
    TODO:
    
      * Include the module from Groonga::Table, Groonga::Column and
        Groonga::Database.
      * Handle error.
      * Accept "recursive" option.

  Added files:
    ext/groonga/rb-grn-flushable.c
    test/test-flushable.rb
  Modified files:
    ext/groonga/rb-grn.h
    ext/groonga/rb-groonga.c

  Added: ext/groonga/rb-grn-flushable.c (+64 -0) 100644
===================================================================
--- /dev/null
+++ ext/groonga/rb-grn-flushable.c    2015-07-10 15:22:53 +0900 (59815f2)
@@ -0,0 +1,64 @@
+/* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+  Copyright (C) 2015  Masafumi Yokoyama <yokoyama �� clear-code.com>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "rb-grn.h"
+
+#define SELF(object) (RB_GRN_OBJECT(DATA_PTR(object)))
+
+/*
+ * Document-module: Groonga::Flushable
+ *
+ * It provides the ability to flash memory for an object.
+ */
+
+/*
+ * It flushes memory mapped data to disk.
+ *
+ * @return [void]
+ */
+static VALUE
+rb_grn_flushable_flush (VALUE self)
+{
+    grn_ctx *context = NULL;
+    grn_obj *object = NULL;
+
+    rb_grn_object_deconstruct(SELF(self), &object, &context,
+                              NULL, NULL, NULL, NULL);
+    if (!object) {
+        rb_raise(rb_eGrnClosed,
+                 "can't access already closed Groonga object: <%s>",
+                 rb_grn_inspect(self));
+    }
+
+    rb_grn_context_check(context, self);
+
+    grn_obj_flush_recursive(context, object);
+
+    return Qnil;
+}
+
+void
+rb_grn_init_flushable (VALUE mGrn)
+{
+    VALUE rb_mGrnFlushable;
+
+    rb_mGrnFlushable = rb_define_module_under(mGrn, "Flushable");
+
+    rb_define_method(rb_mGrnFlushable, "flush",
+                     rb_grn_flushable_flush, 0);
+}

  Modified: ext/groonga/rb-grn.h (+2 -0)
===================================================================
--- ext/groonga/rb-grn.h    2015-07-10 14:15:26 +0900 (363ffe6)
+++ ext/groonga/rb-grn.h    2015-07-10 15:22:53 +0900 (a1947f4)
@@ -300,6 +300,7 @@ RB_GRN_VAR VALUE rb_cGrnRecordExpressionBuilder;
 RB_GRN_VAR VALUE rb_cGrnColumnExpressionBuilder;
 RB_GRN_VAR VALUE rb_cGrnPlugin;
 RB_GRN_VAR VALUE rb_cGrnNormalizer;
+RB_GRN_VAR VALUE rb_cGrnFlushable;
 
 void           rb_grn_init_utils                    (VALUE mGrn);
 void           rb_grn_init_exception                (VALUE mGrn);
@@ -350,6 +351,7 @@ void           rb_grn_init_query_logger             (VALUE mGrn);
 void           rb_grn_init_snippet                  (VALUE mGrn);
 void           rb_grn_init_plugin                   (VALUE mGrn);
 void           rb_grn_init_normalizer               (VALUE mGrn);
+void           rb_grn_init_flushable                (VALUE mGrn);
 
 VALUE          rb_grn_rc_to_exception               (grn_rc rc);
 const char    *rb_grn_rc_to_message                 (grn_rc rc);

  Modified: ext/groonga/rb-groonga.c (+1 -0)
===================================================================
--- ext/groonga/rb-groonga.c    2015-07-10 14:15:26 +0900 (37cfee2)
+++ ext/groonga/rb-groonga.c    2015-07-10 15:22:53 +0900 (c40793a)
@@ -189,4 +189,5 @@ Init_groonga (void)
     rb_grn_init_snippet(mGrn);
     rb_grn_init_plugin(mGrn);
     rb_grn_init_normalizer(mGrn);
+    rb_grn_init_flushable(mGrn);
 }

  Added: test/test-flushable.rb (+26 -0) 100644
===================================================================
--- /dev/null
+++ test/test-flushable.rb    2015-07-10 15:22:53 +0900 (d066060)
@@ -0,0 +1,26 @@
+# Copyright (C) 2015  Masafumi Yokoyama <yokoyama �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+class FlushableTest < Test::Unit::TestCase
+  include GroongaTestUtils
+
+  setup :setup_database
+
+  def test_flush
+    table = Groonga::Hash.create
+    table.extend(Groonga::Flushable)
+    assert_nil(table.flush)
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index