Kouhei Sutou
null+****@clear*****
Fri Aug 7 15:38:12 JST 2015
Kouhei Sutou 2015-08-07 15:38:12 +0900 (Fri, 07 Aug 2015) New Revision: 669d80b46d7fcea04af64ef161f41de606ff4eba https://github.com/groonga/groonga/commit/669d80b46d7fcea04af64ef161f41de606ff4eba Message: database_reopen: add It's an experimental command. You can't use the command when your Groonga server runs multiple threads. Because reopening database is thread unsafe feature. You need to reduce the number of threads to 1 by thread_count command to use this command. Added files: test/command/suite/database_reopen/select.expected test/command/suite/database_reopen/select.test Modified files: lib/proc.c Modified: lib/proc.c (+24 -0) =================================================================== --- lib/proc.c 2015-08-07 15:36:34 +0900 (d249e35) +++ lib/proc.c 2015-08-07 15:38:12 +0900 (884c322) @@ -6922,6 +6922,28 @@ proc_thread_count(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d return NULL; } +static grn_obj * +proc_database_reopen(grn_ctx *ctx, int nargs, grn_obj **args, + grn_user_data *user_data) +{ + grn_rc rc; + uint32_t current_count; + + current_count = grn_thread_get_count(); + if (current_count != 1) { + ERR(GRN_OPERATION_NOT_PERMITTED, + "[database_reopen] the number of threads must be 1: <%u>", + current_count); + GRN_OUTPUT_BOOL(GRN_FALSE); + return NULL; + } + + rc = grn_db_reopen(ctx, grn_ctx_db(ctx)); + GRN_OUTPUT_BOOL(rc == GRN_SUCCESS); + + return NULL; +} + #define DEF_VAR(v,name_str) do {\ (v).name = (name_str);\ (v).name_size = GRN_STRLEN(name_str);\ @@ -7211,4 +7233,6 @@ grn_db_init_builtin_query(grn_ctx *ctx) DEF_VAR(vars[0], "new_count"); DEF_COMMAND("thread_count", proc_thread_count, 1, vars); + + DEF_COMMAND("database_reopen", proc_database_reopen, 0, vars); } Added: test/command/suite/database_reopen/select.expected (+57 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/database_reopen/select.expected 2015-08-07 15:38:12 +0900 (9cf6a0e) @@ -0,0 +1,57 @@ +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] +load --table Users +[ +{"_key": "alice", "name": "Alice"}, +{"_key": "bob", "name": "Bob"}, +{"_key": "charlie", "name": "Charlie"} +] +[[0,0.0,0.0],3] +database_reopen +[[0,0.0,0.0],true] +select Users +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 3 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "name", + "ShortText" + ] + ], + [ + 1, + "alice", + "Alice" + ], + [ + 2, + "bob", + "Bob" + ], + [ + 3, + "charlie", + "Charlie" + ] + ] + ] +] Added: test/command/suite/database_reopen/select.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/database_reopen/select.test 2015-08-07 15:38:12 +0900 (6535ce3) @@ -0,0 +1,16 @@ +table_create Users TABLE_HASH_KEY ShortText +column_create Users name COLUMN_SCALAR ShortText + +load --table Users +[ +{"_key": "alice", "name": "Alice"}, +{"_key": "bob", "name": "Bob"}, +{"_key": "charlie", "name": "Charlie"} +] + +#@disable-logging +thread_count 1 +#@enable-logging +database_reopen + +select Users -------------- next part -------------- HTML����������������������������... 下載