Tarantool development patches archive
 help / color / mirror / Atom feed
From: Oleg Babin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH vshard 2/5] storage: auto enable/disable
Date: Fri, 17 Dec 2021 14:09:32 +0300	[thread overview]
Message-ID: <f59f0248-e4d2-c26e-3af0-804c4cc2f172@tarantool.org> (raw)
In-Reply-To: <9d767a02cabc032ff4ad478b4a51c0a254276569.1639700518.git.v.shpilevoy@tarantool.org>

Thanks for your patch. See my two nits below.

On 17.12.2021 03:25, Vladislav Shpilevoy wrote:
> +--------------------------------------------------------------------------------
> +-- Public API protection
> +--------------------------------------------------------------------------------
> +
> +--
> +-- Arguments are listed explicitly instead of '...' because the latter does not
> +-- jit.
> +--
> +local function storage_api_call_safe(func, arg1, arg2, arg3, arg4)
> +    return func(arg1, arg2, arg3, arg4)
> +end
> +
> +--
> +-- Unsafe proxy is loaded with protections. But it is used rarely and only in
> +-- the beginning of instance's lifetime.
> +--
> +local function storage_api_call_unsafe(func, arg1, arg2, arg3, arg4)
> +    -- box.info is quite expensive. Avoid calling it again when the instance
> +    -- is finally loaded.
> +    if not M.is_loaded then
> +        -- box.info raises an error until box.cfg() is started.
> +        local ok, status = pcall(function()
> +            return box.info.status
> +        end)

nit: It could be changed to type(box.cfg) == 'function'. I'd call it 
"common" pattern to check that box is not yet configured.

> +        if not ok then
> +            local msg = 'box seem not to be configured'

nit: seem -> seems?


> +            return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
> +        end
> +        -- 'Orphan' is allowed because even if a replica is an orphan, it still
> +        -- could be up to date. Just not all other replicas are connected.
> +        if status ~= 'running' and status ~= 'orphan' then
> +            local msg = ('instance status is "%s"'):format(status)
> +            return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
> +        end
> +        M.is_loaded = true
> +    end
> +    if not M.is_configured then
> +        local msg = 'storage is not configured'
> +        return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
> +    end
> +    M.api_call_cache = storage_api_call_safe
> +    return func(arg1, arg2, arg3, arg4)
> +end
> +
> +M.api_call_cache = storage_api_call_unsafe
> +
> +local function storage_make_api(func)
> +    return function(arg1, arg2, arg3, arg4)
> +        return M.api_call_cache(func, arg1, arg2, arg3, arg4)
> +    end
> +end
> +
>   --------------------------------------------------------------------------------
>   -- Module definition
>   --------------------------------------------------------------------------------
> @@ -3021,44 +3091,67 @@ M.bucket_are_all_rw = bucket_are_all_rw_public
>   M.bucket_generation_wait = bucket_generation_wait
>   lregistry.storage = M
>   
> +--
> +-- Not all methods are public here. Private methods should not be exposed if
> +-- possible. At least not without notable difference in naming.
> +--
>   return {
> -    sync = sync,
> -    bucket_force_create = bucket_force_create,
> -    bucket_force_drop = bucket_force_drop,
> -    bucket_collect = bucket_collect,
> -    bucket_recv = bucket_recv,
> -    bucket_send = bucket_send,
> -    bucket_stat = bucket_stat,
> -    bucket_pin = bucket_pin,
> -    bucket_unpin = bucket_unpin,
> -    bucket_ref = bucket_ref,
> -    bucket_unref = bucket_unref,
> -    bucket_refro = bucket_refro,
> -    bucket_refrw = bucket_refrw,
> -    bucket_unrefro = bucket_unrefro,
> -    bucket_unrefrw = bucket_unrefrw,
> -    bucket_delete_garbage = bucket_delete_garbage,
> -    garbage_collector_wakeup = garbage_collector_wakeup,
> -    rebalancer_wakeup = rebalancer_wakeup,
> -    rebalancer_apply_routes = rebalancer_apply_routes,
> -    rebalancer_disable = rebalancer_disable,
> -    rebalancer_enable = rebalancer_enable,
> -    is_locked = is_this_replicaset_locked,
> -    rebalancing_is_in_progress = rebalancing_is_in_progress,
> -    recovery_wakeup = recovery_wakeup,
> -    call = storage_call,
> -    _call = service_call,
> +    --
> +    -- Bucket methods.
> +    --
> +    bucket_force_create = storage_make_api(bucket_force_create),
> +    bucket_force_drop = storage_make_api(bucket_force_drop),
> +    bucket_collect = storage_make_api(bucket_collect),
> +    bucket_recv = storage_make_api(bucket_recv),
> +    bucket_send = storage_make_api(bucket_send),
> +    bucket_stat = storage_make_api(bucket_stat),
> +    bucket_pin = storage_make_api(bucket_pin),
> +    bucket_unpin = storage_make_api(bucket_unpin),
> +    bucket_ref = storage_make_api(bucket_ref),
> +    bucket_unref = storage_make_api(bucket_unref),
> +    bucket_refro = storage_make_api(bucket_refro),
> +    bucket_refrw = storage_make_api(bucket_refrw),
> +    bucket_unrefro = storage_make_api(bucket_unrefro),
> +    bucket_unrefrw = storage_make_api(bucket_unrefrw),
> +    bucket_delete_garbage = storage_make_api(bucket_delete_garbage),
> +    _bucket_delete_garbage = bucket_delete_garbage,
> +    buckets_info = storage_make_api(storage_buckets_info),
> +    buckets_count = storage_make_api(bucket_count_public),
> +    buckets_discovery = storage_make_api(buckets_discovery),
> +    --
> +    -- Garbage collector.
> +    --
> +    garbage_collector_wakeup = storage_make_api(garbage_collector_wakeup),
> +    --
> +    -- Rebalancer.
> +    --
> +    rebalancer_wakeup = storage_make_api(rebalancer_wakeup),
> +    rebalancer_apply_routes = storage_make_api(rebalancer_apply_routes),
> +    rebalancer_disable = storage_make_api(rebalancer_disable),
> +    rebalancer_enable = storage_make_api(rebalancer_enable),
> +    rebalancing_is_in_progress = storage_make_api(rebalancing_is_in_progress),
> +    rebalancer_request_state = storage_make_api(rebalancer_request_state),
> +    _rebalancer_request_state = rebalancer_request_state,
> +    --
> +    -- Recovery.
> +    --
> +    recovery_wakeup = storage_make_api(recovery_wakeup),
> +    --
> +    -- Instance info.
> +    --
> +    is_locked = storage_make_api(is_this_replicaset_locked),
> +    info = storage_make_api(storage_info),
> +    sharded_spaces = storage_make_api(storage_sharded_spaces),
> +    _sharded_spaces = storage_sharded_spaces,
> +    module_version = function() return M.module_version end,
> +    --
> +    -- Miscellaneous.
> +    --
> +    call = storage_make_api(storage_call),
> +    _call = storage_make_api(service_call),
> +    sync = storage_make_api(sync),
>       cfg = function(cfg, uuid) return storage_cfg(cfg, uuid, false) end,
> -    info = storage_info,
> -    buckets_info = storage_buckets_info,
> -    buckets_count = bucket_count_public,
> -    buckets_discovery = buckets_discovery,
> -    rebalancer_request_state = rebalancer_request_state,
> +    on_master_enable = storage_make_api(on_master_enable),
> +    on_master_disable = storage_make_api(on_master_disable),
>       internal = M,
> -    on_master_enable = on_master_enable,
> -    on_master_disable = on_master_disable,
> -    sharded_spaces = function()
> -        return table.deepcopy(find_sharded_spaces())
> -    end,
> -    module_version = function() return M.module_version end,
>   }

  reply	other threads:[~2021-12-17 11:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-17  0:25 [Tarantool-patches] [PATCH vshard 0/5] Router backoff, storage disable Vladislav Shpilevoy via Tarantool-patches
2021-12-17  0:25 ` [Tarantool-patches] [PATCH vshard 1/5] router: backoff on some box errors Vladislav Shpilevoy via Tarantool-patches
2021-12-17 11:09   ` Oleg Babin via Tarantool-patches
2021-12-17 23:10     ` Vladislav Shpilevoy via Tarantool-patches
2021-12-18 13:57       ` Oleg Babin via Tarantool-patches
2021-12-17  0:25 ` [Tarantool-patches] [PATCH vshard 2/5] storage: auto enable/disable Vladislav Shpilevoy via Tarantool-patches
2021-12-17 11:09   ` Oleg Babin via Tarantool-patches [this message]
2021-12-17 23:10     ` Vladislav Shpilevoy via Tarantool-patches
2021-12-18 13:58       ` Oleg Babin via Tarantool-patches
2021-12-17  0:25 ` [Tarantool-patches] [PATCH vshard 3/5] storage: manual enable/disable Vladislav Shpilevoy via Tarantool-patches
2021-12-17 11:09   ` Oleg Babin via Tarantool-patches
2021-12-17  0:25 ` [Tarantool-patches] [PATCH vshard 4/5] error: introduce from_string Vladislav Shpilevoy via Tarantool-patches
2021-12-17 11:09   ` Oleg Babin via Tarantool-patches
2021-12-17 23:10     ` Vladislav Shpilevoy via Tarantool-patches
2021-12-17  0:25 ` [Tarantool-patches] [PATCH vshard 5/5] router: backoff on storage being disabled Vladislav Shpilevoy via Tarantool-patches
2021-12-17 11:09   ` Oleg Babin via Tarantool-patches
2021-12-18 13:58 ` [Tarantool-patches] [PATCH vshard 0/5] Router backoff, storage disable Oleg Babin via Tarantool-patches
2021-12-20 23:52 ` Vladislav Shpilevoy via Tarantool-patches

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=f59f0248-e4d2-c26e-3af0-804c4cc2f172@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=olegrok@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH vshard 2/5] storage: auto enable/disable' \
    /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