From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org, olegrok@tarantool.org Subject: [Tarantool-patches] [PATCH vshard 3/5] storage: manual enable/disable Date: Fri, 17 Dec 2021 01:25:29 +0100 [thread overview] Message-ID: <27d5f55a68c72c6f7cb9f0d6eabaf787772f423f.1639700518.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1639700518.git.v.shpilevoy@tarantool.org> The patch introduces functions vshard.storage.enable()/disable(). They allow to control manually whether the instance can accept requests. It solves the following problems which were not covered by previous patches: - Even if box.cfg() is done, status is 'running', and vshard.storage.cfg() is finished, still user's application can be not ready to accept requests. For instance, it needs to create more functions and users on top of vshard. Then it wants to disable public requests until all preliminary work is done. - After all is enabled, fine, and dandy, still the instance might want to disable self in case of an emergency. Such as its config got broken or too outdated, desynced with a centric storage. vshard.storage.enable()/disable() can be called any time, before, during, and after vshard.storage.cfg() to solve these issues. Part of #298 --- test/storage/storage.result | 27 +++++++++++++++++++++++++++ test/storage/storage.test.lua | 12 ++++++++++++ vshard/storage/init.lua | 28 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/test/storage/storage.result b/test/storage/storage.result index e83b34f..e1b0d5d 100644 --- a/test/storage/storage.result +++ b/test/storage/storage.result @@ -1052,6 +1052,33 @@ assert(ok and res == 100) --- - true ... +-- +-- Manual enable/disable. +-- +vshard.storage.disable() +--- +... +ok, err = pcall(vshard.storage.call, 1, 'read', 'echo', {100}) +--- +... +assert(not ok and err.code == vshard.error.code.STORAGE_IS_DISABLED) +--- +- true +... +assert(err.message:match('storage is disabled explicitly') ~= nil) +--- +- true +... +vshard.storage.enable() +--- +... +ok, res = vshard.storage.call(1, 'read', 'echo', {100}) +--- +... +assert(ok and res == 100) +--- +- true +... _ = test_run:switch("default") --- ... diff --git a/test/storage/storage.test.lua b/test/storage/storage.test.lua index ff39f2f..e1127d3 100644 --- a/test/storage/storage.test.lua +++ b/test/storage/storage.test.lua @@ -342,6 +342,18 @@ f:join() ok, res = vshard.storage.call(1, 'read', 'echo', {100}) assert(ok and res == 100) +-- +-- Manual enable/disable. +-- +vshard.storage.disable() +ok, err = pcall(vshard.storage.call, 1, 'read', 'echo', {100}) +assert(not ok and err.code == vshard.error.code.STORAGE_IS_DISABLED) +assert(err.message:match('storage is disabled explicitly') ~= nil) + +vshard.storage.enable() +ok, res = vshard.storage.call(1, 'read', 'echo', {100}) +assert(ok and res == 100) + _ = test_run:switch("default") test_run:drop_cluster(REPLICASET_2) test_run:drop_cluster(REPLICASET_1) diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua index d3c4e2a..94e0c16 100644 --- a/vshard/storage/init.lua +++ b/vshard/storage/init.lua @@ -139,6 +139,9 @@ if not M then -- Flag whether box.info.status is acceptable. For instance, 'loading' -- is not. is_loaded = false, + -- Flag whether the instance is enabled manually. It is true by default + -- for backward compatibility with old vshard. + is_enabled = true, -- Reference to the function-proxy to most of the public functions. It -- allows to avoid 'if's in each function by adding expensive -- conditional checks in one rarely used version of the wrapper and no @@ -201,6 +204,11 @@ if not M then } else bucket_ref_new = ffi.typeof("struct bucket_ref") + + -- It is not set when reloaded from an old vshard version. + if M.is_enabled == nil then + M.is_enabled = true + end end -- @@ -2973,6 +2981,10 @@ local function storage_api_call_unsafe(func, arg1, arg2, arg3, arg4) local msg = 'storage is not configured' return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg)) end + if not M.is_enabled then + local msg = 'storage is disabled explicitly' + 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 @@ -2985,6 +2997,20 @@ local function storage_make_api(func) end end +local function storage_enable() + M.is_enabled = true +end + +-- +-- Disable can be used in case the storage entered a critical state in which +-- requests are not allowed. For instance, its config got broken or too old +-- compared to a centric config somewhere. +-- +local function storage_disable() + M.is_enabled = false + M.api_call_cache = storage_api_call_unsafe +end + -------------------------------------------------------------------------------- -- Module definition -------------------------------------------------------------------------------- @@ -3153,5 +3179,7 @@ return { cfg = function(cfg, uuid) return storage_cfg(cfg, uuid, false) end, on_master_enable = storage_make_api(on_master_enable), on_master_disable = storage_make_api(on_master_disable), + enable = storage_enable, + disable = storage_disable, internal = M, } -- 2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2021-12-17 0:27 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 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 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-12-17 11:09 ` [Tarantool-patches] [PATCH vshard 3/5] storage: manual enable/disable 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=27d5f55a68c72c6f7cb9f0d6eabaf787772f423f.1639700518.git.v.shpilevoy@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=olegrok@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH vshard 3/5] storage: manual 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