From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 4F4B76ECC0; Fri, 17 Dec 2021 03:27:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F4B76ECC0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1639700835; bh=olPzYEzlaJG9YZIyU/n/tcJj5fJrDMQTA576lx9MYZQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jh28fU6Tm8J9MMcD/O+LPGvM7nwrrkSURn/Cw0Y32XqdbU4r350yu0wXktUY7tN87 WgE87NfFXTOWKtDY5ntK82WTekbVeonsRGswvpxlD4LGNggtbdRd9yrCsKezTAPcd+ FFJp262zCrOiKV3i4XjXaDO2ctmYzHW+ehsTfEuo= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EBDC56ECDC for ; Fri, 17 Dec 2021 03:25:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EBDC56ECDC Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1my143-0007At-6a; Fri, 17 Dec 2021 03:25:35 +0300 To: tarantool-patches@dev.tarantool.org, olegrok@tarantool.org Date: Fri, 17 Dec 2021 01:25:29 +0100 Message-Id: <27d5f55a68c72c6f7cb9f0d6eabaf787772f423f.1639700518.git.v.shpilevoy@tarantool.org> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9B5397E24C93BDA67437C98EFFD86422F45ABD0E79110D478182A05F538085040835A1A98766971EA3E7A70CDBC25ADCBAB50341A25CE0BC3BBEB785991F343D9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7081BBE264C6D7F42EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375A514678F9DF65078638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D859390F37B6887335EBFDB9F441033F7E117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352026055571C92BF10FBDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FC3163393FEE54070F9D80E07F76ECF39A6024DF4F6ACCAAF9B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBD215BE4436AF2686DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34BF5454112BD5BFD779B0D0967E3CDEF602C210A8F2DB8EDE766380C472A4037A81AE8A802FE78F631D7E09C32AA3244C6BCE94442F26A6F1F778322E628300F9E3D93501275E802F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojieEIankJUzqHXdun2Qo0zA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D7DB0AA48D3F871F3B7E2F0C6149001B73841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E25FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH vshard 3/5] storage: manual enable/disable X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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)