[Groonga-commit] groonga/groonga at 4461999 [master] Add API to access lock timeout

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 6 13:07:18 JST 2014


Kouhei Sutou	2014-01-06 13:07:18 +0900 (Mon, 06 Jan 2014)

  New Revision: 4461999f6d3303341506377c9fdd5a9947ce9b51
  https://github.com/groonga/groonga/commit/4461999f6d3303341506377c9fdd5a9947ce9b51

  Message:
    Add API to access lock timeout
    
    New functions:
    
      * grn_get_lock_timeout()
      * grn_set_lock_timeout()

  Added files:
    doc/source/reference/api/global_configurations.txt
  Modified files:
    include/groonga.h
    lib/com.c
    lib/ctx.c
    lib/ctx.h
    lib/db.c
    lib/ii.c
    lib/store.c
    lib/token.c

  Added: doc/source/reference/api/global_configurations.txt (+42 -0) 100644
===================================================================
--- /dev/null
+++ doc/source/reference/api/global_configurations.txt    2014-01-06 13:07:18 +0900 (2140b5b)
@@ -0,0 +1,42 @@
+.. -*- rst -*-
+
+.. highlightlang:: none
+
+Global configurations
+=====================
+
+Summary
+-------
+
+Groonga has the global configurations. You can access them by API.
+
+
+Reference
+---------
+
+.. c:function:: int grn_get_lock_timeout(void)
+
+   Returns the lock timeout.
+
+   :c:type:`grn_ctx` acquires a lock for updating a shared value. If
+   other :c:type:`grn_ctx` is already updating the same value,
+   :c:type:`grn_ctx` that try to acquire a lock can't acquires a lock.
+   The :c:type:`grn_ctx` that can't acquires a lock waits 1
+   millisecond and try to acquire a lock again. The try is done
+   ``timeout`` times. If the :c:type:`grn_ctx` that can't acquires a
+   lock until ``timeout`` times, the tries are failed.
+
+   The default lock timeout is ``10000000``. It means that Groonga
+   doesn't report a lock failure until about 3 hours.  (1 * 10000000
+   [msec] = 10000 [sec] = 166.666... [min] = 2.777... [hour])
+
+   :return: The lock timeout.
+
+.. c:function:: grn_rc grn_set_lock_timeout(int timeout)
+
+   Sets the lock timeout.
+
+   See :c:function:`grn_get_lock_timeout` about lock timeout.
+
+   :param timeuot: The new lock timeout.
+   :return: ``GRN_SUCCESS``. It doesn't fail.

  Modified: include/groonga.h (+3 -0)
===================================================================
--- include/groonga.h    2014-01-06 12:35:56 +0900 (94ded74)
+++ include/groonga.h    2014-01-06 13:07:18 +0900 (fa8de78)
@@ -244,6 +244,9 @@ GRN_API grn_rc grn_ctx_set_match_escalation_threshold(grn_ctx *ctx, long long in
 GRN_API long long int grn_get_default_match_escalation_threshold(void);
 GRN_API grn_rc grn_set_default_match_escalation_threshold(long long int threshold);
 
+GRN_API int grn_get_lock_timeout(void);
+GRN_API grn_rc grn_set_lock_timeout(int timeout);
+
 /* cache */
 #define GRN_CACHE_DEFAULT_MAX_N_ENTRIES 100
 typedef struct _grn_cache grn_cache;

  Modified: lib/com.c (+2 -2)
===================================================================
--- lib/com.c    2014-01-06 12:35:56 +0900 (af2928c)
+++ lib/com.c    2014-01-06 13:07:18 +0900 (74327de)
@@ -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, GRN_LOCK_TIMEOUT)) {
+  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, GRN_LOCK_TIMEOUT)) {
+  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/ctx.c (+14 -0)
===================================================================
--- lib/ctx.c    2014-01-06 12:35:56 +0900 (96e342a)
+++ lib/ctx.c    2014-01-06 13:07:18 +0900 (411a3af)
@@ -54,6 +54,7 @@ grn_ctx grn_gctx = GRN_CTX_INITIALIZER(GRN_ENC_DEFAULT);
 int grn_pagesize;
 grn_critical_section grn_glock;
 uint32_t grn_gtick;
+int grn_lock_timeout = GRN_LOCK_TIMEOUT;
 
 #ifdef USE_UYIELD
 int grn_uyield_count = 0;
@@ -1362,6 +1363,19 @@ grn_set_default_match_escalation_threshold(long long int threshold)
   return grn_ctx_set_match_escalation_threshold(&grn_gctx, threshold);
 }
 
+int
+grn_get_lock_timeout(void)
+{
+  return grn_lock_timeout;
+}
+
+grn_rc
+grn_set_lock_timeout(int timeout)
+{
+  grn_lock_timeout = timeout;
+  return GRN_SUCCESS;
+}
+
 static int alloc_count = 0;
 
 grn_rc

  Modified: lib/ctx.h (+1 -0)
===================================================================
--- lib/ctx.h    2014-01-06 12:35:56 +0900 (572925c)
+++ lib/ctx.h    2014-01-06 13:07:18 +0900 (b4a3d1b)
@@ -383,6 +383,7 @@ GRN_VAR grn_ctx grn_gctx;
 extern int grn_pagesize;
 extern grn_critical_section grn_glock;
 extern uint32_t grn_gtick;
+extern int grn_lock_timeout;
 
 #define GRN_CTX_ALLOCATED                            (0x80)
 #define GRN_CTX_TEMPORARY_DISABLE_II_RESOLVE_SEL_AND (0x40)

  Modified: lib/db.c (+10 -10)
===================================================================
--- lib/db.c    2014-01-06 12:35:56 +0900 (38041fa)
+++ lib/db.c    2014-01-06 13:07:18 +0900 (13c9ab4)
@@ -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, GRN_LOCK_TIMEOUT)) {
+            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, GRN_LOCK_TIMEOUT)) {
+            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, GRN_LOCK_TIMEOUT)) {
+            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, GRN_LOCK_TIMEOUT)) {
+          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, GRN_LOCK_TIMEOUT))) {
+            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, GRN_LOCK_TIMEOUT))) {
+            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, GRN_LOCK_TIMEOUT))) {
+            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, GRN_LOCK_TIMEOUT))) {
+    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, GRN_LOCK_TIMEOUT)) {
+    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, GRN_LOCK_TIMEOUT)) {
+      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 12:35:56 +0900 (0fcfac5)
+++ lib/ii.c    2014-01-06 13:07:18 +0900 (05415cc)
@@ -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, GRN_LOCK_TIMEOUT)) { 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 12:35:56 +0900 (333659c)
+++ lib/store.c    2014-01-06 13:07:18 +0900 (82988ed)
@@ -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, GRN_LOCK_TIMEOUT)) {
+  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, GRN_LOCK_TIMEOUT)) { 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, GRN_LOCK_TIMEOUT)) {
+    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 12:35:56 +0900 (90689f3)
+++ lib/token.c    2014-01-06 13:07:18 +0900 (5d354fa)
@@ -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, GRN_LOCK_TIMEOUT)) {
+        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, GRN_LOCK_TIMEOUT)) {
+        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, GRN_LOCK_TIMEOUT)) {
+        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