Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, olegrok@tarantool.org
Subject: [Tarantool-patches] [PATCH vshard 5/7] router: keep known bucket count stat up to date
Date: Fri,  1 May 2020 02:16:32 +0200	[thread overview]
Message-ID: <0bf7b575c617bf49904c4f6fc51a0b9f163e111a.1588292014.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1588292014.git.v.shpilevoy@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)

  parent reply	other threads:[~2020-05-01  0:16 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01  0:16 [Tarantool-patches] [PATCH vshard 0/7] Router extended discovery Vladislav Shpilevoy
2020-05-01  0:16 ` [Tarantool-patches] [PATCH vshard 1/7] test: print errors in a portable way Vladislav Shpilevoy
2020-05-01 16:58   ` Oleg Babin
2020-05-02 20:08     ` Vladislav Shpilevoy
2020-05-04 14:26       ` Oleg Babin
2020-05-01  0:16 ` [Tarantool-patches] [PATCH vshard 2/7] router: introduce discovery_mode Vladislav Shpilevoy
2020-05-01 16:59   ` Oleg Babin
2020-05-01  0:16 ` [Tarantool-patches] [PATCH vshard 3/7] test: disable router discovery for some tests Vladislav Shpilevoy
2020-05-01 17:00   ` Oleg Babin
2020-05-02 20:09     ` Vladislav Shpilevoy
2020-05-04 14:26       ` Oleg Babin
2020-05-01  0:16 ` [Tarantool-patches] [PATCH vshard 4/7] test: clear route map, respecting statistics Vladislav Shpilevoy
2020-05-01 17:00   ` Oleg Babin
2020-05-01  0:16 ` Vladislav Shpilevoy [this message]
2020-05-01 17:01   ` [Tarantool-patches] [PATCH vshard 5/7] router: keep known bucket count stat up to date Oleg Babin
2020-05-01  0:16 ` [Tarantool-patches] [PATCH vshard 6/7] router: make discovery smoother in a big cluster Vladislav Shpilevoy
2020-05-01 17:01   ` Oleg Babin
2020-05-02 20:12     ` Vladislav Shpilevoy
2020-05-04 14:26       ` Oleg Babin
2020-05-04 21:09         ` Vladislav Shpilevoy
2020-05-06  8:27           ` Oleg Babin
2020-05-07 22:45   ` Konstantin Osipov
2020-05-08 19:56     ` Vladislav Shpilevoy
2020-05-09  7:37       ` Konstantin Osipov
2020-05-01  0:16 ` [Tarantool-patches] [PATCH vshard 7/7] router: introduce discovery mode 'once' Vladislav Shpilevoy
2020-05-01 17:02   ` Oleg Babin
2020-05-02 20:12     ` Vladislav Shpilevoy
2020-05-04 14:27       ` Oleg Babin
2020-05-06 20:54 ` [Tarantool-patches] [PATCH vshard 0/7] Router extended discovery Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0bf7b575c617bf49904c4f6fc51a0b9f163e111a.1588292014.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=olegrok@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH vshard 5/7] router: keep known bucket count stat up to date' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox