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 CE0DA28742 for ; Wed, 1 Aug 2018 14:43:39 -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 1kYozD2bbrjw for ; Wed, 1 Aug 2018 14:43:39 -0400 (EDT) Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (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 30E92286B9 for ; Wed, 1 Aug 2018 14:43:39 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 1/3] Update only vshard part of a cfg on reload References: <37ba10547bf64fd880734b0550e4865f58dda14a.1533054045.git.avkhatskevich@tarantool.org> From: Vladislav Shpilevoy Message-ID: Date: Wed, 1 Aug 2018 21:43:35 +0300 MIME-Version: 1.0 In-Reply-To: <37ba10547bf64fd880734b0550e4865f58dda14a.1533054045.git.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 Thanks for the patch! See 4 comments below. On 31/07/2018 19:25, AKhatskevich wrote: > Box cfg could have been changed by a user and then overridden by > an old vshard config on reload. > > Since that commit, box part of a config is applied only when > it is explicitly passed to a `cfg` method. > > This change is important for the multiple routers feature. > --- > vshard/cfg.lua | 54 +++++++++++++++++++++++++------------------------ > vshard/router/init.lua | 18 ++++++++--------- > vshard/storage/init.lua | 53 ++++++++++++++++++++++++++++-------------------- > 3 files changed, 67 insertions(+), 58 deletions(-) > > diff --git a/vshard/cfg.lua b/vshard/cfg.lua > index bba12cc..8282086 100644 > --- a/vshard/cfg.lua > +++ b/vshard/cfg.lua > @@ -230,48 +230,50 @@ local non_dynamic_options = { > 'bucket_count', 'shard_index' > } > > +-- > +-- Deepcopy a config and split it into vshard_cfg and box_cfg. > +-- > +local function split_cfg(cfg) > + local vshard_field_map = {} > + for _, field in ipairs(cfg_template) do > + vshard_field_map[field[1]] = true > + end 1. vshard_field_map does not change ever. Why do you build it on each cfg? Please, store it in a module local variable like cfg_template. Or refactor cfg_template and other templates so they would be maps with parameter name as a key - looks like the most suitable solution. > + local vshard_cfg = {} > + local box_cfg = {} > + for k, v in pairs(cfg) do > + if vshard_field_map[k] then > + vshard_cfg[k] = table.deepcopy(v) > + else > + box_cfg[k] = table.deepcopy(v) > + end > + end > + return vshard_cfg, box_cfg > +end > + > diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua > index 102b942..75f5df9 100644 > --- a/vshard/storage/init.lua > +++ b/vshard/storage/init.lua > @@ -1500,13 +1500,17 @@ end > -------------------------------------------------------------------------------- > -- Configuration > -------------------------------------------------------------------------------- > +-- Private (not accessible by a user) reload indicator. > +local is_reload = false 2. Please, make this variable be parameter of storage_cfg and wrap public storage.cfg with a one-liner: storage.cfg = function(cfg, uuid) return storage_cfg(cfg, uuid, false) end I believe/hope you understand that such way to pass parameters, via global variables, is flawed by design. > @@ -1553,18 +1557,19 @@ local function storage_cfg(cfg, this_replica_uuid) > -- > -- If a master role of the replica is not changed, then > -- 'read_only' can be set right here. > - cfg.listen = cfg.listen or this_replica.uri > - if cfg.replication == nil and this_replicaset.master and not is_master then > - cfg.replication = {this_replicaset.master.uri} > + box_cfg.listen = box_cfg.listen or this_replica.uri > + if box_cfg.replication == nil and this_replicaset.master > + and not is_master then 3. Broken indentation. > + box_cfg.replication = {this_replicaset.master.uri} > else > - cfg.replication = {} > + box_cfg.replication = {} > end > if was_master == is_master then > - cfg.read_only = not is_master > + box_cfg.read_only = not is_master > end > if type(box.cfg) == 'function' then > - cfg.instance_uuid = this_replica.uuid > - cfg.replicaset_uuid = this_replicaset.uuid > + box_cfg.instance_uuid = this_replica.uuid > + box_cfg.replicaset_uuid = this_replicaset.uuid > else > local info = box.info > if this_replica_uuid ~= info.uuid then > @@ -1607,9 +1614,10 @@ local function storage_cfg(cfg, this_replica_uuid) > local_on_master_enable_prepare() > end > > - local box_cfg = table.copy(cfg) > - lcfg.remove_non_box_options(box_cfg) > - local ok, err = pcall(box.cfg, box_cfg) > + local ok, err = true, nil > + if not xis_reload then > + ok, err = pcall(box.cfg, box_cfg) > + end 4. The code below (if not ok then ...) can be moved inside 'if not is_reload' together with 'local ok, err' declaration. Please, do. > while M.errinj.ERRINJ_CFG_DELAY do > lfiber.sleep(0.01) > end