Tarantool development patches archive
 help / color / mirror / Atom feed
From: AKhatskevich <avkhatskevich@tarantool.org>
To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH 1/2] Preserve route_map on router.cfg
Date: Fri, 15 Jun 2018 15:47:58 +0300	[thread overview]
Message-ID: <344d2c601d489836268d55e0f9207f2a6a577f81.1529066485.git.avkhatskevich@tarantool.org> (raw)
In-Reply-To: <cover.1529066485.git.avkhatskevich@tarantool.org>
In-Reply-To: <cover.1529066485.git.avkhatskevich@tarantool.org>

Routes in `M.route_map` can be preserved during reconfigure process.
This is necessary to prevent a dramatic performance degradation just
	after reconfugure and reload.

Closes #117
---
 test/router/router.result   | 42 ++++++++++++++++++++++++++++++++++++++++++
 test/router/router.test.lua | 24 ++++++++++++++++++++++++
 vshard/router/init.lua      |  7 +++++--
 3 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/test/router/router.result b/test/router/router.result
index 2ee1bff..5643f3e 100644
--- a/test/router/router.result
+++ b/test/router/router.result
@@ -1057,6 +1057,48 @@ error_messages
 - - Use replica:is_connected(...) instead of replica.is_connected(...)
   - Use replica:safe_uri(...) instead of replica.safe_uri(...)
 ...
+--
+-- gh-117: Preserve route_map on router.cfg.
+--
+bucket_to_old_rs = {}
+---
+...
+bucket_cnt = 0
+---
+...
+test_run:cmd("setopt delimiter ';'")
+---
+- true
+...
+for bucket, rs in pairs(vshard.router.internal.route_map) do
+    bucket_to_old_rs[bucket] = rs
+    bucket_cnt = bucket_cnt + 1
+end;
+---
+...
+bucket_cnt;
+---
+- 3000
+...
+vshard.router.cfg(cfg);
+---
+...
+for bucket, old_rs in pairs(bucket_to_old_rs) do
+    local old_uuid = old_rs.uuid
+    local rs = vshard.router.internal.route_map[bucket]
+    if not rs or not old_uuid == rs.uuid then
+        error("Bucket lost during reconfigure.")
+    end
+    if rs == old_rs then
+        error("route_map was not updataed.")
+    end
+end;
+---
+...
+test_run:cmd("setopt delimiter ''");
+---
+- true
+...
 _ = test_run:cmd("switch default")
 ---
 ...
diff --git a/test/router/router.test.lua b/test/router/router.test.lua
index fae8e24..106f3d8 100644
--- a/test/router/router.test.lua
+++ b/test/router/router.test.lua
@@ -389,6 +389,30 @@ end;
 test_run:cmd("setopt delimiter ''");
 error_messages
 
+--
+-- gh-117: Preserve route_map on router.cfg.
+--
+bucket_to_old_rs = {}
+bucket_cnt = 0
+test_run:cmd("setopt delimiter ';'")
+for bucket, rs in pairs(vshard.router.internal.route_map) do
+    bucket_to_old_rs[bucket] = rs
+    bucket_cnt = bucket_cnt + 1
+end;
+bucket_cnt;
+vshard.router.cfg(cfg);
+for bucket, old_rs in pairs(bucket_to_old_rs) do
+    local old_uuid = old_rs.uuid
+    local rs = vshard.router.internal.route_map[bucket]
+    if not rs or not old_uuid == rs.uuid then
+        error("Bucket lost during reconfigure.")
+    end
+    if rs == old_rs then
+        error("route_map was not updataed.")
+    end
+end;
+test_run:cmd("setopt delimiter ''");
+
 _ = test_run:cmd("switch default")
 test_run:drop_cluster(REPLICASET_2)
 
diff --git a/vshard/router/init.lua b/vshard/router/init.lua
index 21093e5..7e765fa 100644
--- a/vshard/router/init.lua
+++ b/vshard/router/init.lua
@@ -475,8 +475,6 @@ local function router_cfg(cfg)
     log.info("Box has been configured")
     M.total_bucket_count = total_bucket_count
     M.collect_lua_garbage = collect_lua_garbage
-    -- TODO: update existing route map in-place
-    M.route_map = {}
     M.replicasets = new_replicasets
     -- Move connections from an old configuration to a new one.
     -- It must be done with no yields to prevent usage both of not
@@ -489,6 +487,11 @@ local function router_cfg(cfg)
     for _, replicaset in pairs(new_replicasets) do
         replicaset:connect_all()
     end
+    -- Update existing route map in-place.
+    for bucket, rs in pairs(M.route_map) do
+        M.route_map[bucket] = M.replicasets[rs.uuid]
+    end
+
     lreplicaset.wait_masters_connect(new_replicasets)
     if M.failover_fiber == nil then
         log.info('Start failover fiber')
-- 
2.14.1

  reply	other threads:[~2018-06-15 12:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-15 12:47 [tarantool-patches] [PATCH 0/2][vshard] preserve route map AKhatskevich
2018-06-15 12:47 ` AKhatskevich [this message]
2018-06-21 12:54   ` [tarantool-patches] Re: [PATCH 1/2] Preserve route_map on router.cfg Vladislav Shpilevoy
2018-06-25 12:48     ` Alex Khatskevich
2018-06-15 12:47 ` [tarantool-patches] [PATCH 2/2] Fix discovery/reconfigure race AKhatskevich
2018-06-21 12:54   ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-25 12:48     ` Alex Khatskevich
2018-06-26 11:11       ` Vladislav Shpilevoy
2018-06-26 14:03         ` Alex Khatskevich
2018-06-27 11:45           ` Vladislav Shpilevoy
2018-06-27 19:50             ` Alex Khatskevich
2018-06-28 19:41               ` Vladislav Shpilevoy
2018-06-21 12:54 ` [tarantool-patches] Re: [PATCH 0/2][vshard] preserve route map Vladislav Shpilevoy
2018-06-25 11:52   ` Alex Khatskevich

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=344d2c601d489836268d55e0f9207f2a6a577f81.1529066485.git.avkhatskevich@tarantool.org \
    --to=avkhatskevich@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 1/2] Preserve route_map on router.cfg' \
    /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