[Groonga-commit] groonga/groonga at 1c94645 [master] Make lock timeout customizable

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 6 11:48:02 JST 2014


Kouhei Sutou	2014-01-06 11:48:02 +0900 (Mon, 06 Jan 2014)

  New Revision: 1c946450fa9eef925354bdb533d8520730ca2db2
  https://github.com/groonga/groonga/commit/1c946450fa9eef925354bdb533d8520730ca2db2

  Message:
    Make lock timeout customizable
    
    confiugre users: Use --with-lock-timeout
    
    CMake users: Use -DGRN_LOCK_TIMEOUT
    
    Redmine: fixes #109
    
    [groonga-dev,02017]
    
    Suggested by yoku. Thanks!!!

  Modified files:
    CMakeLists.txt
    configure.ac
    lib/com.c
    lib/db.c
    lib/ii.c
    lib/store.c
    lib/token.c

  Modified: CMakeLists.txt (+4 -0)
===================================================================
--- CMakeLists.txt    2014-01-06 11:30:43 +0900 (879198d)
+++ CMakeLists.txt    2014-01-06 11:48:02 +0900 (a76cd73)
@@ -67,6 +67,10 @@ set(GRN_STACK_SIZE
   1024
   CACHE STRING
   "DANGER!!! groonga stack size. Normarlly, you should not change this variable.")
+set(GRN_LOCK_TIMEOUT
+  10000000
+  CACHE STRING
+  "timeout to acquire a lock.")
 set(GRN_LOCK_WAIT_TIME_NANOSECOND
   1000000
   CACHE STRING

  Modified: configure.ac (+14 -0)
===================================================================
--- configure.ac    2014-01-06 11:30:43 +0900 (74746dd)
+++ configure.ac    2014-01-06 11:48:02 +0900 (5ed1be9)
@@ -441,6 +441,20 @@ AC_ARG_WITH(stack_size,
   GRN_STACK_SIZE="$withval")
 AC_DEFINE_UNQUOTED(GRN_STACK_SIZE, [$GRN_STACK_SIZE], [stack size])
 
+# lock timeout
+GRN_LOCK_TIMEOUT=10000000
+AC_ARG_WITH(lock_timeout,
+  [AS_HELP_STRING([--with-lock-timeout=N],
+    [This option specifies how many times Groonga tries to acquire a lock.
+     Each try waits --with-lock-wait-time nanoseconds to acquire a lock.
+     It means that Groonga gives up after
+     (--with-lock-wait-time * --with-lock-timeout) nanoseconds.
+     (default=$GRN_LOCK_TIMEOUT)])],
+  GRN_LOCK_TIMEOUT="$withval")
+AC_DEFINE_UNQUOTED(GRN_LOCK_TIMEOUT,
+                   [$GRN_LOCK_TIMEOUT],
+                   [lock timeout])
+
 # lock wait time
 GRN_LOCK_WAIT_TIME_NANOSECOND=1000000
 AC_ARG_WITH(lock_wait_time,

  Modified: lib/com.c (+2 -2)
===================================================================
--- lib/com.c    2014-01-06 11:30:43 +0900 (f942903)
+++ lib/com.c    2014-01-06 11:48:02 +0900 (af2928c)
@@ -1121,7 +1121,7 @@ grn_edges_fin(grn_ctx *ctx)
 grn_edge *
 grn_edges_add(grn_ctx *ctx, grn_com_addr *addr, int *added)
 {
-  if (grn_io_lock(ctx, grn_edges->io, 10000000)) {
+  if (grn_io_lock(ctx, grn_edges->io, GRN_LOCK_TIMEOUT)) {
     return NULL;
   } else {
     grn_edge *edge;
@@ -1136,7 +1136,7 @@ grn_edges_add(grn_ctx *ctx, grn_com_addr *addr, int *added)
 void
 grn_edges_delete(grn_ctx *ctx, grn_edge *edge)
 {
-  if (!grn_io_lock(ctx, grn_edges->io, 10000000)) {
+  if (!grn_io_lock(ctx, grn_edges->io, GRN_LOCK_TIMEOUT)) {
     grn_hash_delete_by_id(ctx, grn_edges, edge->id, NULL);
     grn_io_unlock(grn_edges->io);
   }

  Modified: lib/db.c (+10 -10)
===================================================================
--- lib/db.c    2014-01-06 11:30:43 +0900 (d8620e2)
+++ lib/db.c    2014-01-06 11:48:02 +0900 (38041fa)
@@ -1115,7 +1115,7 @@ grn_table_add(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key_si
         grn_pat *pat = (grn_pat *)table;
         WITH_NORMALIZE(pat, key, key_size, {
           if (pat->io && !(pat->io->flags & GRN_IO_TEMPORARY)) {
-            if (grn_io_lock(ctx, pat->io, 10000000)) {
+            if (grn_io_lock(ctx, pat->io, GRN_LOCK_TIMEOUT)) {
               id = GRN_ID_NIL;
             } else {
               id = grn_pat_add(ctx, pat, key, key_size, NULL, &added_);
@@ -1133,7 +1133,7 @@ grn_table_add(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key_si
         grn_dat *dat = (grn_dat *)table;
         WITH_NORMALIZE(dat, key, key_size, {
           if (dat->io && !(dat->io->flags & GRN_IO_TEMPORARY)) {
-            if (grn_io_lock(ctx, dat->io, 10000000)) {
+            if (grn_io_lock(ctx, dat->io, GRN_LOCK_TIMEOUT)) {
               id = GRN_ID_NIL;
             } else {
               id = grn_dat_add(ctx, dat, key, key_size, NULL, &added_);
@@ -1151,7 +1151,7 @@ grn_table_add(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key_si
         grn_hash *hash = (grn_hash *)table;
         WITH_NORMALIZE(hash, key, key_size, {
           if (hash->io && !(hash->io->flags & GRN_IO_TEMPORARY)) {
-            if (grn_io_lock(ctx, hash->io, 10000000)) {
+            if (grn_io_lock(ctx, hash->io, GRN_LOCK_TIMEOUT)) {
               id = GRN_ID_NIL;
             } else {
               id = grn_hash_add(ctx, hash, key, key_size, NULL, &added_);
@@ -1168,7 +1168,7 @@ grn_table_add(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key_si
       {
         grn_array *array = (grn_array *)table;
         if (array->io && !(array->io->flags & GRN_IO_TEMPORARY)) {
-          if (grn_io_lock(ctx, array->io, 10000000)) {
+          if (grn_io_lock(ctx, array->io, GRN_LOCK_TIMEOUT)) {
             id = GRN_ID_NIL;
           } else {
             id = grn_array_add(ctx, array, NULL);
@@ -1691,7 +1691,7 @@ grn_table_delete(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key
         WITH_NORMALIZE((grn_pat *)table, key, key_size, {
           grn_pat *pat = (grn_pat *)table;
           if (pat->io && !(pat->io->flags & GRN_IO_TEMPORARY)) {
-            if (!(rc = grn_io_lock(ctx, pat->io, 10000000))) {
+            if (!(rc = grn_io_lock(ctx, pat->io, GRN_LOCK_TIMEOUT))) {
               rc = grn_pat_delete(ctx, pat, key, key_size, NULL);
               grn_io_unlock(pat->io);
             }
@@ -1704,7 +1704,7 @@ grn_table_delete(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key
         WITH_NORMALIZE((grn_dat *)table, key, key_size, {
           grn_dat *dat = (grn_dat *)table;
           if (dat->io && !(dat->io->flags & GRN_IO_TEMPORARY)) {
-            if (!(rc = grn_io_lock(ctx, dat->io, 10000000))) {
+            if (!(rc = grn_io_lock(ctx, dat->io, GRN_LOCK_TIMEOUT))) {
               rc = grn_dat_delete(ctx, dat, key, key_size, NULL);
               grn_io_unlock(dat->io);
             }
@@ -1717,7 +1717,7 @@ grn_table_delete(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key
         WITH_NORMALIZE((grn_hash *)table, key, key_size, {
           grn_hash *hash = (grn_hash *)table;
           if (hash->io && !(hash->io->flags & GRN_IO_TEMPORARY)) {
-            if (!(rc = grn_io_lock(ctx, hash->io, 10000000))) {
+            if (!(rc = grn_io_lock(ctx, hash->io, GRN_LOCK_TIMEOUT))) {
               rc = grn_hash_delete(ctx, hash, key, key_size, NULL);
               grn_io_unlock(hash->io);
             }
@@ -1781,7 +1781,7 @@ grn_table_delete_by_id(grn_ctx *ctx, grn_obj *table, grn_id id)
   grn_io *io;
   GRN_API_ENTER;
   if ((io = grn_obj_io(table)) && !(io->flags & GRN_IO_TEMPORARY)) {
-    if (!(rc = grn_io_lock(ctx, io, 10000000))) {
+    if (!(rc = grn_io_lock(ctx, io, GRN_LOCK_TIMEOUT))) {
       rc = _grn_table_delete_by_id(ctx, table, id, NULL);
       grn_io_unlock(io);
     }
@@ -7177,7 +7177,7 @@ grn_obj_remove(grn_ctx *ctx, grn_obj *obj)
   GRN_API_ENTER;
   if (ctx->impl && ctx->impl->db && ctx->impl->db != obj) {
     grn_io *io = grn_obj_io(ctx->impl->db);
-    if (!grn_io_lock(ctx, io, 10000000)) {
+    if (!grn_io_lock(ctx, io, GRN_LOCK_TIMEOUT)) {
       _grn_obj_remove(ctx, obj);
       grn_io_unlock(io);
     }
@@ -7196,7 +7196,7 @@ grn_table_update_by_id(grn_ctx *ctx, grn_obj *table, grn_id id,
   if (table->header.type == GRN_TABLE_DAT_KEY) {
     grn_dat *dat = (grn_dat *)table;
     if (dat->io && !(dat->io->flags & GRN_IO_TEMPORARY)) {
-      if (grn_io_lock(ctx, dat->io, 10000000)) {
+      if (grn_io_lock(ctx, dat->io, GRN_LOCK_TIMEOUT)) {
         rc = ctx->rc;
       } else {
         rc = grn_dat_update_by_id(ctx, dat, id, dest_key, dest_key_size);

  Modified: lib/ii.c (+1 -1)
===================================================================
--- lib/ii.c    2014-01-06 11:30:43 +0900 (98a481d)
+++ lib/ii.c    2014-01-06 11:48:02 +0900 (0fcfac5)
@@ -4943,7 +4943,7 @@ grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, unsigned int section,
     GRN_RECORD_INIT(&buf, GRN_OBJ_VECTOR, grn_obj_id(ctx, ii->lexicon));
     post = &buf;
   }
-  if (grn_io_lock(ctx, ii->seg, 10000000)) { return ctx->rc; }
+  if (grn_io_lock(ctx, ii->seg, GRN_LOCK_TIMEOUT)) { return ctx->rc; }
   if (new) {
     unsigned char type = (ii->obj.header.domain == new->header.domain)
       ? GRN_UVECTOR

  Modified: lib/store.c (+3 -3)
===================================================================
--- lib/store.c    2014-01-06 11:30:43 +0900 (3ca5154)
+++ lib/store.c    2014-01-06 11:48:02 +0900 (333659c)
@@ -568,7 +568,7 @@ grn_ja_replace(grn_ctx *ctx, grn_ja *ja, grn_id id,
   lseg = id >> JA_W_EINFO_IN_A_SEGMENT;
   pos = id & JA_M_EINFO_IN_A_SEGMENT;
   pseg = &ja->header->esegs[lseg];
-  if (grn_io_lock(ctx, ja->io, 10000000)) {
+  if (grn_io_lock(ctx, ja->io, GRN_LOCK_TIMEOUT)) {
     return ctx->rc;
   }
   if (*pseg == JA_ESEG_VOID) {
@@ -631,7 +631,7 @@ grn_ja_alloc(grn_ctx *ctx, grn_ja *ja, grn_id id,
     return GRN_SUCCESS;
   }
   iw->tiny_p = 0;
-  if (grn_io_lock(ctx, ja->io, 10000000)) { return ctx->rc; }
+  if (grn_io_lock(ctx, ja->io, GRN_LOCK_TIMEOUT)) { return ctx->rc; }
   if (element_size + sizeof(grn_id) > JA_SEGMENT_SIZE) {
     int i, j, n = (element_size + JA_SEGMENT_SIZE - 1) >> GRN_JA_W_SEGMENT;
     for (i = 0, j = -1; i < JA_N_DSEGMENTS; i++) {
@@ -966,7 +966,7 @@ grn_ja_put_raw(grn_ctx *ctx, grn_ja *ja, grn_id id,
     return GRN_INVALID_ARGUMENT;
   }
   if ((rc = grn_ja_replace(ctx, ja, id, &einfo, cas))) {
-    if (!grn_io_lock(ctx, ja->io, 10000000)) {
+    if (!grn_io_lock(ctx, ja->io, GRN_LOCK_TIMEOUT)) {
       grn_ja_free(ctx, ja, &einfo);
       grn_io_unlock(ja->io);
     }

  Modified: lib/token.c (+3 -3)
===================================================================
--- lib/token.c    2014-01-06 11:30:43 +0900 (429a711)
+++ lib/token.c    2014-01-06 11:48:02 +0900 (90689f3)
@@ -609,7 +609,7 @@ grn_token_next(grn_ctx *ctx, grn_token *token)
     if (token->mode == GRN_TOKEN_ADD) {
       switch (table->header.type) {
       case GRN_TABLE_PAT_KEY :
-        if (grn_io_lock(ctx, ((grn_pat *)table)->io, 10000000)) {
+        if (grn_io_lock(ctx, ((grn_pat *)table)->io, GRN_LOCK_TIMEOUT)) {
           tid = GRN_ID_NIL;
         } else {
           tid = grn_pat_add(ctx, (grn_pat *)table, token->curr, token->curr_size,
@@ -618,7 +618,7 @@ grn_token_next(grn_ctx *ctx, grn_token *token)
         }
         break;
       case GRN_TABLE_DAT_KEY :
-        if (grn_io_lock(ctx, ((grn_dat *)table)->io, 10000000)) {
+        if (grn_io_lock(ctx, ((grn_dat *)table)->io, GRN_LOCK_TIMEOUT)) {
           tid = GRN_ID_NIL;
         } else {
           tid = grn_dat_add(ctx, (grn_dat *)table, token->curr, token->curr_size,
@@ -627,7 +627,7 @@ grn_token_next(grn_ctx *ctx, grn_token *token)
         }
         break;
       case GRN_TABLE_HASH_KEY :
-        if (grn_io_lock(ctx, ((grn_hash *)table)->io, 10000000)) {
+        if (grn_io_lock(ctx, ((grn_hash *)table)->io, GRN_LOCK_TIMEOUT)) {
           tid = GRN_ID_NIL;
         } else {
           tid = grn_hash_add(ctx, (grn_hash *)table, token->curr, token->curr_size,
-------------- next part --------------
HTML����������������������������...
Download 



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