[Groonga-commit] groonga/groonga at 7977632 [master] load: add "lock_table" option

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Aug 27 18:11:17 JST 2018


Kouhei Sutou	2018-08-27 18:11:17 +0900 (Mon, 27 Aug 2018)

  Revision: 79776322e4982588979315cf91c7969bea8f6b75
  https://github.com/groonga/groonga/commit/79776322e4982588979315cf91c7969bea8f6b75

  Message:
    load: add "lock_table" option
    
    If "--lock_table yes" is specified, "load" locks the target table
    while updating columns and applying "--each". This option avoids
    "load" and "delete" conflicts but it'll reduce load performance.

  Added files:
    test/command/suite/load/lock_table/brace.expected
    test/command/suite/load/lock_table/brace.test
    test/command/suite/load/lock_table/bracket.expected
    test/command/suite/load/lock_table/bracket.test
  Modified files:
    lib/grn_ctx_impl.h
    lib/grn_load.h
    lib/load.c
    lib/proc.c

  Modified: lib/grn_ctx_impl.h (+2 -0)
===================================================================
--- lib/grn_ctx_impl.h    2018-08-27 17:36:18 +0900 (425b1bb81)
+++ lib/grn_ctx_impl.h    2018-08-27 18:11:17 +0900 (ffd2199eb)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2018 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou �� 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
@@ -92,6 +93,7 @@ typedef struct {
   char errbuf[GRN_CTX_MSGSIZE];
   grn_bool output_ids;
   grn_bool output_errors;
+  grn_bool lock_table;
 } grn_loader;
 
 #define GRN_CTX_N_SEGMENTS 512

  Modified: lib/grn_load.h (+2 -0)
===================================================================
--- lib/grn_load.h    2018-08-27 17:36:18 +0900 (5b34d2279)
+++ lib/grn_load.h    2018-08-27 18:11:17 +0900 (5e161d76c)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2017 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou �� 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
@@ -36,6 +37,7 @@ typedef struct grn_load_input_ {
   grn_raw_string each;
   grn_bool output_ids;
   grn_bool output_errors;
+  grn_bool lock_table;
   uint32_t emit_level;
 } grn_load_input;
 

  Modified: lib/load.c (+26 -5)
===================================================================
--- lib/load.c    2018-08-27 17:36:18 +0900 (9c8a898f5)
+++ lib/load.c    2018-08-27 18:11:17 +0900 (d1df75b53)
@@ -17,9 +17,10 @@
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-#include "grn_load.h"
 #include "grn_ctx_impl.h"
 #include "grn_db.h"
+#include "grn_load.h"
+#include "grn_obj.h"
 #include "grn_util.h"
 
 static void
@@ -531,8 +532,17 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
     goto exit;
   }
 
-  bracket_close_set_values(ctx, loader, id, key, value, nvalues);
-  grn_loader_apply_each(ctx, loader, id);
+  if (loader->lock_table) {
+    GRN_TABLE_LOCK_BEGIN(ctx, loader->table) {
+      if (grn_table_at(ctx, loader->table, id) == id) {
+        bracket_close_set_values(ctx, loader, id, key, value, nvalues);
+        grn_loader_apply_each(ctx, loader, id);
+      }
+    } GRN_TABLE_LOCK_END(ctx, table);
+  } else {
+    bracket_close_set_values(ctx, loader, id, key, value, nvalues);
+    grn_loader_apply_each(ctx, loader, id);
+  }
   loader->nrecords++;
 exit:
   if (is_record_load) {
@@ -722,8 +732,17 @@ brace_close(grn_ctx *ctx, grn_loader *loader)
     goto exit;
   }
 
-  brace_close_set_values(ctx, loader, id, key, value_begin, value_end);
-  grn_loader_apply_each(ctx, loader, id);
+  if (loader->lock_table) {
+    GRN_TABLE_LOCK_BEGIN(ctx, loader->table) {
+      if (grn_table_at(ctx, loader->table, id) == id) {
+        brace_close_set_values(ctx, loader, id, key, value_begin, value_end);
+        grn_loader_apply_each(ctx, loader, id);
+      }
+    } GRN_TABLE_LOCK_END(ctx, loader->table);
+  } else {
+    brace_close_set_values(ctx, loader, id, key, value_begin, value_end);
+    grn_loader_apply_each(ctx, loader, id);
+  }
   loader->nrecords++;
 exit:
   if (ctx->rc != GRN_SUCCESS) {
@@ -1246,6 +1265,7 @@ grn_load_internal(grn_ctx *ctx, grn_load_input *input)
     }
     loader->output_ids = input->output_ids;
     loader->output_errors = input->output_errors;
+    loader->lock_table = input->lock_table;
   } else {
     if (!loader->table) {
       ERR(GRN_INVALID_ARGUMENT, "mandatory \"table\" parameter is absent");
@@ -1297,6 +1317,7 @@ grn_load(grn_ctx *ctx, grn_content_type input_type,
     input.each.length = each_len;
     input.output_ids = GRN_FALSE;
     input.output_errors = GRN_FALSE;
+    input.lock_table = GRN_FALSE;
     input.emit_level = 1;
     grn_load_internal(ctx, &input);
   }

  Modified: lib/proc.c (+6 -1)
===================================================================
--- lib/proc.c    2018-08-27 17:36:18 +0900 (0a4ac0150)
+++ lib/proc.c    2018-08-27 18:11:17 +0900 (c3a07ad79)
@@ -178,6 +178,10 @@ proc_load(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
                                                      user_data,
                                                      "output_errors", -1,
                                                      GRN_FALSE);
+  input.lock_table = grn_plugin_proc_get_var_bool(ctx,
+                                                  user_data,
+                                                  "lock_table", -1,
+                                                  GRN_FALSE);
   input.emit_level = 1;
 
   grn_load_internal(ctx, &input);
@@ -4063,7 +4067,8 @@ grn_db_init_builtin_commands(grn_ctx *ctx)
   DEF_VAR(vars[5], "each");
   DEF_VAR(vars[6], "output_ids");
   DEF_VAR(vars[7], "output_errors");
-  DEF_COMMAND("load", proc_load, 8, vars);
+  DEF_VAR(vars[8], "lock_table");
+  DEF_COMMAND("load", proc_load, 9, vars);
 
   DEF_COMMAND("status", proc_status, 0, vars);
 

  Added: test/command/suite/load/lock_table/brace.expected (+43 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/load/lock_table/brace.expected    2018-08-27 18:11:17 +0900 (9fd35ffc5)
@@ -0,0 +1,43 @@
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos content COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+load --table Memos --lock_table yes
+[
+{"_key": "Groonga", "content": "Fast full text search engine!"}
+]
+[[0,0.0,0.0],1]
+select Memos
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "content",
+          "Text"
+        ]
+      ],
+      [
+        1,
+        "Groonga",
+        "Fast full text search engine!"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/load/lock_table/brace.test (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/load/lock_table/brace.test    2018-08-27 18:11:17 +0900 (452c0a1da)
@@ -0,0 +1,11 @@
+# This test case does test nothing about locked...
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+load --table Memos --lock_table yes
+[
+{"_key": "Groonga", "content": "Fast full text search engine!"}
+]
+
+select Memos

  Added: test/command/suite/load/lock_table/bracket.expected (+44 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/load/lock_table/bracket.expected    2018-08-27 18:11:17 +0900 (78bf6f278)
@@ -0,0 +1,44 @@
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos content COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+load --table Memos --lock_table yes
+[
+["_key", "content"],
+["Groonga", "Fast full text search engine!"]
+]
+[[0,0.0,0.0],1]
+select Memos
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "content",
+          "Text"
+        ]
+      ],
+      [
+        1,
+        "Groonga",
+        "Fast full text search engine!"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/load/lock_table/bracket.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/load/lock_table/bracket.test    2018-08-27 18:11:17 +0900 (21bb51d94)
@@ -0,0 +1,12 @@
+# This test case does test nothing about locked...
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+load --table Memos --lock_table yes
+[
+["_key", "content"],
+["Groonga", "Fast full text search engine!"]
+]
+
+select Memos
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180827/b85d9071/attachment-0001.htm 



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