Kouhei Sutou
null+****@clear*****
Fri Jun 16 14:33:58 JST 2017
Kouhei Sutou 2017-06-16 14:33:58 +0900 (Fri, 16 Jun 2017) New Revision: ee45972003392fcc6d73dc85936142384342874a https://github.com/groonga/groonga/commit/ee45972003392fcc6d73dc85936142384342874a Message: io_flush: add only_opened option Added files: test/command/suite/io_flush/only_opened/yes.expected test/command/suite/io_flush/only_opened/yes.test Modified files: lib/db.c lib/proc.c Modified: lib/db.c (+7 -1) =================================================================== --- lib/db.c 2017-06-15 09:05:38 +0900 (74798e4) +++ lib/db.c 2017-06-16 14:33:58 +0900 (63e5573) @@ -11481,7 +11481,13 @@ grn_obj_flush(grn_ctx *ctx, grn_obj *obj) rc = grn_ii_flush(ctx, (grn_ii *)obj); break; default : - rc = grn_io_flush(ctx, grn_obj_io(obj)); + { + grn_io *io; + io = grn_obj_io(obj); + if (io) { + rc = grn_io_flush(ctx, io); + } + } break; } Modified: lib/proc.c (+30 -2) =================================================================== --- lib/proc.c 2017-06-15 09:05:38 +0900 (56578fd) +++ lib/proc.c 2017-06-16 14:33:58 +0900 (8559a67) @@ -3449,11 +3449,14 @@ 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 *target; grn_bool is_recursive; + grn_bool is_only_opened; target_name = VAR(0); recursive = VAR(1); + only_opened = VAR(2); if (GRN_TEXT_LEN(target_name) > 0) { target = grn_ctx_get(ctx, @@ -3471,10 +3474,34 @@ proc_io_flush(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) } 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; if (is_recursive) { - rc = grn_obj_flush_recursive(ctx, target); + if (target->header.type == GRN_DB && is_only_opened) { + rc = grn_obj_flush(ctx, target); + if (rc == GRN_SUCCESS) { + GRN_TABLE_EACH_BEGIN_FLAGS(ctx, target, cursor, id, GRN_CURSOR_BY_ID) { + grn_obj *sub_target; + + if (id < GRN_N_RESERVED_TYPES) { + continue; + } + + if (!grn_ctx_is_opened(ctx, id)) { + continue; + } + + sub_target = grn_ctx_at(ctx, id); + rc = grn_obj_flush(ctx, sub_target); + if (rc != GRN_SUCCESS) { + break; + } + } GRN_TABLE_EACH_END(ctx, cursor); + } + } else { + rc = grn_obj_flush_recursive(ctx, target); + } } else { rc = grn_obj_flush(ctx, target); } @@ -3943,7 +3970,8 @@ grn_db_init_builtin_commands(grn_ctx *ctx) DEF_VAR(vars[0], "target_name"); DEF_VAR(vars[1], "recursive"); - DEF_COMMAND("io_flush", proc_io_flush, 2, vars); + DEF_VAR(vars[2], "only_opened"); + DEF_COMMAND("io_flush", proc_io_flush, 3, vars); grn_proc_init_object_exist(ctx); Added: test/command/suite/io_flush/only_opened/yes.expected (+41 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/io_flush/only_opened/yes.expected 2017-06-16 14:33:58 +0900 (6719cf2) @@ -0,0 +1,41 @@ +table_create Users TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Users name COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +[[0,0.0,0.0],true] +column_create Terms users_name COLUMN_INDEX|WITH_POSITION Users name +[[0,0.0,0.0],true] +database_unmap +[[0,0.0,0.0],true] +select Users +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 0 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "name", + "ShortText" + ] + ] + ] + ] +] +io_flush --only_opened yes +[[0,0.0,0.0],true] Added: test/command/suite/io_flush/only_opened/yes.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/io_flush/only_opened/yes.test 2017-06-16 14:33:58 +0900 (ffc82c0) @@ -0,0 +1,16 @@ +table_create Users TABLE_HASH_KEY ShortText +column_create Users name COLUMN_SCALAR ShortText + +table_create Terms TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer NormalizerAuto +column_create Terms users_name COLUMN_INDEX|WITH_POSITION Users name + +#@disable-logging +thread_limit 1 +#@enable-logging +database_unmap + +select Users + +io_flush --only_opened yes -------------- next part -------------- HTML����������������������������... Download