Skip to content

Commit 989cc85

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 dc3d4f0 commit 989cc85

File tree

6 files changed

+49
-5
lines changed

6 files changed

+49
-5
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 & 5 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

@@ -1670,23 +1671,25 @@ end
16701671
-- the beginning of instance's lifetime.
16711672
--
16721673
local function router_api_call_unsafe(func, router, arg1, arg2,
1673-
arg3, arg4, arg5)
1674+
arg3, arg4, arg5, opts)
16741675
-- Router can be started on instance with unconfigured box.cfg.
16751676
if not router.is_configured then
16761677
local msg = 'router is not configured'
16771678
return error(lerror.vshard(lerror.code.ROUTER_IS_DISABLED, msg))
16781679
end
1679-
if not router.is_enabled then
1680+
local is_disabled_skip = opts and opts.is_disabled_skip
1681+
if not router.is_enabled and not is_disabled_skip then
16801682
local msg = 'router is disabled explicitly'
16811683
return error(lerror.vshard(lerror.code.ROUTER_IS_DISABLED, msg))
16821684
end
16831685
router.api_call_cache = router_api_call_safe
16841686
return func(router, arg1, arg2, arg3, arg4, arg5)
16851687
end
16861688

1687-
local function router_make_api(func)
1689+
local function router_make_api(func, opts)
16881690
return function(router, arg1, arg2, arg3, arg4, arg5)
1689-
return router.api_call_cache(func, router, arg1, arg2, arg3, arg4, arg5)
1691+
return router.api_call_cache(func, router, arg1, arg2,
1692+
arg3, arg4, arg5, opts)
16901693
end
16911694
end
16921695

@@ -1710,7 +1713,7 @@ end
17101713
local router_mt = {
17111714
__index = {
17121715
cfg = function(router, cfg) return router_cfg_fiber_safe(router, cfg, false) end,
1713-
info = router_make_api(router_info),
1716+
info = router_make_api(router_info, {is_disabled_skip = true}),
17141717
buckets_info = router_make_api(router_buckets_info),
17151718
call = router_make_api(router_call),
17161719
callro = router_make_api(router_callro),

0 commit comments

Comments
 (0)