null+****@clear*****
null+****@clear*****
2010年 9月 15日 (水) 11:58:53 JST
Kouhei Sutou 2010-09-15 02:58:53 +0000 (Wed, 15 Sep 2010) New Revision: 9f614d004ff0f41ddf57b8ed003a67708aee98da Log: check command version availability. Modified files: groonga.h lib/ctx.c lib/proc.c test/unit/gqtp/test-status.rb test/unit/lib/ruby/groonga-constants.rb Modified: groonga.h (+7 -3) =================================================================== --- groonga.h 2010-09-15 02:32:46 +0000 (5f9ed65) +++ groonga.h 2010-09-15 02:58:53 +0000 (4989aed) @@ -109,7 +109,8 @@ typedef enum { GRN_TOO_SMALL_OFFSET = -67, GRN_TOO_LARGE_OFFSET = -68, GRN_TOO_SMALL_LIMIT = -69, - GRN_CAS_ERROR = -70 + GRN_CAS_ERROR = -70, + GRN_UNSUPPORTED_COMMAND_VERSION = -71 } grn_rc; GRN_API grn_rc grn_init(void); @@ -128,10 +129,13 @@ typedef enum { typedef enum { GRN_COMMAND_VERSION_DEFAULT = 0, GRN_COMMAND_VERSION_1, - GRN_COMMAND_VERSION_2, - GRN_COMMAND_VERSION_MAX + GRN_COMMAND_VERSION_2 } grn_command_version; +#define GRN_COMMAND_VERSION_MIN GRN_COMMAND_VERSION_1 +#define GRN_COMMAND_VERSION_STABLE GRN_COMMAND_VERSION_1 +#define GRN_COMMAND_VERSION_MAX GRN_COMMAND_VERSION_2 + typedef enum { GRN_LOG_NONE = 0, GRN_LOG_EMERG, Modified: lib/ctx.c (+21 -7) =================================================================== --- lib/ctx.c 2010-09-15 02:32:46 +0000 (bc9e5cb) +++ lib/ctx.c 2010-09-15 02:58:53 +0000 (6de94a8) @@ -264,7 +264,7 @@ grn_ctx_impl_init(grn_ctx *ctx) GRN_UINT32_INIT(&ctx->impl->levels, GRN_OBJ_VECTOR); if (ctx == &grn_gctx) { - ctx->impl->command_version = GRN_COMMAND_VERSION_MAX - 1; + ctx->impl->command_version = GRN_COMMAND_VERSION_STABLE; } else { ctx->impl->command_version = grn_get_default_command_version(); } @@ -769,7 +769,7 @@ grn_ctx_get_command_version(grn_ctx *ctx) if (ctx->impl) { return ctx->impl->command_version; } else { - return GRN_COMMAND_VERSION_MAX - 1; + return GRN_COMMAND_VERSION_STABLE; } } @@ -778,15 +778,15 @@ grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version) { switch (version) { case GRN_COMMAND_VERSION_DEFAULT : - ctx->impl->command_version = GRN_COMMAND_VERSION_MAX - 1; + ctx->impl->command_version = GRN_COMMAND_VERSION_STABLE; return GRN_SUCCESS; default : - if (GRN_COMMAND_VERSION_DEFAULT < version && - version < GRN_COMMAND_VERSION_MAX) { + if (GRN_COMMAND_VERSION_MIN <= version && + version <= GRN_COMMAND_VERSION_MAX) { ctx->impl->command_version = version; return GRN_SUCCESS; } else { - return GRN_INVALID_ARGUMENT; + return GRN_UNSUPPORTED_COMMAND_VERSION; } } } @@ -903,7 +903,17 @@ get_command_version(grn_ctx *ctx, const char *p, const char *pe) version = grn_atoui(p, pe, &rest); if (pe == rest) { - grn_ctx_set_command_version(ctx, version); + grn_rc rc; + rc = grn_ctx_set_command_version(ctx, version); + if (rc == GRN_UNSUPPORTED_COMMAND_VERSION) { + ERR(rc, + "unsupported command version is specified: %d: " + "stable command version: %d: " + "available command versions: %d-%d", + version, + GRN_COMMAND_VERSION_STABLE, + GRN_COMMAND_VERSION_MIN, GRN_COMMAND_VERSION_MAX); + } } } @@ -950,6 +960,7 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len) GRN_BULK_REWIND(&buf); p = grn_text_cgidec(ctx, &buf, p, e, '&'); get_command_version(ctx, GRN_TEXT_VALUE(&buf), GRN_BULK_CURR(&buf)); + if (ctx->rc) { goto exit; } } else { if (!(val = grn_expr_get_or_add_var(ctx, expr, v, l))) { val = &buf; @@ -969,6 +980,7 @@ grn_ctx_qe_exec_uri(grn_ctx *ctx, const char *path, uint32_t path_len) ctx->impl->curr_expr = expr; grn_expr_exec(ctx, expr, 0); } +exit : GRN_OBJ_FIN(ctx, &buf); return expr; } @@ -1005,6 +1017,7 @@ grn_ctx_qe_exec(grn_ctx *ctx, const char *str, uint32_t str_len) GRN_BULK_REWIND(&buf); p = grn_text_unesc_tok(ctx, &buf, p, e, &tok_type); get_command_version(ctx, GRN_TEXT_VALUE(&buf), GRN_BULK_CURR(&buf)); + if (ctx->rc) { goto exit; } } else if (expr && (val = grn_expr_get_or_add_var(ctx, expr, v, l))) { grn_obj_reinit(ctx, val, GRN_DB_TEXT, 0); p = grn_text_unesc_tok(ctx, val, p, e, &tok_type); @@ -1036,6 +1049,7 @@ grn_ctx_qe_exec(grn_ctx *ctx, const char *str, uint32_t str_len) GRN_TEXT_LEN(&buf), GRN_TEXT_VALUE(&buf)); } } +exit : GRN_OBJ_FIN(ctx, &buf); return expr; } Modified: lib/proc.c (+1 -1) =================================================================== --- lib/proc.c 2010-09-15 02:32:46 +0000 (e941f27) +++ lib/proc.c 2010-09-15 02:58:53 +0000 (2faacad) @@ -406,7 +406,7 @@ proc_status(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data) GRN_OUTPUT_CSTR("default_command_version"); GRN_OUTPUT_INT32(grn_get_default_command_version()); GRN_OUTPUT_CSTR("max_command_version"); - GRN_OUTPUT_INT32(GRN_COMMAND_VERSION_MAX - 1); + GRN_OUTPUT_INT32(GRN_COMMAND_VERSION_MAX); GRN_OUTPUT_MAP_CLOSE(); return NULL; } Modified: test/unit/gqtp/test-status.rb (+8 -1) =================================================================== --- test/unit/gqtp/test-status.rb 2010-09-15 02:32:46 +0000 (97a8a92) +++ test/unit/gqtp/test-status.rb 2010-09-15 02:58:53 +0000 (fac8e15) @@ -33,6 +33,13 @@ class StatusTest < Test::Unit::TestCase def test_command_version output = run_groonga(@database_path, "status", "--command_version", "1") - assert_equal(1, JSON.parse(output)[1]["command_version"]) + rc, result = JSON.parse(output) + assert_equal(1, result["command_version"]) + end + + def test_unsupported_command_version + output = run_groonga(@database_path, "status", "--command_version", "10000") + rc, result = JSON.parse(output) + assert_equal(Result::UNSUPPORTED_COMMAND_VERSION, rc[0]) end end Modified: test/unit/lib/ruby/groonga-constants.rb (+6 -0) =================================================================== --- test/unit/lib/ruby/groonga-constants.rb 2010-09-15 02:32:46 +0000 (3cc30fa) +++ test/unit/lib/ruby/groonga-constants.rb 2010-09-15 02:58:53 +0000 (e4f4b6b) @@ -84,6 +84,12 @@ module GroongaConstants SYNTAX_ERROR = -63 RETRY_MAX = -64 INCOMPATIBLE_FILE_FORMAT = -65 + UPDATE_NOT_ALLOWED = -66 + TOO_SMALL_OFFSET = -67 + TOO_LARGE_OFFSET = -68 + TOO_SMALL_LIMIT = -69 + CAS_ERROR = -70 + UNSUPPORTED_COMMAND_VERSION = -71 end module Table