[Groonga-commit] groonga/groonga at 56b4b4b [master] experimental: add an option whether skip the same value put for ja or not

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Oct 29 17:56:00 JST 2013


Kouhei Sutou	2013-10-29 17:56:00 +0900 (Tue, 29 Oct 2013)

  New Revision: 56b4b4b95a532f0382eb2cdd1e4dd5d0ab514acc
  https://github.com/groonga/groonga/commit/56b4b4b95a532f0382eb2cdd1e4dd5d0ab514acc

  Message:
    experimental: add an option whether skip the same value put for ja or not
    
    You can enable it by defining GRN_JA_SKIP_SAME_VALUE_PUT=yes
    environment variable. It may increase ja file size. We need to
    try it on many cases to determine better behavior.

  Modified files:
    lib/ctx.c
    lib/store.c
    lib/store.h

  Modified: lib/ctx.c (+15 -0)
===================================================================
--- lib/ctx.c    2013-10-29 13:57:41 +0900 (781f81b)
+++ lib/ctx.c    2013-10-29 17:56:00 +0900 (bac651a)
@@ -1217,6 +1217,20 @@ check_overcommit_memory(grn_ctx *ctx)
   fclose(file);
 }
 
+static void
+grn_ja_skip_same_value_put_init(grn_ctx *ctx)
+{
+  const char *grn_ja_skip_same_value_put_env;
+
+  grn_ja_skip_same_value_put_env = getenv("GRN_JA_SKIP_SAME_VALUE_PUT");
+  if (grn_ja_skip_same_value_put_env &&
+      strcmp(grn_ja_skip_same_value_put_env, "yes") == 0) {
+    grn_ja_skip_same_value_put = GRN_TRUE;
+  } else {
+    grn_ja_skip_same_value_put = GRN_FALSE;
+  }
+}
+
 grn_rc
 grn_init(void)
 {
@@ -1311,6 +1325,7 @@ grn_init(void)
   grn_cache_init();
   GRN_LOG(ctx, GRN_LOG_NOTICE, "grn_init");
   check_overcommit_memory(ctx);
+  grn_ja_skip_same_value_put_init(ctx);
   return rc;
 }
 

  Modified: lib/store.c (+19 -0)
===================================================================
--- lib/store.c    2013-10-29 13:57:41 +0900 (2e09598)
+++ lib/store.c    2013-10-29 17:56:00 +0900 (72c7b51)
@@ -800,6 +800,25 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
   int64_t buf;
   grn_io_win iw;
   grn_ja_einfo einfo;
+
+  if (grn_ja_skip_same_value_put &&
+      (flags & GRN_OBJ_SET_MASK) == GRN_OBJ_SET &&
+      value_len > 0) {
+    grn_io_win jw;
+    uint32_t old_len;
+    void *old_value;
+    grn_bool same_value = GRN_FALSE;
+
+    old_value = grn_ja_ref(ctx, ja, id, &jw, &old_len);
+    if (value_len == old_len && memcmp(value, old_value, value_len) == 0) {
+      same_value = GRN_TRUE;
+    }
+    grn_ja_unref(ctx, &jw);
+    if (same_value) {
+      return GRN_SUCCESS;
+    }
+  }
+
   switch (flags & GRN_OBJ_SET_MASK) {
   case GRN_OBJ_APPEND :
     if (value_len) {

  Modified: lib/store.h (+2 -0)
===================================================================
--- lib/store.h    2013-10-29 13:57:41 +0900 (87a440a)
+++ lib/store.h    2013-10-29 17:56:00 +0900 (719fe77)
@@ -82,6 +82,8 @@ void *grn_ra_ref_cache(grn_ctx *ctx, grn_ra *ra, grn_id id, grn_ra_cache *cache)
 
 /**** variable sized elements ****/
 
+extern grn_bool grn_ja_skip_same_value_put;
+
 typedef struct _grn_ja grn_ja;
 
 struct _grn_ja {
-------------- next part --------------
HTML����������������������������...
Download 



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