[Groonga-commit] groonga/groonga [master] fixed trying to lock temporary table in grn_table_add

Back to archive index

null+****@clear***** null+****@clear*****
2011年 11月 18日 (金) 20:14:44 JST


Daijiro MORI	2011-11-18 11:14:44 +0000 (Fri, 18 Nov 2011)

  New Revision: 75bbe511d192e72b9e97a030fc06766a6c31a3ac

  Log:
    fixed trying to lock temporary table in grn_table_add

  Modified files:
    lib/db.c

  Modified: lib/db.c (+36 -11)
===================================================================
--- lib/db.c    2011-11-18 09:42:33 +0000 (a4c8686)
+++ lib/db.c    2011-11-18 11:14:44 +0000 (f09f3e7)
@@ -896,11 +896,15 @@ grn_table_add(grn_ctx *ctx, grn_obj *table, const void *key, unsigned key_size,
       {
         grn_pat *pat = (grn_pat *)table;
         WITH_NORMALIZE(pat, key, key_size, {
-          if (grn_io_lock(ctx, pat->io, 10000000)) {
-            id = GRN_ID_NIL;
+          if (pat->io && !(pat->io->flags & GRN_IO_TEMPORARY)) {
+            if (grn_io_lock(ctx, pat->io, 10000000)) {
+              id = GRN_ID_NIL;
+            } else {
+              id = grn_pat_add(ctx, pat, key, key_size, NULL, &added_);
+              grn_io_unlock(pat->io);
+            }
           } else {
             id = grn_pat_add(ctx, pat, key, key_size, NULL, &added_);
-            grn_io_unlock(pat->io);
           }
         });
         if (added) { *added = added_; }
@@ -910,11 +914,15 @@ grn_table_add(grn_ctx *ctx, grn_obj *table, const void *key, unsigned key_size,
       {
         grn_dat *dat = (grn_dat *)table;
         WITH_NORMALIZE(dat, key, key_size, {
-          if (grn_io_lock(ctx, dat->io, 10000000)) {
-            id = GRN_ID_NIL;
+          if (dat->io && !(dat->io->flags & GRN_IO_TEMPORARY)) {
+            if (grn_io_lock(ctx, dat->io, 10000000)) {
+              id = GRN_ID_NIL;
+            } else {
+              id = grn_dat_add(ctx, dat, key, key_size, NULL, &added_);
+              grn_io_unlock(dat->io);
+            }
           } else {
             id = grn_dat_add(ctx, dat, key, key_size, NULL, &added_);
-            grn_io_unlock(dat->io);
           }
         });
         if (added) { *added = added_; }
@@ -924,19 +932,36 @@ grn_table_add(grn_ctx *ctx, grn_obj *table, const void *key, unsigned key_size,
       {
         grn_hash *hash = (grn_hash *)table;
         WITH_NORMALIZE(hash, key, key_size, {
-          if (grn_io_lock(ctx, hash->io, 10000000)) {
-            id = GRN_ID_NIL;
+          if (hash->io && !(hash->io->flags & GRN_IO_TEMPORARY)) {
+            if (grn_io_lock(ctx, hash->io, 10000000)) {
+              id = GRN_ID_NIL;
+            } else {
+              id = grn_hash_add(ctx, hash, key, key_size, NULL, &added_);
+              grn_io_unlock(hash->io);
+            }
           } else {
             id = grn_hash_add(ctx, hash, key, key_size, NULL, &added_);
-            grn_io_unlock(hash->io);
           }
         });
         if (added) { *added = added_; }
       }
       break;
     case GRN_TABLE_NO_KEY :
-      id = grn_array_add(ctx, (grn_array *)table, NULL);
-      if (added) { *added = id ? 1 : 0; }
+      {
+        grn_array *array = (grn_array *)table;
+        if (array->io && !(array->io->flags & GRN_IO_TEMPORARY)) {
+          if (grn_io_lock(ctx, array->io, 10000000)) {
+            id = GRN_ID_NIL;
+          } else {
+            id = grn_array_add(ctx, array, NULL);
+            grn_io_unlock(array->io);
+          }
+        } else {
+          id = grn_array_add(ctx, array, NULL);
+        }
+        added_ = id ? 1 : 0;
+        if (added) { *added = added_; }
+      }
       break;
     }
     if (added_) {




Groonga-commit メーリングリストの案内
Back to archive index