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 389794696C8 for ; Fri, 1 May 2020 03:16:39 +0300 (MSK) From: Vladislav Shpilevoy Date: Fri, 1 May 2020 02:16:31 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH vshard 4/7] test: clear route map, respecting statistics List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, olegrok@tarantool.org Router's test sometimes need to wipe the route map. Simple reset it to {} may produce unexpected results, because route map is not just a table. It is also statistics in replicaset objects. Inconsistent statistics may lead to failing tests in surprising places. That becomes even more true with forthcoming patches, which rework the statistics a little bit so it actually affects something inside the router. Part of #210 --- test/router/router.result | 12 ++++-------- test/router/router.test.lua | 10 ++++------ vshard/router/init.lua | 9 +++++++++ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/test/router/router.result b/test/router/router.result index 267a3e9..df7be4a 100644 --- a/test/router/router.result +++ b/test/router/router.result @@ -175,7 +175,7 @@ vshard.router.bootstrap() -- -- gh-108: negative bucket count on discovery. -- -vshard.router.static.route_map = {} +vshard.router.static:_route_map_clear() --- ... rets = {} @@ -985,10 +985,8 @@ _ = test_run:cmd("setopt delimiter ';'") --- ... for i = 1, 100 do - local rs = vshard.router.static.route_map[i] - assert(rs) - rs.bucket_count = rs.bucket_count - 1 - vshard.router.static.route_map[i] = nil + assert(vshard.router.static.route_map[i]) + vshard.router.static:_bucket_reset(i) end; --- ... @@ -1243,9 +1241,7 @@ end; vshard.router.cfg(cfg); --- ... -vshard.router.static.route_map = {}; ---- -... +vshard.router.static:_route_map_clear() vshard.router.internal.errinj.ERRINJ_LONG_DISCOVERY = false; --- ... diff --git a/test/router/router.test.lua b/test/router/router.test.lua index c36026d..97dce49 100644 --- a/test/router/router.test.lua +++ b/test/router/router.test.lua @@ -73,7 +73,7 @@ vshard.router.bootstrap() -- -- gh-108: negative bucket count on discovery. -- -vshard.router.static.route_map = {} +vshard.router.static:_route_map_clear() rets = {} function do_echo() table.insert(rets, vshard.router.callro(1, 'echo', {1})) end f1 = fiber.create(do_echo) f2 = fiber.create(do_echo) @@ -331,10 +331,8 @@ _ = test_run:switch('router_1') -- _ = test_run:cmd("setopt delimiter ';'") for i = 1, 100 do - local rs = vshard.router.static.route_map[i] - assert(rs) - rs.bucket_count = rs.bucket_count - 1 - vshard.router.static.route_map[i] = nil + assert(vshard.router.static.route_map[i]) + vshard.router.static:_bucket_reset(i) end; _ = test_run:cmd("setopt delimiter ''"); calculate_known_buckets() @@ -453,7 +451,7 @@ while vshard.router.internal.errinj.ERRINJ_LONG_DISCOVERY ~= 'waiting' do fiber.sleep(0.02) end; vshard.router.cfg(cfg); -vshard.router.static.route_map = {}; +vshard.router.static:_route_map_clear() vshard.router.internal.errinj.ERRINJ_LONG_DISCOVERY = false; -- Do discovery iteration. Upload buckets from the -- first replicaset. diff --git a/vshard/router/init.lua b/vshard/router/init.lua index ebd8356..43b2ef7 100644 --- a/vshard/router/init.lua +++ b/vshard/router/init.lua @@ -112,6 +112,13 @@ local function bucket_reset(router, bucket_id) router.route_map[bucket_id] = nil end +local function route_map_clear(router) + router.route_map = {} + for _, rs in pairs(router.replicasets) do + rs.bucket_count = 0 + end +end + -- -- Increase/decrease number of routers which require to collect -- a lua garbage and change state of the `lua_gc` fiber. @@ -1173,6 +1180,8 @@ local router_mt = { bucket_discovery = bucket_discovery; discovery_wakeup = discovery_wakeup; discovery_set = discovery_set, + _route_map_clear = route_map_clear, + _bucket_reset = bucket_reset, } } -- 2.21.1 (Apple Git-122.3)