Kouhei Sutou
null+****@clear*****
Tue Oct 9 18:48:51 JST 2018
Kouhei Sutou 2018-10-09 18:48:51 +0900 (Tue, 09 Oct 2018) Revision: 65d93129ab139d5dfdfc0b407b1675fcad79b663 https://github.com/groonga/groonga/commit/65d93129ab139d5dfdfc0b407b1675fcad79b663 Message: io_flush: lock DB while flushing It means that you can't create/remove table/column while flushing. Modified files: lib/proc.c Modified: lib/proc.c (+19 -4) =================================================================== --- lib/proc.c 2018-10-09 18:19:15 +0900 (c3a07ad79) +++ lib/proc.c 2018-10-09 18:48:51 +0900 (dae5e548a) @@ -3709,7 +3709,9 @@ proc_io_flush(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) grn_obj *target_name; grn_obj *recursive; grn_obj *only_opened; + grn_obj *db; grn_obj *target; + grn_rc rc; grn_bool is_recursive; grn_bool is_only_opened; @@ -3717,6 +3719,8 @@ proc_io_flush(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) recursive = VAR(1); only_opened = VAR(2); + db = grn_ctx_db(ctx); + if (GRN_TEXT_LEN(target_name) > 0) { target = grn_ctx_get(ctx, GRN_TEXT_VALUE(target_name), @@ -3729,13 +3733,18 @@ proc_io_flush(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) return NULL; } } else { - target = grn_ctx_db(ctx); + target = db; } + rc = grn_obj_lock(ctx, db, GRN_ID_NIL, grn_lock_timeout); + if (rc != GRN_SUCCESS) { + ERR(rc, "[io_flush] failed to lock DB: %s", ctx->errbuf); + GRN_OUTPUT_BOOL(GRN_FALSE); + return NULL; + } is_recursive = grn_proc_option_value_bool(ctx, recursive, GRN_TRUE); is_only_opened = grn_proc_option_value_bool(ctx, only_opened, GRN_FALSE); { - grn_rc rc = GRN_SUCCESS; if (target->header.type == GRN_DB && is_only_opened) { GRN_TABLE_EACH_BEGIN_FLAGS(ctx, target, cursor, id, GRN_CURSOR_BY_ID) { grn_obj *sub_target; @@ -3764,9 +3773,15 @@ proc_io_flush(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) rc = grn_obj_flush(ctx, target); } } - GRN_OUTPUT_BOOL(rc == GRN_SUCCESS); } - + { + grn_rc unlock_rc; + unlock_rc = grn_obj_unlock(ctx, db, GRN_ID_NIL); + if (rc != GRN_SUCCESS) { + rc = unlock_rc; + } + } + GRN_OUTPUT_BOOL(rc == GRN_SUCCESS); return NULL; } -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181009/0c1cccd9/attachment-0001.htm