From: AKhatskevich <avkhatskevich@tarantool.org> To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH] Cache find_sharded_spaces result Date: Mon, 4 Jun 2018 15:52:42 +0300 [thread overview] Message-ID: <20180604125242.13445-1-avkhatskevich@tarantool.org> (raw) `find_sharded_spaces` result is cached. Cache result is updated only when `schema_version` changes. User-visible `sharded_spaces` function returns a deep copy of the cached result and user cannot affect a result of a future call to the function. Closes: #111 --- Branch: https://github.com/tarantool/vshard/tree/kh/gh-111-cache_spaces Issue: https://github.com/tarantool/vshard/issues/111 test/unit/garbage.result | 24 ++++++++++++++++++++++-- test/unit/garbage.test.lua | 9 +++++++++ vshard/storage/init.lua | 15 +++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/test/unit/garbage.result b/test/unit/garbage.result index 270949c..0da8ee1 100644 --- a/test/unit/garbage.result +++ b/test/unit/garbage.result @@ -106,8 +106,8 @@ sk2 = s2:create_index('bucket_id', {parts = {{2, 'unsigned'}}, unique = false}) ... show_sharded_spaces() --- -- - test2 - - test +- - test + - test2 ... s:drop() --- @@ -116,6 +116,26 @@ s2:drop() --- ... -- +-- gh-111: cache sharded spaces based on schema version +-- +cached_spaces = vshard.storage.internal.cached_find_sharded_spaces() +--- +... +cached_spaces == vshard.storage.internal.cached_find_sharded_spaces() +--- +- true +... +s = box.schema.create_space('test') +--- +... +cached_spaces == vshard.storage.internal.cached_find_sharded_spaces() +--- +- false +... +s:drop() +--- +... +-- -- Test garbage buckets detection. -- find_garbage = vshard.storage.internal.find_garbage_bucket diff --git a/test/unit/garbage.test.lua b/test/unit/garbage.test.lua index 12a59c5..db7821f 100644 --- a/test/unit/garbage.test.lua +++ b/test/unit/garbage.test.lua @@ -58,6 +58,15 @@ show_sharded_spaces() s:drop() s2:drop() +-- +-- gh-111: cache sharded spaces based on schema version +-- +cached_spaces = vshard.storage.internal.cached_find_sharded_spaces() +cached_spaces == vshard.storage.internal.cached_find_sharded_spaces() +s = box.schema.create_space('test') +cached_spaces == vshard.storage.internal.cached_find_sharded_spaces() +s:drop() + -- -- Test garbage buckets detection. -- diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua index f3f1bab..d5e7b57 100644 --- a/vshard/storage/init.lua +++ b/vshard/storage/init.lua @@ -552,10 +552,16 @@ local function bucket_recv(bucket_id, from, data) end -- --- Find spaces with index having the specified name. +-- Find spaces with index having the specified (in cfg) name. +-- The function result is cached using `schema_version`. -- @retval Map of type {space_id = <space object>}. -- +local sharded_spaces_cache_schema_version = nil +local sharded_spaces_cache = nil local function find_sharded_spaces() + if sharded_spaces_cache_schema_version == box.internal.schema_version() then + return sharded_spaces_cache + end local spaces = {} local idx = M.shard_index for k, space in pairs(box.space) do @@ -567,6 +573,8 @@ local function find_sharded_spaces() end end end + sharded_spaces_cache_schema_version = box.internal.schema_version() + sharded_spaces_cache = spaces return spaces end @@ -1817,6 +1825,7 @@ M.collect_garbage_step = collect_garbage_step M.collect_garbage_f = collect_garbage_f M.rebalancer_build_routes = rebalancer_build_routes M.rebalancer_calculate_metrics = rebalancer_calculate_metrics +M.cached_find_sharded_spaces = find_sharded_spaces if not rawget(_G, '__module_vshard_storage') then rawset(_G, '__module_vshard_storage', M) @@ -1853,6 +1862,8 @@ return { internal = M, on_master_enable = on_master_enable, on_master_disable = on_master_disable, - sharded_spaces = find_sharded_spaces, + sharded_spaces = function() + return table.deepcopy(find_sharded_spaces()) + end, module_version = function() return M.module_version end, } -- 2.14.1
next reply other threads:[~2018-06-04 12:53 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-06-04 12:52 AKhatskevich [this message] 2018-06-04 14:34 ` [tarantool-patches] " Vladislav Shpilevoy
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=20180604125242.13445-1-avkhatskevich@tarantool.org \ --to=avkhatskevich@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH] Cache find_sharded_spaces result' \ /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