From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp41.i.mail.ru (smtp41.i.mail.ru [94.100.177.101]) (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 5B9754696C3 for ; Fri, 1 May 2020 03:16:40 +0300 (MSK) From: Vladislav Shpilevoy Date: Fri, 1 May 2020 02:16:32 +0200 Message-Id: <0bf7b575c617bf49904c4f6fc51a0b9f163e111a.1588292014.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH vshard 5/7] router: keep known bucket count stat up to date List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, olegrok@tarantool.org Known bucket count was calculated on demand when router.info() was called. Now it is going to be needed for advanced discovery. The optimization will be that if known bucket count is equal to total bucket count, the discovery enters 'idle' mode, when it works much less aggressive, therefore reducing load on the cluster. Which can be quite big when bucket count is huge. Part of #210 --- vshard/router/init.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vshard/router/init.lua b/vshard/router/init.lua index 43b2ef7..6d88153 100644 --- a/vshard/router/init.lua +++ b/vshard/router/init.lua @@ -69,6 +69,7 @@ local ROUTER_TEMPLATE = { discovery_mode = nil, -- Bucket count stored on all replicasets. total_bucket_count = 0, + known_bucket_count = 0, -- Boolean lua_gc state (create periodic gc task). collect_lua_garbage = nil, -- Timeout after which a ping is considered to be @@ -96,6 +97,8 @@ local function bucket_set(router, bucket_id, rs_uuid) if old_replicaset ~= replicaset then if old_replicaset then old_replicaset.bucket_count = old_replicaset.bucket_count - 1 + else + router.known_bucket_count = router.known_bucket_count + 1 end replicaset.bucket_count = replicaset.bucket_count + 1 end @@ -108,12 +111,14 @@ local function bucket_reset(router, bucket_id) local replicaset = router.route_map[bucket_id] if replicaset then replicaset.bucket_count = replicaset.bucket_count - 1 + router.known_bucket_count = router.known_bucket_count - 1 end router.route_map[bucket_id] = nil end local function route_map_clear(router) router.route_map = {} + router.known_bucket_count = 0 for _, rs in pairs(router.replicasets) do rs.bucket_count = 0 end @@ -217,6 +222,8 @@ local function discovery_handle_buckets(router, replicaset, buckets) affected[old_rs] = bc end old_rs.bucket_count = bc - 1 + else + router.known_bucket_count = router.known_bucket_count + 1 end router.route_map[bucket_id] = replicaset end @@ -939,7 +946,6 @@ local function router_info(router) status = consts.STATUS.GREEN, } local bucket_info = state.bucket - local known_bucket_count = 0 for rs_uuid, replicaset in pairs(router.replicasets) do -- Replicaset info parameters: -- * master instance info; @@ -1007,7 +1013,6 @@ local function router_info(router) -- available for any requests; -- * unknown: how many buckets are unknown - a router -- doesn't know their replicasets. - known_bucket_count = known_bucket_count + replicaset.bucket_count if rs_info.master.status ~= 'available' then if rs_info.replica.status ~= 'available' then rs_info.bucket.unreachable = replicaset.bucket_count @@ -1028,7 +1033,7 @@ local function router_info(router) -- If a bucket is unreachable, then replicaset is -- unreachable too and color already is red. end - bucket_info.unknown = router.total_bucket_count - known_bucket_count + bucket_info.unknown = router.total_bucket_count - router.known_bucket_count if bucket_info.unknown > 0 then state.status = math.max(state.status, consts.STATUS.YELLOW) table.insert(state.alerts, lerror.alert(lerror.code.UNKNOWN_BUCKETS, -- 2.21.1 (Apple Git-122.3)