Kouhei Sutou
null+****@clear*****
Wed Dec 10 22:40:17 JST 2014
Kouhei Sutou 2014-12-10 22:40:17 +0900 (Wed, 10 Dec 2014) New Revision: 166e2361bdd971586dbb64f3d32662e0dc93388c https://github.com/groonga/groonga/commit/166e2361bdd971586dbb64f3d32662e0dc93388c Message: Add grn_db_recover() It's an experimental API. You should use this API carefully. You don't use this API when other process or thread open the target database. If you use this API for database that is opened by other process or thread, the database may be broken. grn_db_recover() checks the target database. If there are broken objects by crash(*), it tries to recover it. (*) Broken objects are detected by checking whether IO lock is remained or not. Because crash may remain IO lock. If other process or thread open the database, IO lock may be remained. But the IO lock is normal lock not unexpected IO lock. So broken objects detection may be failed. For now, index column is only supported for broken objects detection and recovering. TODO: * Document me. * Support broken object detection other objects. Modified files: include/groonga/groonga.h lib/db.c Modified: include/groonga/groonga.h (+1 -0) =================================================================== --- include/groonga/groonga.h 2014-12-10 22:37:30 +0900 (9d3ea11) +++ include/groonga/groonga.h 2014-12-10 22:40:17 +0900 (41bc727) @@ -424,6 +424,7 @@ GRN_API grn_obj *grn_db_create(grn_ctx *ctx, const char *path, grn_db_create_opt GRN_API grn_obj *grn_db_open(grn_ctx *ctx, const char *path); GRN_API void grn_db_touch(grn_ctx *ctx, grn_obj *db); +GRN_API grn_rc grn_db_recover(grn_ctx *ctx, grn_obj *db); GRN_API grn_rc grn_ctx_use(grn_ctx *ctx, grn_obj *db); GRN_API grn_obj *grn_ctx_db(grn_ctx *ctx); Modified: lib/db.c (+53 -0) =================================================================== --- lib/db.c 2014-12-10 22:37:30 +0900 (cbd36f4) +++ lib/db.c 2014-12-10 22:40:17 +0900 (f839023) @@ -11615,3 +11615,56 @@ grn_load(grn_ctx *ctx, grn_content_type input_type, ifexists, ifexists_len, each, each_len, 1); GRN_API_RETURN(ctx->rc); } + +static void +grn_db_recover_index_column(grn_ctx *ctx, grn_obj *index_column) +{ + grn_ii *ii = (grn_ii *)index_column; + + if (!grn_obj_is_locked(ctx, index_column)) { + return; + } + + grn_ii_truncate(ctx, ii); + build_index(ctx, index_column); +} + +grn_rc +grn_db_recover(grn_ctx *ctx, grn_obj *db) +{ + grn_table_cursor *cursor; + grn_id id; + + GRN_API_ENTER; + cursor = grn_table_cursor_open(ctx, db, + NULL, 0, NULL, 0, + 0, -1, + GRN_CURSOR_BY_ID); + if (!cursor) { + GRN_API_RETURN(ctx->rc); + } + + while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) { + grn_obj *object; + + if ((object = grn_ctx_at(ctx, id))) { + switch (object->header.type) { + case GRN_COLUMN_INDEX : + grn_db_recover_index_column(ctx, object); + break; + default: + break; + } + grn_obj_unlink(ctx, object); + } else { + ERRCLR(ctx); + } + + if (ctx->rc != GRN_SUCCESS) { + break; + } + } + grn_table_cursor_close(ctx, cursor); + + GRN_API_RETURN(ctx->rc); +} -------------- next part -------------- HTML����������������������������...Télécharger