[Groonga-commit] groonga/groonga at 16e0d50 [master] Add grn_obj_is_corrupt()

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jun 14 16:38:59 JST 2017


Kouhei Sutou	2017-06-14 16:38:59 +0900 (Wed, 14 Jun 2017)

  New Revision: 16e0d506498def03407f045a98a944102ff102b1
  https://github.com/groonga/groonga/commit/16e0d506498def03407f045a98a944102ff102b1

  Message:
    Add grn_obj_is_corrupt()

  Modified files:
    include/groonga/obj.h
    lib/db.c

  Modified: include/groonga/obj.h (+2 -0)
===================================================================
--- include/groonga/obj.h    2017-06-14 16:38:24 +0900 (7b14ce6)
+++ include/groonga/obj.h    2017-06-14 16:38:59 +0900 (cfcb191)
@@ -73,6 +73,8 @@ GRN_API grn_bool grn_obj_name_is_column(grn_ctx *ctx,
                                         const char *name,
                                         int name_len);
 
+GRN_API grn_bool grn_obj_is_corrupt(grn_ctx *ctx, grn_obj *obj);
+
 #ifdef __cplusplus
 }
 #endif

  Modified: lib/db.c (+42 -0)
===================================================================
--- lib/db.c    2017-06-14 16:38:24 +0900 (51e321d)
+++ lib/db.c    2017-06-14 16:38:59 +0900 (448672b)
@@ -739,6 +739,48 @@ grn_db_touch(grn_ctx *ctx, grn_obj *s)
   grn_obj_touch(ctx, s, NULL);
 }
 
+grn_bool
+grn_obj_is_corrupt(grn_ctx *ctx, grn_obj *obj)
+{
+  grn_bool is_corrupt = GRN_FALSE;
+
+  GRN_API_ENTER;
+
+  if (!obj) {
+    ERR(GRN_INVALID_ARGUMENT, "[object][corrupt] object must not be NULL");
+    GRN_API_RETURN(GRN_FALSE);
+  }
+
+  switch (obj->header.type) {
+  case GRN_DB :
+    is_corrupt = grn_io_is_corrupt(ctx, grn_obj_io(obj));
+    if (!is_corrupt) {
+      is_corrupt = grn_io_is_corrupt(ctx, ((grn_db *)obj)->specs->io);
+    }
+    if (!is_corrupt) {
+      is_corrupt = grn_io_is_corrupt(ctx, ((grn_db *)obj)->config->io);
+    }
+    break;
+  case GRN_TABLE_HASH_KEY :
+  case GRN_TABLE_PAT_KEY :
+  case GRN_TABLE_DAT_KEY :
+  case GRN_COLUMN_FIX_SIZE :
+  case GRN_COLUMN_VAR_SIZE :
+    is_corrupt = grn_io_is_corrupt(ctx, grn_obj_io(obj));
+    break;
+  case GRN_COLUMN_INDEX :
+    is_corrupt = grn_io_is_corrupt(ctx, ((grn_ii *)obj)->seg);
+    if (!is_corrupt) {
+      is_corrupt = grn_io_is_corrupt(ctx, ((grn_ii *)obj)->chunk);
+    }
+    break;
+  default :
+    break;
+  }
+
+  GRN_API_RETURN(is_corrupt);
+}
+
 #define IS_TEMP(obj) (DB_OBJ(obj)->id & GRN_OBJ_TMP_OBJECT)
 
 static inline void
-------------- next part --------------
HTML����������������������������...
Download 



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