Kouhei Sutou
null+****@clear*****
Thu Apr 5 12:20:20 JST 2018
Kouhei Sutou 2018-04-05 12:20:20 +0900 (Thu, 05 Apr 2018) New Revision: 878f80d45eb97e60910a01a0a70a7ec755a4f41b https://github.com/groonga/groonga/commit/878f80d45eb97e60910a01a0a70a7ec755a4f41b Message: Add data store for option Modified files: lib/ctx.c lib/db.c lib/grn_ctx_impl.h lib/grn_db.h Modified: lib/ctx.c (+12 -0) =================================================================== --- lib/ctx.c 2018-04-05 12:18:13 +0900 (3b13840a7) +++ lib/ctx.c 2018-04-05 12:20:20 +0900 (561e160db) @@ -215,6 +215,7 @@ grn_ctx_impl_init(grn_ctx *ctx) ctx->impl->values = NULL; ctx->impl->temporary_columns = NULL; + ctx->impl->temporary_options = NULL; ctx->impl->ios = NULL; ctx->impl->expr_vars = NULL; ctx->impl->stack = NULL; @@ -230,6 +231,11 @@ grn_ctx_impl_init(grn_ctx *ctx) 0))) { goto exit; } + ctx->impl->temporary_options = + grn_options_create(ctx, NULL, "[ctx][impl][create]"); + if (!ctx->impl->temporary_options) { + goto exit; + } if (!(ctx->impl->ios = grn_hash_create(ctx, NULL, GRN_TABLE_MAX_KEY_SIZE, sizeof(grn_io *), GRN_OBJ_KEY_VAR_SIZE|GRN_HASH_TINY))) { @@ -315,6 +321,9 @@ exit : if (ctx->impl->ios) { grn_hash_close(ctx, ctx->impl->ios); } + if (ctx->impl->temporary_options) { + grn_options_close(ctx, ctx->impl->temporary_options); + } if (ctx->impl->temporary_columns) { grn_pat_close(ctx, ctx->impl->temporary_columns); } @@ -421,6 +430,9 @@ grn_ctx_impl_fin(grn_ctx *ctx) #endif grn_pat_close(ctx, ctx->impl->temporary_columns); } + if (ctx->impl->temporary_options) { + grn_options_close(ctx, ctx->impl->temporary_options); + } if (ctx->impl->ios) { grn_hash_close(ctx, ctx->impl->ios); } Modified: lib/db.c (+66 -0) =================================================================== --- lib/db.c 2018-04-05 12:18:13 +0900 (57328bf34) +++ lib/db.c 2018-04-05 12:20:20 +0900 (c8c458cac) @@ -214,6 +214,7 @@ grn_db_create(grn_ctx *ctx, const char *path, grn_db_create_optarg *optarg) s->specs = NULL; s->config = NULL; s->cache = NULL; + s->options = NULL; { grn_bool use_default_db_key = GRN_TRUE; @@ -264,6 +265,10 @@ grn_db_create(grn_ctx *ctx, const char *path, grn_db_create_optarg *optarg) if (!grn_db_config_create(ctx, s, path, "[db][create]")) { goto exit; } + s->options = grn_options_create(ctx, path, "[db][create]"); + if (!s->options) { + goto exit; + } grn_ctx_use(ctx, (grn_obj *)s); grn_db_init_builtin_types(ctx); if (path) { @@ -288,6 +293,14 @@ exit: grn_ja_close(ctx, s->specs); grn_ja_remove(ctx, specs_path); } + if (s->config) { + grn_hash_close(ctx, s->config); + grn_db_config_remove(ctx, path); + } + if (s->options) { + grn_options_close(ctx, s->options); + grn_options_remove(ctx, path); + } grn_tiny_array_fin(&s->values); CRITICAL_SECTION_FIN(s->lock); GRN_FREE(s); @@ -328,6 +341,7 @@ grn_db_open(grn_ctx *ctx, const char *path) s->specs = NULL; s->config = NULL; s->cache = NULL; + s->options = NULL; { uint32_t type = grn_io_detect_type(ctx, path); @@ -366,6 +380,10 @@ grn_db_open(grn_ctx *ctx, const char *path) if (!grn_db_config_open(ctx, s, path)) { goto exit; } + s->options = grn_options_open(ctx, path, "[db][open]"); + if (!s->options) { + goto exit; + } GRN_DB_OBJ_SET_TYPE(s, GRN_DB); s->obj.db = (grn_obj *)s; @@ -395,6 +413,10 @@ grn_db_open(grn_ctx *ctx, const char *path) exit: if (s) { + grn_options_close(ctx, s->options); + if (s->config) { + grn_hash_close(ctx, s->config); + } if (s->specs) { grn_ja_close(ctx, s->specs); } @@ -482,6 +504,7 @@ grn_db_close(grn_ctx *ctx, grn_obj *db) CRITICAL_SECTION_FIN(s->lock); if (s->specs) { grn_ja_close(ctx, s->specs); } grn_hash_close(ctx, s->config); + grn_options_close(ctx, s->options); GRN_FREE(s); if (ctx_used_db) { @@ -790,6 +813,9 @@ grn_obj_is_corrupt(grn_ctx *ctx, grn_obj *obj) if (!is_corrupt) { is_corrupt = grn_io_is_corrupt(ctx, ((grn_db *)obj)->config->io); } + if (!is_corrupt) { + is_corrupt = grn_options_is_corrupt(ctx, ((grn_db *)obj)->options); + } break; case GRN_TABLE_HASH_KEY : case GRN_TABLE_PAT_KEY : @@ -878,6 +904,37 @@ grn_db_check_name(grn_ctx *ctx, const char *name, unsigned int name_size) return GRN_SUCCESS; } +grn_rc +grn_db_set_option_values(grn_ctx *ctx, + grn_obj *db, + grn_id id, + const char *name, + int name_length, + grn_obj *values) +{ + grn_db *db_ = (grn_db *)db; + return grn_options_set(ctx, db_->options, id, name, name_length, values); +} + +grn_option_revision +grn_db_get_option_values(grn_ctx *ctx, + grn_obj *db, + grn_id id, + const char *name, + int name_length, + grn_option_revision revision, + grn_obj *values) +{ + grn_db *db_ = (grn_db *)db; + return grn_options_get(ctx, + db_->options, + id, + name, + name_length, + revision, + values); +} + static grn_obj * grn_type_open(grn_ctx *ctx, grn_obj_spec *spec) { @@ -9452,6 +9509,11 @@ _grn_obj_remove_db(grn_ctx *ctx, grn_obj *obj, grn_obj *db, grn_id id, } else { grn_db_config_remove(ctx, path); } + if (rc == GRN_SUCCESS) { + rc = grn_options_remove(ctx, path); + } else { + grn_options_remove(ctx, path); + } } return rc; @@ -11543,6 +11605,7 @@ grn_obj_clear_lock(grn_ctx *ctx, grn_obj *obj) grn_obj_clear_lock(ctx, (grn_obj *)(db->specs)); } grn_obj_clear_lock(ctx, (grn_obj *)(db->config)); + grn_options_clear_lock(ctx, db->options); } break; case GRN_TABLE_NO_KEY : @@ -11622,6 +11685,9 @@ grn_obj_flush(grn_ctx *ctx, grn_obj *obj) if (rc == GRN_SUCCESS) { rc = grn_obj_flush(ctx, (grn_obj *)(db->config)); } + if (rc == GRN_SUCCESS) { + rc = grn_options_flush(ctx, db->options); + } } break; case GRN_TABLE_DAT_KEY : Modified: lib/grn_ctx_impl.h (+2 -0) =================================================================== --- lib/grn_ctx_impl.h 2018-04-05 12:18:13 +0900 (2084080f4) +++ lib/grn_ctx_impl.h 2018-04-05 12:20:20 +0900 (425b1bb81) @@ -20,6 +20,7 @@ #include "grn_ctx.h" #include "grn_com.h" +#include "grn_options.h" #include "grn_msgpack.h" #ifdef GRN_WITH_MRUBY @@ -214,6 +215,7 @@ struct _grn_ctx_impl { grn_obj *db; grn_array *values; /* temporary objects */ grn_pat *temporary_columns; + grn_options *temporary_options; grn_hash *ios; /* IOs */ grn_com *com; unsigned int com_status; Modified: lib/grn_db.h (+17 -0) =================================================================== --- lib/grn_db.h 2018-04-05 12:18:13 +0900 (f971e5e5c) +++ lib/grn_db.h 2018-04-05 12:20:20 +0900 (95a5a381e) @@ -20,6 +20,7 @@ #include "grn.h" #include "grn_ctx.h" +#include "grn_options.h" #include "grn_store.h" #include "grn_rset.h" @@ -49,6 +50,7 @@ struct _grn_db { grn_tiny_array values; grn_critical_section lock; grn_cache *cache; + grn_options *options; }; #define GRN_SERIALIZED_SPEC_INDEX_SPEC 0 @@ -130,6 +132,21 @@ void grn_db_generate_pathname(grn_ctx *ctx, char *buffer); grn_rc grn_db_clear_dirty(grn_ctx *ctx, grn_obj *db); +grn_rc grn_db_set_option_values(grn_ctx *ctx, + grn_obj *db, + grn_id id, + const char *name, + int name_length, + grn_obj *values); +grn_option_revision +grn_db_get_option_values(grn_ctx *ctx, + grn_obj *db, + grn_id id, + const char *name, + int name_length, + grn_option_revision revision, + grn_obj *values); + grn_rc _grn_table_delete_by_id(grn_ctx *ctx, grn_obj *table, grn_id id, grn_table_delete_optarg *optarg); -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180405/c2fded39/attachment-0001.htm