From: Vladimir Davydov <vdavydov.dev@gmail.com> To: tarantool-patches@freelists.org Subject: [PATCH 01/13] vinyl: embed engine in vy_env Date: Sat, 10 Aug 2019 13:03:28 +0300 [thread overview] Message-ID: <54993ef2ba91daee63193d492150eb0baab35bef.1565430177.git.vdavydov.dev@gmail.com> (raw) In-Reply-To: <cover.1565430177.git.vdavydov.dev@gmail.com> There's no point in having vinyl_engine and vinyl_index wrapper structs to bind vy_env and vy_lsm to struct engine and index. Instead we can simply embed engine and index in vy_env and vy_lsm. This will simplify further development, e.g. this will allow us to move reference counting from vy_lsm up to struct index so that it can be used in the generic code. --- src/box/box.cc | 20 ++++------ src/box/lua/info.c | 3 +- src/box/lua/stat.c | 3 +- src/box/vinyl.c | 96 +++++++++++++++++++++------------------------- src/box/vinyl.h | 26 ++++++------- 5 files changed, 65 insertions(+), 83 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 80249919..66cd6d3a 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -784,8 +784,7 @@ box_set_snap_io_rate_limit(void) assert(memtx != NULL); memtx_engine_set_snap_io_rate_limit(memtx, cfg_getd("snap_io_rate_limit")); - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_set_snap_io_rate_limit(vinyl, cfg_getd("snap_io_rate_limit")); @@ -816,8 +815,7 @@ box_set_too_long_threshold(void) { too_long_threshold = cfg_getd("too_long_threshold"); - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_set_too_long_threshold(vinyl, too_long_threshold); } @@ -855,8 +853,7 @@ box_set_checkpoint_wal_threshold(void) void box_set_vinyl_memory(void) { - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_set_memory_xc(vinyl, box_check_vinyl_memory(cfg_geti64("vinyl_memory"))); @@ -865,8 +862,7 @@ box_set_vinyl_memory(void) void box_set_vinyl_max_tuple_size(void) { - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_set_max_tuple_size(vinyl, cfg_geti("vinyl_max_tuple_size")); @@ -875,8 +871,7 @@ box_set_vinyl_max_tuple_size(void) void box_set_vinyl_cache(void) { - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_set_cache(vinyl, cfg_geti64("vinyl_cache")); } @@ -884,8 +879,7 @@ box_set_vinyl_cache(void) void box_set_vinyl_timeout(void) { - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_set_timeout(vinyl, cfg_getd("vinyl_timeout")); } @@ -1718,7 +1712,7 @@ engine_init() struct engine *blackhole = blackhole_engine_new_xc(); engine_register(blackhole); - struct vinyl_engine *vinyl; + struct engine *vinyl; vinyl = vinyl_engine_new_xc(cfg_gets("vinyl_dir"), cfg_geti64("vinyl_memory"), cfg_geti("vinyl_read_threads"), diff --git a/src/box/lua/info.c b/src/box/lua/info.c index d0e553b1..55382fd7 100644 --- a/src/box/lua/info.c +++ b/src/box/lua/info.c @@ -463,8 +463,7 @@ lbox_info_vinyl_call(struct lua_State *L) { struct info_handler h; luaT_info_handler_create(&h, L); - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_stat(vinyl, &h); return 1; diff --git a/src/box/lua/stat.c b/src/box/lua/stat.c index eee2b104..29ec38b2 100644 --- a/src/box/lua/stat.c +++ b/src/box/lua/stat.c @@ -121,8 +121,7 @@ lbox_stat_vinyl(struct lua_State *L) { struct info_handler h; luaT_info_handler_create(&h, L); - struct vinyl_engine *vinyl; - vinyl = (struct vinyl_engine *)engine_by_name("vinyl"); + struct engine *vinyl = engine_by_name("vinyl"); assert(vinyl != NULL); vinyl_engine_stat(vinyl, &h); return 1; diff --git a/src/box/vinyl.c b/src/box/vinyl.c index cd009c1c..327d0c39 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -94,6 +94,7 @@ enum vy_status { }; struct vy_env { + struct engine base; /** Recovery status */ enum vy_status status; /** TX manager */ @@ -141,19 +142,6 @@ struct vy_env { bool force_recovery; }; -struct vinyl_engine { - struct engine base; - /** Vinyl environment. */ - struct vy_env *env; -}; - -/** Extract vy_env from an engine object. */ -static inline struct vy_env * -vy_env(struct engine *engine) -{ - return ((struct vinyl_engine *)engine)->env; -} - struct vinyl_index { struct index base; /** LSM tree that stores index data. */ @@ -210,6 +198,14 @@ static const struct index_vtab vinyl_index_vtab; static struct trigger on_replace_vinyl_deferred_delete; +/** Extract vy_env from an engine object. */ +static inline struct vy_env * +vy_env(struct engine *engine) +{ + assert(engine->vtab == &vinyl_engine_vtab); + return (struct vy_env *)engine; +} + /** * A quick intro into Vinyl cosmology and file format * -------------------------------------------------- @@ -327,9 +323,9 @@ vy_info_append_disk(struct vy_env *env, struct info_handler *h) } void -vinyl_engine_stat(struct vinyl_engine *vinyl, struct info_handler *h) +vinyl_engine_stat(struct engine *engine, struct info_handler *h) { - struct vy_env *env = vinyl->env; + struct vy_env *env = vy_env(engine); info_begin(h); vy_info_append_tx(env, h); @@ -692,14 +688,13 @@ static struct index * vinyl_space_create_index(struct space *space, struct index_def *index_def) { assert(index_def->type == TREE); - struct vinyl_engine *vinyl = (struct vinyl_engine *)space->engine; struct vinyl_index *index = calloc(1, sizeof(*index)); if (index == NULL) { diag_set(OutOfMemory, sizeof(*index), "malloc", "struct vinyl_index"); return NULL; } - struct vy_env *env = vinyl->env; + struct vy_env *env = vy_env(space->engine); struct vy_lsm *pk = NULL; if (index_def->iid > 0) { pk = vy_lsm(space_index(space, 0)); @@ -712,7 +707,7 @@ vinyl_space_create_index(struct space *space, struct index_def *index_def) free(index); return NULL; } - if (index_create(&index->base, (struct engine *)vinyl, + if (index_create(&index->base, &env->base, &vinyl_index_vtab, index_def) != 0) { vy_lsm_delete(lsm); free(index); @@ -2689,82 +2684,77 @@ vy_env_complete_recovery(struct vy_env *env) vy_regulator_start(&env->regulator); } -struct vinyl_engine * +struct engine * vinyl_engine_new(const char *dir, size_t memory, int read_threads, int write_threads, bool force_recovery) { - struct vinyl_engine *vinyl = calloc(1, sizeof(*vinyl)); - if (vinyl == NULL) { - diag_set(OutOfMemory, sizeof(*vinyl), - "malloc", "struct vinyl_engine"); + struct vy_env *env = vy_env_new(dir, memory, read_threads, + write_threads, force_recovery); + if (env == NULL) return NULL; - } - vinyl->env = vy_env_new(dir, memory, read_threads, - write_threads, force_recovery); - if (vinyl->env == NULL) { - free(vinyl); - return NULL; - } - - vinyl->base.vtab = &vinyl_engine_vtab; - vinyl->base.name = "vinyl"; - return vinyl; + env->base.vtab = &vinyl_engine_vtab; + env->base.name = "vinyl"; + return &env->base; } static void vinyl_engine_shutdown(struct engine *engine) { - struct vinyl_engine *vinyl = (struct vinyl_engine *)engine; - vy_env_delete(vinyl->env); - free(vinyl); + struct vy_env *env = vy_env(engine); + vy_env_delete(env); } void -vinyl_engine_set_cache(struct vinyl_engine *vinyl, size_t quota) +vinyl_engine_set_cache(struct engine *engine, size_t quota) { - vy_cache_env_set_quota(&vinyl->env->cache_env, quota); + struct vy_env *env = vy_env(engine); + vy_cache_env_set_quota(&env->cache_env, quota); } int -vinyl_engine_set_memory(struct vinyl_engine *vinyl, size_t size) +vinyl_engine_set_memory(struct engine *engine, size_t size) { - if (size < vinyl->env->quota.limit) { + struct vy_env *env = vy_env(engine); + if (size < env->quota.limit) { diag_set(ClientError, ER_CFG, "vinyl_memory", "cannot decrease memory size at runtime"); return -1; } - vy_regulator_set_memory_limit(&vinyl->env->regulator, size); + vy_regulator_set_memory_limit(&env->regulator, size); return 0; } void -vinyl_engine_set_max_tuple_size(struct vinyl_engine *vinyl, size_t max_size) +vinyl_engine_set_max_tuple_size(struct engine *engine, size_t max_size) { - vinyl->env->stmt_env.max_tuple_size = max_size; + struct vy_env *env = vy_env(engine); + env->stmt_env.max_tuple_size = max_size; } void -vinyl_engine_set_timeout(struct vinyl_engine *vinyl, double timeout) +vinyl_engine_set_timeout(struct engine *engine, double timeout) { - vinyl->env->timeout = timeout; + struct vy_env *env = vy_env(engine); + env->timeout = timeout; } void -vinyl_engine_set_too_long_threshold(struct vinyl_engine *vinyl, +vinyl_engine_set_too_long_threshold(struct engine *engine, double too_long_threshold) { - vinyl->env->quota.too_long_threshold = too_long_threshold; - vinyl->env->lsm_env.too_long_threshold = too_long_threshold; + struct vy_env *env = vy_env(engine); + env->quota.too_long_threshold = too_long_threshold; + env->lsm_env.too_long_threshold = too_long_threshold; } void -vinyl_engine_set_snap_io_rate_limit(struct vinyl_engine *vinyl, double limit) +vinyl_engine_set_snap_io_rate_limit(struct engine *engine, double limit) { + struct vy_env *env = vy_env(engine); int64_t limit_in_bytes = limit * 1024 * 1024; - vinyl->env->run_env.snap_io_rate_limit = limit_in_bytes; - vy_regulator_reset_dump_bandwidth(&vinyl->env->regulator, - limit_in_bytes); + env->run_env.snap_io_rate_limit = limit_in_bytes; + vy_regulator_reset_dump_bandwidth(&env->regulator, limit_in_bytes); } /** }}} Environment */ diff --git a/src/box/vinyl.h b/src/box/vinyl.h index 21f99e45..2a3e8f1f 100644 --- a/src/box/vinyl.h +++ b/src/box/vinyl.h @@ -39,9 +39,9 @@ extern "C" { #endif /* defined(__cplusplus) */ struct info_handler; -struct vinyl_engine; +struct engine; -struct vinyl_engine * +struct engine * vinyl_engine_new(const char *dir, size_t memory, int read_threads, int write_threads, bool force_recovery); @@ -49,55 +49,55 @@ vinyl_engine_new(const char *dir, size_t memory, * Vinyl engine statistics (box.stat.vinyl()). */ void -vinyl_engine_stat(struct vinyl_engine *vinyl, struct info_handler *handler); +vinyl_engine_stat(struct engine *engine, struct info_handler *handler); /** * Update vinyl cache size. */ void -vinyl_engine_set_cache(struct vinyl_engine *vinyl, size_t quota); +vinyl_engine_set_cache(struct engine *engine, size_t quota); /** * Update vinyl memory size. */ int -vinyl_engine_set_memory(struct vinyl_engine *vinyl, size_t size); +vinyl_engine_set_memory(struct engine *engine, size_t size); /** * Update max tuple size. */ void -vinyl_engine_set_max_tuple_size(struct vinyl_engine *vinyl, size_t max_size); +vinyl_engine_set_max_tuple_size(struct engine *engine, size_t max_size); /** * Update query timeout. */ void -vinyl_engine_set_timeout(struct vinyl_engine *vinyl, double timeout); +vinyl_engine_set_timeout(struct engine *engine, double timeout); /** * Update too_long_threshold. */ void -vinyl_engine_set_too_long_threshold(struct vinyl_engine *vinyl, +vinyl_engine_set_too_long_threshold(struct engine *engine, double too_long_threshold); /** * Update snap_io_rate_limit. */ void -vinyl_engine_set_snap_io_rate_limit(struct vinyl_engine *vinyl, double limit); +vinyl_engine_set_snap_io_rate_limit(struct engine *engine, double limit); #ifdef __cplusplus } /* extern "C" */ #include "diag.h" -static inline struct vinyl_engine * +static inline struct engine * vinyl_engine_new_xc(const char *dir, size_t memory, int read_threads, int write_threads, bool force_recovery) { - struct vinyl_engine *vinyl; + struct engine *vinyl; vinyl = vinyl_engine_new(dir, memory, read_threads, write_threads, force_recovery); if (vinyl == NULL) @@ -106,9 +106,9 @@ vinyl_engine_new_xc(const char *dir, size_t memory, } static inline void -vinyl_engine_set_memory_xc(struct vinyl_engine *vinyl, size_t size) +vinyl_engine_set_memory_xc(struct engine *engine, size_t size) { - if (vinyl_engine_set_memory(vinyl, size) != 0) + if (vinyl_engine_set_memory(engine, size) != 0) diag_raise(); } -- 2.20.1
next prev parent reply other threads:[~2019-08-10 10:03 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-10 10:03 [PATCH 00/13] Join replicas off the current read view Vladimir Davydov 2019-08-10 10:03 ` Vladimir Davydov [this message] 2019-08-12 22:14 ` [tarantool-patches] Re: [PATCH 01/13] vinyl: embed engine in vy_env Konstantin Osipov 2019-08-14 13:09 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 02/13] vinyl: embed index in vy_lsm Vladimir Davydov 2019-08-12 22:14 ` [tarantool-patches] " Konstantin Osipov 2019-08-14 13:09 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 03/13] vinyl: move reference counting from vy_lsm to index Vladimir Davydov 2019-08-12 22:16 ` [tarantool-patches] " Konstantin Osipov 2019-08-14 13:09 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 04/13] vinyl: don't pin index for iterator lifetime Vladimir Davydov 2019-08-10 10:03 ` [PATCH 05/13] vinyl: don't exempt dropped indexes from dump and compaction Vladimir Davydov 2019-08-10 10:03 ` [PATCH 06/13] memtx: don't store pointers to index internals in iterator Vladimir Davydov 2019-08-12 22:21 ` [tarantool-patches] " Konstantin Osipov 2019-08-14 13:10 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 07/13] memtx: use ref counting to pin indexes for snapshot Vladimir Davydov 2019-08-12 22:24 ` [tarantool-patches] " Konstantin Osipov 2019-08-13 10:56 ` Vladimir Davydov 2019-08-13 16:08 ` Georgy Kirichenko 2019-08-10 10:03 ` [PATCH 08/13] memtx: allow snapshot iterator to fail Vladimir Davydov 2019-08-12 22:25 ` [tarantool-patches] " Konstantin Osipov 2019-08-14 13:10 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 09/13] memtx: enter small delayed free mode from snapshot iterator Vladimir Davydov 2019-08-12 22:27 ` [tarantool-patches] " Konstantin Osipov 2019-08-13 10:59 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 10/13] wal: make wal_sync fail on write error Vladimir Davydov 2019-08-12 22:29 ` [tarantool-patches] " Konstantin Osipov 2019-08-14 16:48 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 11/13] xrow: factor out helper for setting REPLACE request body Vladimir Davydov 2019-08-12 22:29 ` [tarantool-patches] " Konstantin Osipov 2019-08-14 13:11 ` Vladimir Davydov 2019-08-10 10:03 ` [PATCH 12/13] test: disable replication/on_schema_init Vladimir Davydov 2019-08-12 22:31 ` [tarantool-patches] " Konstantin Osipov 2019-08-10 10:03 ` [PATCH 13/13] relay: join new replicas off read view Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=54993ef2ba91daee63193d492150eb0baab35bef.1565430177.git.vdavydov.dev@gmail.com \ --to=vdavydov.dev@gmail.com \ --cc=tarantool-patches@freelists.org \ --subject='Re: [PATCH 01/13] vinyl: embed engine in vy_env' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox