Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org,
	AKhatskevich <avkhatskevich@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 1/3] Update only vshard part of a cfg on reload
Date: Wed, 1 Aug 2018 21:43:35 +0300	[thread overview]
Message-ID: <be620274-9bf4-cf01-b19d-b83a1a1f610d@tarantool.org> (raw)
In-Reply-To: <37ba10547bf64fd880734b0550e4865f58dda14a.1533054045.git.avkhatskevich@tarantool.org>

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

  reply	other threads:[~2018-08-01 18:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31 16:25 [tarantool-patches] [PATCH 0/3] multiple routers AKhatskevich
2018-07-31 16:25 ` [tarantool-patches] [PATCH 1/3] Update only vshard part of a cfg on reload AKhatskevich
2018-08-01 18:43   ` Vladislav Shpilevoy [this message]
2018-08-03 20:03     ` [tarantool-patches] " Alex Khatskevich
2018-08-06 17:03       ` Vladislav Shpilevoy
2018-08-07 13:19         ` Alex Khatskevich
2018-08-08 11:17           ` Vladislav Shpilevoy
2018-07-31 16:25 ` [tarantool-patches] [PATCH 2/3] Move lua gc to a dedicated module AKhatskevich
2018-08-01 18:43   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-03 20:04     ` Alex Khatskevich
2018-08-06 17:03       ` Vladislav Shpilevoy
2018-08-08 11:17       ` Vladislav Shpilevoy
2018-07-31 16:25 ` [tarantool-patches] [PATCH 3/3] Introduce multiple routers feature AKhatskevich
2018-08-01 18:43   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-03 20:05     ` Alex Khatskevich
2018-08-06 17:03       ` Vladislav Shpilevoy
2018-08-07 13:18         ` Alex Khatskevich
2018-08-08 12:28           ` Vladislav Shpilevoy
2018-08-08 14:04             ` Alex Khatskevich
2018-08-08 15:37               ` Vladislav Shpilevoy
2018-08-01 14:30 ` [tarantool-patches] [PATCH] Check self arg passed for router objects AKhatskevich
2018-08-03 20:07 ` [tarantool-patches] [PATCH] Refactor config templates AKhatskevich
2018-08-06 15:49   ` [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=be620274-9bf4-cf01-b19d-b83a1a1f610d@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=avkhatskevich@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 1/3] Update only vshard part of a cfg on reload' \
    /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