Skip to content

Commit d373701

Browse files
committed
router: allow calling info when disabled
A router may be marked as disabled, which previously made it difficult to obtain status information from the component. This patch allows calling vshard.router.info even when the component is disabled. The function now also returns a new boolean field is_enabled indicating whether the component is currently enabled. Follow-up #565 @TarantoolBot document Title: vshard: router.info behavior change vshard.router.info() This function can now be called even when the router is disabled. It now also returns a new boolean field is_enabled indicating whether the component is currently enabled.
1 parent b2bcf17 commit d373701

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

test/failover/cluster_changes.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ info
127127
available_rw: 0
128128
identification_mode: uuid_as_key
129129
status: 1
130+
is_enabled: true
130131
alerts:
131132
- ['UNKNOWN_BUCKETS', '3000 buckets are not discovered']
132133
...
@@ -278,6 +279,7 @@ info
278279
available_rw: 0
279280
identification_mode: uuid_as_key
280281
status: 3
282+
is_enabled: true
281283
alerts:
282284
- ['MISSING_MASTER', 'Master is not configured for replicaset 739fe4fb-2850-4cde-9637-10150724c5eb']
283285
- ['MISSING_MASTER', 'Master is not configured for replicaset 832bbba0-9699-4aa1-907d-c7c7af61f5c9']
@@ -384,6 +386,7 @@ info
384386
available_rw: 0
385387
identification_mode: uuid_as_key
386388
status: 1
389+
is_enabled: true
387390
alerts:
388391
- ['UNKNOWN_BUCKETS', '3000 buckets are not discovered']
389392
...

test/rebalancer/restart_during_rebalancing.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ info
285285
available_rw: 200
286286
identification_mode: uuid_as_key
287287
status: 0
288+
is_enabled: true
288289
alerts: []
289290
...
290291
util.stop_loading()

test/router-luatest/router_2_2_test.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,3 +1265,37 @@ g.test_log_ratelimiter_is_dropped_on_disable_of_the_service = function(g)
12651265
_G.ratelimit = nil
12661266
end, {name})
12671267
end
1268+
1269+
g.test_info_disable_consistency = function(g)
1270+
local router = vtest.router_new(g, 'router_1')
1271+
router:exec(function(cfg)
1272+
ivtest.clear_test_cfg_options(cfg)
1273+
-- Do not allow router's configuration to complete.
1274+
_G.ivshard.router.internal.errinj.ERRINJ_CFG_DELAY = true
1275+
local fiber_cfg = ifiber.create(ivshard.router.cfg, cfg)
1276+
fiber_cfg:set_joinable(true)
1277+
local routers = ivshard.router.internal.routers
1278+
local _, err = pcall(routers._static_router.info,
1279+
routers._static_router)
1280+
ilt.assert_not_equals(err, nil)
1281+
ilt.assert_str_contains(err.message, 'router is not configured')
1282+
1283+
-- Unblock router's configuration and wait until it's finished.
1284+
_G.ivshard.router.internal.errinj.ERRINJ_CFG_DELAY = false
1285+
fiber_cfg:join()
1286+
local res = ivshard.router:info()
1287+
ilt.assert_not_equals(res, nil)
1288+
ilt.assert(res.is_enabled)
1289+
1290+
ivshard.router:disable()
1291+
res = ivshard.router:info()
1292+
ilt.assert_not_equals(res, nil)
1293+
ilt.assert_not(res.is_enabled)
1294+
1295+
ivshard.router:enable()
1296+
res = ivshard.router:info()
1297+
t.assert_not_equals(res, nil)
1298+
t.assert(res.is_enabled)
1299+
end, {global_cfg})
1300+
vtest.drop_instance(g, router)
1301+
end

test/router/reconnect_to_master.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ vshard.router.info()
149149
available_rw: 0
150150
identification_mode: uuid_as_key
151151
status: 2
152+
is_enabled: true
152153
alerts:
153154
- ['UNREACHABLE_MASTER', 'Master of replicaset cbf06940-0790-498b-948d-042b62cf3d29
154155
is unreachable: disconnected']

test/router/router.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ vshard.router.info()
220220
available_rw: 1
221221
identification_mode: uuid_as_key
222222
status: 1
223+
is_enabled: true
223224
alerts:
224225
- ['UNKNOWN_BUCKETS', '2999 buckets are not discovered']
225226
...
@@ -1076,6 +1077,7 @@ info
10761077
available_rw: 3000
10771078
identification_mode: uuid_as_key
10781079
status: 0
1080+
is_enabled: true
10791081
alerts: []
10801082
...
10811083
-- Remove replica and master connections to trigger alert

vshard/router/init.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,7 @@ local function router_info(router, opts)
15461546
router.discovery_service:info(),
15471547
}
15481548
end
1549+
state.is_enabled = router.is_enabled
15491550
return state
15501551
end
15511552

@@ -1661,31 +1662,32 @@ end
16611662
-- Public API protection
16621663
--------------------------------------------------------------------------------
16631664

1664-
local function router_api_call_safe(func, router, ...)
1665+
local function router_api_call_safe(func, router, _opts, ...)
16651666
return func(router, ...)
16661667
end
16671668

16681669
--
16691670
-- Unsafe proxy is loaded with protections. But it is used rarely and only in
16701671
-- the beginning of instance's lifetime.
16711672
--
1672-
local function router_api_call_unsafe(func, router, ...)
1673+
local function router_api_call_unsafe(func, router, opts, ...)
16731674
-- Router can be started on instance with unconfigured box.cfg.
16741675
if not router.is_configured then
16751676
local msg = 'router is not configured'
16761677
return error(lerror.vshard(lerror.code.ROUTER_IS_DISABLED, msg))
16771678
end
1678-
if not router.is_enabled then
1679+
local is_disabled_skip = opts and opts.is_disabled_skip
1680+
if not router.is_enabled and not is_disabled_skip then
16791681
local msg = 'router is disabled explicitly'
16801682
return error(lerror.vshard(lerror.code.ROUTER_IS_DISABLED, msg))
16811683
end
16821684
router.api_call_cache = router_api_call_safe
16831685
return func(router, ...)
16841686
end
16851687

1686-
local function router_make_api(func)
1688+
local function router_make_api(func, opts)
16871689
return function(router, ...)
1688-
return router.api_call_cache(func, router, ...)
1690+
return router.api_call_cache(func, router, opts, ...)
16891691
end
16901692
end
16911693

@@ -1709,7 +1711,7 @@ end
17091711
local router_mt = {
17101712
__index = {
17111713
cfg = function(router, cfg) return router_cfg_fiber_safe(router, cfg, false) end,
1712-
info = router_make_api(router_info),
1714+
info = router_make_api(router_info, {is_disabled_skip = true}),
17131715
buckets_info = router_make_api(router_buckets_info),
17141716
call = router_make_api(router_call),
17151717
callro = router_make_api(router_callro),

0 commit comments

Comments
 (0)