Kouhei Sutou
null+****@clear*****
Mon Jan 25 14:44:42 JST 2016
Kouhei Sutou 2016-01-25 14:44:42 +0900 (Mon, 25 Jan 2016) New Revision: 105dee038da24205fd0adcd8cd33cd071e63a6ed https://github.com/groonga/groonga/commit/105dee038da24205fd0adcd8cd33cd071e63a6ed Message: Extract lock related commands Added files: lib/proc/proc_lock.c Modified files: lib/grn_proc.h lib/proc.c lib/proc/sources.am Modified: lib/grn_proc.h (+2 -0) =================================================================== --- lib/grn_proc.h 2016-01-25 00:12:23 +0900 (9603414) +++ lib/grn_proc.h 2016-01-25 14:44:42 +0900 (fd42ea6) @@ -29,9 +29,11 @@ void grn_proc_init_from_env(void); GRN_VAR const char *grn_document_root; void grn_db_init_builtin_query(grn_ctx *ctx); +void grn_proc_init_clearlock(grn_ctx *ctx); void grn_proc_init_config_get(grn_ctx *ctx); void grn_proc_init_config_set(grn_ctx *ctx); void grn_proc_init_config_delete(grn_ctx *ctx); +void grn_proc_init_lock_clear(grn_ctx *ctx); void grn_proc_init_schema(grn_ctx *ctx); void grn_proc_init_table_create(grn_ctx *ctx); void grn_proc_init_table_list(grn_ctx *ctx); Modified: lib/proc.c (+3 -34) =================================================================== --- lib/proc.c 2016-01-25 00:12:23 +0900 (653c88c) +++ lib/proc.c 2016-01-25 14:44:42 +0900 (c05e44f) @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2 -*- */ /* - Copyright(C) 2009-2015 Brazil + Copyright(C) 2009-2016 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -2013,33 +2013,6 @@ proc_shutdown(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) } static grn_obj * -proc_lock_clear(grn_ctx *ctx, int nargs, grn_obj **args, - grn_user_data *user_data) -{ - int target_name_len; - grn_obj *target_name; - grn_obj *obj; - - target_name = VAR(0); - target_name_len = GRN_TEXT_LEN(target_name); - - if (target_name_len) { - obj = grn_ctx_get(ctx, GRN_TEXT_VALUE(target_name), target_name_len); - } else { - obj = ctx->impl->db; - } - - if (obj) { - grn_obj_clear_lock(ctx, obj); - } else { - ERR(GRN_INVALID_ARGUMENT, "[lock_clear] target object not found: <%.*s>", - target_name_len, GRN_TEXT_VALUE(target_name)); - } - GRN_OUTPUT_BOOL(!ctx->rc); - return NULL; -} - -static grn_obj * proc_defrag(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) { grn_obj *obj; @@ -6915,12 +6888,8 @@ grn_db_init_builtin_query(grn_ctx *ctx) DEF_COMMAND("shutdown", proc_shutdown, 0, vars); - /* Deprecated. Use "lock_clear" instead. */ - DEF_VAR(vars[0], "target_name"); - DEF_COMMAND("clearlock", proc_lock_clear, 1, vars); - - DEF_VAR(vars[0], "target_name"); - DEF_COMMAND("lock_clear", proc_lock_clear, 1, vars); + grn_proc_init_clearlock(ctx); + grn_proc_init_lock_clear(ctx); DEF_VAR(vars[0], "target_name"); DEF_VAR(vars[1], "threshold"); Added: lib/proc/proc_lock.c (+80 -0) 100644 =================================================================== --- /dev/null +++ lib/proc/proc_lock.c 2016-01-25 14:44:42 +0900 (e9cb363) @@ -0,0 +1,80 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2009-2016 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "grn_proc.h" + +#include <groonga/plugin.h> + +static grn_obj * +command_lock_clear(grn_ctx *ctx, + int nargs, + grn_obj **args, + grn_user_data *user_data) +{ + int target_name_len; + grn_obj *target_name; + grn_obj *obj; + + target_name = grn_plugin_proc_get_var(ctx, user_data, "target_name", -1); + target_name_len = GRN_TEXT_LEN(target_name); + + if (target_name_len) { + obj = grn_ctx_get(ctx, GRN_TEXT_VALUE(target_name), target_name_len); + } else { + obj = grn_ctx_db(ctx); + } + + if (obj) { + grn_obj_clear_lock(ctx, obj); + } else { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "[lock_clear] target object not found: <%.*s>", + target_name_len, GRN_TEXT_VALUE(target_name)); + } + + grn_ctx_output_bool(ctx, ctx->rc == GRN_SUCCESS); + + return NULL; +} + +void +grn_proc_init_clearlock(grn_ctx *ctx) +{ + grn_expr_var vars[1]; + + /* Deprecated. Use "lock_clear" instead. */ + grn_plugin_expr_var_init(ctx, &(vars[0]), "target_name", -1); + grn_plugin_command_create(ctx, + "clearlock", -1, + command_lock_clear, + 1, + vars); +} + +void +grn_proc_init_lock_clear(grn_ctx *ctx) +{ + grn_expr_var vars[1]; + + grn_plugin_expr_var_init(ctx, &(vars[0]), "target_name", -1); + grn_plugin_command_create(ctx, + "lock_clear", -1, + command_lock_clear, + 1, + vars); +} Modified: lib/proc/sources.am (+1 -0) =================================================================== --- lib/proc/sources.am 2016-01-25 00:12:23 +0900 (a9818ba) +++ lib/proc/sources.am 2016-01-25 14:44:42 +0900 (f036e2d) @@ -1,4 +1,5 @@ libgrnproc_la_SOURCES = \ proc_config.c \ + proc_lock.c \ proc_schema.c \ proc_table.c -------------- next part -------------- HTML����������������������������...Télécharger