[Groonga-commit] groonga/groonga at 8c73dda [master] grn_obj_is_corrupt: support double array trie

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jun 14 17:05:14 JST 2017


Kouhei Sutou	2017-06-14 17:05:14 +0900 (Wed, 14 Jun 2017)

  New Revision: 8c73ddac34edb1b5d43567bb835361d1aed6260c
  https://github.com/groonga/groonga/commit/8c73ddac34edb1b5d43567bb835361d1aed6260c

  Message:
    grn_obj_is_corrupt: support double array trie

  Modified files:
    lib/dat.cpp
    lib/db.c
    lib/grn_dat.h
    test/command_line/suite/grndb/test_check.rb

  Modified: lib/dat.cpp (+33 -0)
===================================================================
--- lib/dat.cpp    2017-06-14 16:43:22 +0900 (dbb20a7)
+++ lib/dat.cpp    2017-06-14 17:05:14 +0900 (baca2b1)
@@ -1266,4 +1266,37 @@ grn_dat_clear_dirty(grn_ctx *ctx, grn_dat *dat)
   return rc;
 }
 
+grn_bool
+grn_dat_is_corrupt(grn_ctx *ctx, grn_dat *dat)
+{
+  if (!dat->io) {
+    return GRN_FALSE;
+  }
+
+  {
+    CriticalSection critical_section(&dat->lock);
+
+    if (grn_io_is_corrupt(ctx, dat->io)) {
+      return GRN_TRUE;
+    }
+
+    if (dat->header->file_id == 0) {
+      return GRN_FALSE;
+    }
+
+    char trie_path[PATH_MAX];
+    grn_dat_generate_trie_path(grn_io_path(dat->io),
+                               trie_path,
+                               dat->header->file_id);
+    struct stat stat;
+    if (::stat(trie_path, &stat) != 0) {
+      SERR("[dat][corrupt] used path doesn't exist: <%s>",
+           trie_path);
+      return GRN_TRUE;
+    }
+  }
+
+  return GRN_FALSE;
+}
+
 }  // extern "C"

  Modified: lib/db.c (+4 -0)
===================================================================
--- lib/db.c    2017-06-14 16:43:22 +0900 (448672b)
+++ lib/db.c    2017-06-14 17:05:14 +0900 (74798e4)
@@ -763,7 +763,11 @@ grn_obj_is_corrupt(grn_ctx *ctx, grn_obj *obj)
     break;
   case GRN_TABLE_HASH_KEY :
   case GRN_TABLE_PAT_KEY :
+    is_corrupt = grn_io_is_corrupt(ctx, grn_obj_io(obj));
+    break;
   case GRN_TABLE_DAT_KEY :
+    is_corrupt = grn_dat_is_corrupt(ctx, (grn_dat *)obj);
+    break;
   case GRN_COLUMN_FIX_SIZE :
   case GRN_COLUMN_VAR_SIZE :
     is_corrupt = grn_io_is_corrupt(ctx, grn_obj_io(obj));

  Modified: lib/grn_dat.h (+2 -0)
===================================================================
--- lib/grn_dat.h    2017-06-14 16:43:22 +0900 (02ce093)
+++ lib/grn_dat.h    2017-06-14 17:05:14 +0900 (a24c310)
@@ -86,6 +86,8 @@ grn_bool grn_dat_is_dirty(grn_ctx *ctx, grn_dat *dat);
 grn_rc grn_dat_clean(grn_ctx *ctx, grn_dat *dat);
 grn_rc grn_dat_clear_dirty(grn_ctx *ctx, grn_dat *dat);
 
+grn_bool grn_dat_is_corrupt(grn_ctx *ctx, grn_dat *dat);
+
 #ifdef __cplusplus
 }
 #endif

  Modified: test/command_line/suite/grndb/test_check.rb (+17 -0)
===================================================================
--- test/command_line/suite/grndb/test_check.rb    2017-06-14 16:43:22 +0900 (1db5035)
+++ test/command_line/suite/grndb/test_check.rb    2017-06-14 17:05:14 +0900 (54e21f1)
@@ -149,6 +149,23 @@ load --table Users
     MESSAGE
   end
 
+  def test_corrupt_double_array_table
+    groonga("table_create", "Users", "TABLE_DAT_KEY", "ShortText")
+    groonga do |external_process|
+      external_process.input.puts("load --table Users")
+      external_process.input.puts("[")
+      external_process.input.puts("{\"_key\": \"x\"}")
+      external_process.input.puts("]")
+    end
+    FileUtils.rm("#{@database_path}.0000100.001")
+    error = assert_raise(CommandRunner::Error) do
+      grndb("check")
+    end
+    assert_equal(<<-MESSAGE, error.error_output)
+[Users] Table is corrupt. (1) Truncate the table (truncate Users or '#{grndb_path} recover --force-truncate #{@database_path}') and (2) load data again.
+    MESSAGE
+  end
+
   def test_corrupt_data_column
     groonga("table_create", "Data", "TABLE_NO_KEY")
     groonga("column_create", "Data", "text", "COLUMN_SCALAR", "Text")
-------------- next part --------------
HTML����������������������������...
Download 



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