From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id BFA0B25F07 for ; Mon, 4 Jun 2018 10:34:52 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j60EOSsldbxF for ; Mon, 4 Jun 2018 10:34:52 -0400 (EDT) Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 70DF025EF4 for ; Mon, 4 Jun 2018 10:34:52 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH] Cache find_sharded_spaces result References: <20180604125242.13445-1-avkhatskevich@tarantool.org> From: Vladislav Shpilevoy Message-ID: Date: Mon, 4 Jun 2018 17:34:49 +0300 MIME-Version: 1.0 In-Reply-To: <20180604125242.13445-1-avkhatskevich@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, AKhatskevich Pushed. On 04/06/2018 15:52, AKhatskevich wrote: > `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 = }. > -- > +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, > } >