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 6222C6ECDB; Sat, 18 Dec 2021 16:58:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6222C6ECDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1639835915; bh=E14gnBPv9wT029GCfMtWcEoj2drkhLDmRW5hnHspMQM=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iU/JvZ8jHnS2ccOXtV5L3pclGXYakntm7O6Ge+ciu9MYYrk0ZEHmn8hRSyEj5npY4 IHc6YFPFtQhGkDLoIvWxDyJ0dviojd6IdT1QLMugIrmqOFNkO7grrlDXnq9bqg9wap ZLZjaEUC9KJ/ywDqx9zLMIO7uOF0q9J9/bScOMyU= Received: from smtp42.i.mail.ru (smtp42.i.mail.ru [94.100.177.102]) (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 EBB346ECDB for ; Sat, 18 Dec 2021 16:58:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EBB346ECDB Received: by smtp42.i.mail.ru with esmtpa (envelope-from ) id 1myaDs-0007vh-7c; Sat, 18 Dec 2021 16:58:04 +0300 Message-ID: <3471e35a-309e-d014-f2b3-eb6376dedfa3@tarantool.org> Date: Sat, 18 Dec 2021 16:58:03 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org References: <9d767a02cabc032ff4ad478b4a51c0a254276569.1639700518.git.v.shpilevoy@tarantool.org> <405403ab-4eb9-56e9-1a3d-91035979c906@tarantool.org> In-Reply-To: <405403ab-4eb9-56e9-1a3d-91035979c906@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9B5397E24C93BDA67CDE94F05641003F359FF77D30AD3E306182A05F538085040CD89B8ECC84168142DE4024EE43A9C23558E45CAB765F6978295F45BE2DE32C1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE73AB734EB09B81F30C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE78887611F2F2455C9EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F28A221813F45A18EEA867341D23A5E553CC7F00164DA146DAFE8445B8C89999728AA50765F7900637D0FEED2715E18529389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC85DBE5CE84B47B0E4117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF96F1FB009BCCE8C5BA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B66E3E992EC305184376E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C289736CE4F78F08343847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A561DF77B8DFD39F02826C1A2D035637BDD5963E9B05539413D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759D2A03B9C34326B3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349FF8F8245A2FAA7B947D268A0A12ECA74438CAE8385CF7AA9CB467952AECF904FF2D4098A868B38D1D7E09C32AA3244C7FA9C093D9E64195E14906FBA79803E9A8CE788DE6831205729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojhDjsAWFBuTMhQmkeHdV9gA== X-Mailru-Sender: 583F1D7ACE8F49BD1042885CEC987B6B9EE4278325BA20B52DE4024EE43A9C2321401CF93FD6FA557019711D9D5B048E1458020726E2BC9FD5ECBA0B92C0A936CDC7563AA7CEBD2872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH vshard 2/5] storage: auto 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: Oleg Babin via Tarantool-patches Reply-To: Oleg Babin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for your fixes. LGTM. On 18.12.2021 02:10, Vladislav Shpilevoy wrote: > Thanks for the review! > > On 17.12.2021 12:09, Oleg Babin via Tarantool-patches wrote: >> 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? > Thanks, all fixed: > > ==================== > diff --git a/test/storage/storage.result b/test/storage/storage.result > index e83b34f..790ba11 100644 > --- a/test/storage/storage.result > +++ b/test/storage/storage.result > @@ -967,15 +967,15 @@ _ = test_run:switch('storage_1_a') > -- Leaving box.cfg() not called won't work because at 1.10 test-run somewhy > -- raises an error when try to start an instance without box.cfg(). It can only > -- be emulated. > -old_info = box.info > +old_cfg = box.cfg > --- > ... > -box.info = setmetatable({}, {__index = function() error('not configured') end}) > +assert(type(old_cfg) == 'table') > --- > +- true > ... > -assert(not pcall(function() return box.info.status end)) > +box.cfg = function(...) return old_cfg(...) end > --- > -- true > ... > ok, err = pcall(vshard.storage.call, 1, 'read', 'echo', {100}) > --- > @@ -984,11 +984,11 @@ assert(not ok and err.code == vshard.error.code.STORAGE_IS_DISABLED) > --- > - true > ... > -assert(err.message:match('box seem not to be configured') ~= nil) > +assert(err.message:match('box seems not to be configured') ~= nil) > --- > - true > ... > -box.info = old_info > +box.cfg = old_cfg > --- > ... > -- Disabled until box is loaded. > diff --git a/test/storage/storage.test.lua b/test/storage/storage.test.lua > index ff39f2f..8695636 100644 > --- a/test/storage/storage.test.lua > +++ b/test/storage/storage.test.lua > @@ -309,14 +309,14 @@ _ = test_run:switch('storage_1_a') > -- Leaving box.cfg() not called won't work because at 1.10 test-run somewhy > -- raises an error when try to start an instance without box.cfg(). It can only > -- be emulated. > -old_info = box.info > -box.info = setmetatable({}, {__index = function() error('not configured') end}) > -assert(not pcall(function() return box.info.status end)) > +old_cfg = box.cfg > +assert(type(old_cfg) == 'table') > +box.cfg = function(...) return old_cfg(...) end > > 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('box seem not to be configured') ~= nil) > -box.info = old_info > +assert(err.message:match('box seems not to be configured') ~= nil) > +box.cfg = old_cfg > > -- Disabled until box is loaded. > vshard.storage.internal.errinj.ERRINJ_CFG_DELAY = true > diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua > index d3c4e2a..77da663 100644 > --- a/vshard/storage/init.lua > +++ b/vshard/storage/init.lua > @@ -2953,14 +2953,11 @@ 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) > - if not ok then > - local msg = 'box seem not to be configured' > + if type(box.cfg) == 'function' then > + local msg = 'box seems not to be configured' > return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg)) > end > + local status = box.info.status > -- '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