[Tarantool-patches] [PATCH vshard 5/7] router: keep known bucket count stat up to date

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri May 1 03:16:32 MSK 2020


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)



More information about the Tarantool-patches mailing list