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 12C406ECDB; Fri, 17 Dec 2021 14:10:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 12C406ECDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1639739401; bh=abS0qjNeex2vuF936BhByMoxS8ecZluCRP98JTil5Lk=; 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=MOPBo7qAUwePdDlxHlCa8NWe5/7VTY83JMgwmWbdE44dFJwxdyexxB2xf8LrXqQrK tSN6o7hNm/kM7EeIPSGuAnL99XQwct6m+2FpzCEOTVrJDROex0BT1x+Wo7YUzDU7YC xAlAGiSJoVK+R9UCvBA7fxNCiZ6hZWFqy8EH92ic= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (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 31AAA6ECDB for ; Fri, 17 Dec 2021 14:09:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 31AAA6ECDB Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1myB7E-0007ip-GW; Fri, 17 Dec 2021 14:09:32 +0300 Message-ID: Date: Fri, 17 Dec 2021 14:09:32 +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> In-Reply-To: <9d767a02cabc032ff4ad478b4a51c0a254276569.1639700518.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9B5397E24C93BDA67420B45F6C0BD1571DFA6B9070FC755DB182A05F538085040F50BE804F02088AC6C961CFD6963DAEF773C94F679932CA547554D72320ADE62 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE768C1628CEA2C3A5EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AE01C1A20EF0A1348638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8FA004DEAEDAB90548F3BF759400817BD117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2EE5AD8F952D28FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FC293FA0ACC26973243AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F7900637CEF0D295B2B773C0D81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16B42539A7722CA490CB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A5C23159469959E2153D9BA7A4F933B13DC568F8F189365699D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759D2A03B9C34326B3410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34128DEC38EFF4BE5AD1A210D781D7B677FB4C6809EAA786B0DAAC4AB06A3F892B106A2E40972CFA261D7E09C32AA3244C733A4B6F32CF2556DF7E62E88051BEABE646F07CC2D4F3D8729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojieEIankJUzoctC2gRuDLQQ== X-Mailru-Sender: 583F1D7ACE8F49BD1042885CEC987B6B08FBD84F61FF88E96C961CFD6963DAEFEFC4EB6826DC22487019711D9D5B048E1458020726E2BC9FD5ECBA0B92C0A936CDC7563AA7CEBD2872D6B4FCE48DF648AE208404248635DF 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 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, > }