[tarantool-patches] Re: [PATCH 1/3] Update only vshard part of a cfg on reload

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Aug 1 21:43:35 MSK 2018


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




More information about the Tarantool-patches mailing list