From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id C681325FBD for ; Thu, 14 Jun 2018 09:52:00 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2R3eI-9L4DvH for ; Thu, 14 Jun 2018 09:52:00 -0400 (EDT) Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [94.100.177.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 822DC25FB0 for ; Thu, 14 Jun 2018 09:52:00 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH][vshard] Preserve route_map on router.cfg Date: Thu, 14 Jun 2018 16:51:40 +0300 Message-Id: <20180614135140.9786-1-avkhatskevich@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org Routes in `M.route_map` should be preserved to avoid redundant discovery. Closes #117 --- Branch: https://github.com/tarantool/vshard/tree/kh/gh-117-save-route-map Issue: https://github.com/tarantool/vshard/issues/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 61c83d4..5674e04 100644 --- a/vshard/router/init.lua +++ b/vshard/router/init.lua @@ -480,8 +480,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 @@ -494,6 +492,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