Skip to content

Commit b2bcf17

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

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

test/storage-luatest/storage_1_test.lua

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,44 @@ test_group.test_alerts_for_named_replica = function(g)
633633

634634
test_alerts_for_non_vshard_config_template(g, non_config_replica)
635635
end
636+
637+
test_group.test_info_disable_consistency = function(g)
638+
-- Make storage unconfigured.
639+
g.replica_1_a:restart()
640+
g.replica_1_a:exec(function(cfg)
641+
ivtest.clear_test_cfg_options(cfg)
642+
-- Imitate unconfigured box.
643+
local old_box_cfg = box.cfg
644+
box.cfg = function(...) return old_box_cfg(...) end
645+
local _, err = pcall(ivshard.storage.info)
646+
ilt.assert_not_equals(err, nil)
647+
ilt.assert_str_contains(err.message, 'box seems not to be configured')
648+
box.cfg = old_box_cfg
649+
650+
local old_box_info = box.info
651+
box.info = {status = 'loading'}
652+
_, err = pcall(ivshard.storage.info)
653+
ilt.assert_not_equals(err, nil)
654+
ilt.assert_str_contains(err.message, 'instance status is "loading"')
655+
box.info = old_box_info
656+
657+
_, err = pcall(ivshard.storage.info)
658+
ilt.assert_not_equals(err, nil)
659+
ilt.assert_str_contains(err.message, 'storage is not configured')
660+
661+
ivshard.storage.cfg(cfg, _G.get_uuid())
662+
local res = ivshard.storage.info()
663+
ilt.assert_not_equals(res, nil)
664+
ilt.assert(res.is_enabled)
665+
666+
ivshard.storage.disable()
667+
res = ivshard.storage.info()
668+
ilt.assert_not_equals(res, nil)
669+
ilt.assert_not(res.is_enabled)
670+
671+
ivshard.storage.enable()
672+
res = ivshard.storage.info()
673+
ilt.assert_not_equals(res, nil)
674+
ilt.assert(res.is_enabled)
675+
end, {global_cfg})
676+
end

test/storage/storage.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ vshard.storage.info()
153153
154154
identification_mode: uuid_as_key
155155
status: 2
156+
is_enabled: true
156157
replication:
157158
status: slave
158159
alerts:
@@ -276,6 +277,7 @@ vshard.storage.info()
276277
277278
identification_mode: uuid_as_key
278279
status: 0
280+
is_enabled: true
279281
replication:
280282
status: follow
281283
lag: <lag>
@@ -338,6 +340,7 @@ info
338340
339341
identification_mode: uuid_as_key
340342
status: 0
343+
is_enabled: true
341344
replication:
342345
status: master
343346
alerts: []
@@ -370,6 +373,7 @@ vshard.storage.info()
370373
371374
identification_mode: uuid_as_key
372375
status: 3
376+
is_enabled: true
373377
replication:
374378
status: master
375379
alerts:
@@ -403,6 +407,7 @@ vshard.storage.info()
403407
404408
identification_mode: uuid_as_key
405409
status: 0
410+
is_enabled: true
406411
replication:
407412
status: follow
408413
lag: <lag>
@@ -436,6 +441,7 @@ vshard.storage.info()
436441
437442
identification_mode: uuid_as_key
438443
status: 0
444+
is_enabled: true
439445
replication:
440446
status: master
441447
alerts: []

vshard/storage/init.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4009,6 +4009,7 @@ local function storage_info(opts)
40094009
M.instance_watch_service:info(),
40104010
}
40114011
end
4012+
state.is_enabled = M.is_enabled
40124013
return state
40134014
end
40144015

@@ -4020,15 +4021,15 @@ end
40204021
-- Arguments are listed explicitly instead of '...' because the latter does not
40214022
-- jit.
40224023
--
4023-
local function storage_api_call_safe(func, ...)
4024+
local function storage_api_call_safe(func, _opts, ...)
40244025
return func(...)
40254026
end
40264027

40274028
--
40284029
-- Unsafe proxy is loaded with protections. But it is used rarely and only in
40294030
-- the beginning of instance's lifetime.
40304031
--
4031-
local function storage_api_call_unsafe(func, ...)
4032+
local function storage_api_call_unsafe(func, opts, ...)
40324033
-- box.info is quite expensive. Avoid calling it again when the instance
40334034
-- is finally loaded.
40344035
if not M.is_loaded then
@@ -4049,17 +4050,18 @@ local function storage_api_call_unsafe(func, ...)
40494050
local msg = 'storage is not configured'
40504051
return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
40514052
end
4052-
if not M.is_enabled then
4053+
local is_disabled_skip = opts and opts.is_disabled_skip
4054+
if not M.is_enabled and not is_disabled_skip then
40534055
local msg = 'storage is disabled explicitly'
40544056
return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
40554057
end
40564058
M.api_call_cache = storage_api_call_safe
40574059
return func(...)
40584060
end
40594061

4060-
local function storage_make_api(func)
4062+
local function storage_make_api(func, opts)
40614063
return function(...)
4062-
return M.api_call_cache(func, ...)
4064+
return M.api_call_cache(func, opts, ...)
40634065
end
40644066
end
40654067

@@ -4241,7 +4243,7 @@ return {
42414243
-- Instance info.
42424244
--
42434245
is_locked = storage_make_api(is_this_replicaset_locked),
4244-
info = storage_make_api(storage_info),
4246+
info = storage_make_api(storage_info, {is_disabled_skip = true}),
42454247
sharded_spaces = storage_make_api(storage_sharded_spaces),
42464248
_sharded_spaces = storage_sharded_spaces,
42474249
module_version = function() return M.module_version end,

0 commit comments

Comments
 (0)