Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/failover/cluster_changes.result
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ info
available_rw: 0
identification_mode: uuid_as_key
status: 1
is_enabled: true
alerts:
- ['UNKNOWN_BUCKETS', '3000 buckets are not discovered']
...
Expand Down Expand Up @@ -278,6 +279,7 @@ info
available_rw: 0
identification_mode: uuid_as_key
status: 3
is_enabled: true
alerts:
- ['MISSING_MASTER', 'Master is not configured for replicaset 739fe4fb-2850-4cde-9637-10150724c5eb']
- ['MISSING_MASTER', 'Master is not configured for replicaset 832bbba0-9699-4aa1-907d-c7c7af61f5c9']
Expand Down Expand Up @@ -384,6 +386,7 @@ info
available_rw: 0
identification_mode: uuid_as_key
status: 1
is_enabled: true
alerts:
- ['UNKNOWN_BUCKETS', '3000 buckets are not discovered']
...
Expand Down
1 change: 1 addition & 0 deletions test/rebalancer/restart_during_rebalancing.result
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ info
available_rw: 200
identification_mode: uuid_as_key
status: 0
is_enabled: true
alerts: []
...
util.stop_loading()
Expand Down
34 changes: 34 additions & 0 deletions test/router-luatest/router_2_2_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1265,3 +1265,37 @@ g.test_log_ratelimiter_is_dropped_on_disable_of_the_service = function(g)
_G.ratelimit = nil
end, {name})
end

g.test_info_disable_consistency = function(g)
local router = vtest.router_new(g, 'router_1')
router:exec(function(cfg)
ivtest.clear_test_cfg_options(cfg)
-- Do not allow router's configuration to complete.
_G.ivshard.router.internal.errinj.ERRINJ_CFG_DELAY = true
local fiber_cfg = ifiber.create(ivshard.router.cfg, cfg)
fiber_cfg:set_joinable(true)
local routers = ivshard.router.internal.routers
local _, err = pcall(routers._static_router.info,
routers._static_router)
ilt.assert_not_equals(err, nil)
ilt.assert_str_contains(err.message, 'router is not configured')

-- Unblock router's configuration and wait until it's finished.
_G.ivshard.router.internal.errinj.ERRINJ_CFG_DELAY = false
fiber_cfg:join()
local res = ivshard.router:info()
ilt.assert_not_equals(res, nil)
ilt.assert(res.is_enabled)

ivshard.router:disable()
res = ivshard.router:info()
ilt.assert_not_equals(res, nil)
ilt.assert_not(res.is_enabled)

ivshard.router:enable()
res = ivshard.router:info()
t.assert_not_equals(res, nil)
t.assert(res.is_enabled)
end, {global_cfg})
vtest.drop_instance(g, router)
end
1 change: 1 addition & 0 deletions test/router/reconnect_to_master.result
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ vshard.router.info()
available_rw: 0
identification_mode: uuid_as_key
status: 2
is_enabled: true
alerts:
- ['UNREACHABLE_MASTER', 'Master of replicaset cbf06940-0790-498b-948d-042b62cf3d29
is unreachable: disconnected']
Expand Down
2 changes: 2 additions & 0 deletions test/router/router.result
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ vshard.router.info()
available_rw: 1
identification_mode: uuid_as_key
status: 1
is_enabled: true
alerts:
- ['UNKNOWN_BUCKETS', '2999 buckets are not discovered']
...
Expand Down Expand Up @@ -1076,6 +1077,7 @@ info
available_rw: 3000
identification_mode: uuid_as_key
status: 0
is_enabled: true
alerts: []
...
-- Remove replica and master connections to trigger alert
Expand Down
41 changes: 41 additions & 0 deletions test/storage-luatest/storage_1_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,44 @@ test_group.test_alerts_for_named_replica = function(g)

test_alerts_for_non_vshard_config_template(g, non_config_replica)
end

test_group.test_info_disable_consistency = function(g)
-- Make storage unconfigured.
g.replica_1_a:restart()
g.replica_1_a:exec(function(cfg)
ivtest.clear_test_cfg_options(cfg)
-- Imitate unconfigured box.
local old_box_cfg = box.cfg
box.cfg = function(...) return old_box_cfg(...) end
local _, err = pcall(ivshard.storage.info)
ilt.assert_not_equals(err, nil)
ilt.assert_str_contains(err.message, 'box seems not to be configured')
box.cfg = old_box_cfg

local old_box_info = box.info
box.info = {status = 'loading'}
_, err = pcall(ivshard.storage.info)
ilt.assert_not_equals(err, nil)
ilt.assert_str_contains(err.message, 'instance status is "loading"')
box.info = old_box_info

_, err = pcall(ivshard.storage.info)
ilt.assert_not_equals(err, nil)
ilt.assert_str_contains(err.message, 'storage is not configured')

ivshard.storage.cfg(cfg, _G.get_uuid())
local res = ivshard.storage.info()
ilt.assert_not_equals(res, nil)
ilt.assert(res.is_enabled)

ivshard.storage.disable()
res = ivshard.storage.info()
ilt.assert_not_equals(res, nil)
ilt.assert_not(res.is_enabled)

ivshard.storage.enable()
res = ivshard.storage.info()
ilt.assert_not_equals(res, nil)
ilt.assert(res.is_enabled)
end, {global_cfg})
end
6 changes: 6 additions & 0 deletions test/storage/storage.result
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ vshard.storage.info()
uri: storage@127.0.0.1:3301
identification_mode: uuid_as_key
status: 2
is_enabled: true
replication:
status: slave
alerts:
Expand Down Expand Up @@ -276,6 +277,7 @@ vshard.storage.info()
uri: storage@127.0.0.1:3304
identification_mode: uuid_as_key
status: 0
is_enabled: true
replication:
status: follow
lag: <lag>
Expand Down Expand Up @@ -338,6 +340,7 @@ info
uri: storage@127.0.0.1:3303
identification_mode: uuid_as_key
status: 0
is_enabled: true
replication:
status: master
alerts: []
Expand Down Expand Up @@ -370,6 +373,7 @@ vshard.storage.info()
uri: storage@127.0.0.1:3303
identification_mode: uuid_as_key
status: 3
is_enabled: true
replication:
status: master
alerts:
Expand Down Expand Up @@ -403,6 +407,7 @@ vshard.storage.info()
uri: storage@127.0.0.1:3304
identification_mode: uuid_as_key
status: 0
is_enabled: true
replication:
status: follow
lag: <lag>
Expand Down Expand Up @@ -436,6 +441,7 @@ vshard.storage.info()
uri: storage@127.0.0.1:3303
identification_mode: uuid_as_key
status: 0
is_enabled: true
replication:
status: master
alerts: []
Expand Down
14 changes: 8 additions & 6 deletions vshard/router/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ local function router_info(router, opts)
router.discovery_service:info(),
}
end
state.is_enabled = router.is_enabled
return state
end

Expand Down Expand Up @@ -1661,31 +1662,32 @@ end
-- Public API protection
--------------------------------------------------------------------------------

local function router_api_call_safe(func, router, ...)
local function router_api_call_safe(func, router, _opts, ...)
return func(router, ...)
end

--
-- Unsafe proxy is loaded with protections. But it is used rarely and only in
-- the beginning of instance's lifetime.
--
local function router_api_call_unsafe(func, router, ...)
local function router_api_call_unsafe(func, router, opts, ...)
-- Router can be started on instance with unconfigured box.cfg.
if not router.is_configured then
local msg = 'router is not configured'
return error(lerror.vshard(lerror.code.ROUTER_IS_DISABLED, msg))
end
if not router.is_enabled then
local is_disabled_skip = opts and opts.is_disabled_skip
if not router.is_enabled and not is_disabled_skip then
local msg = 'router is disabled explicitly'
return error(lerror.vshard(lerror.code.ROUTER_IS_DISABLED, msg))
end
router.api_call_cache = router_api_call_safe
return func(router, ...)
end

local function router_make_api(func)
local function router_make_api(func, opts)
return function(router, ...)
return router.api_call_cache(func, router, ...)
return router.api_call_cache(func, router, opts, ...)
end
end

Expand All @@ -1709,7 +1711,7 @@ end
local router_mt = {
__index = {
cfg = function(router, cfg) return router_cfg_fiber_safe(router, cfg, false) end,
info = router_make_api(router_info),
info = router_make_api(router_info, {is_disabled_skip = true}),
buckets_info = router_make_api(router_buckets_info),
call = router_make_api(router_call),
callro = router_make_api(router_callro),
Expand Down
24 changes: 11 additions & 13 deletions vshard/storage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4009,26 +4009,23 @@ local function storage_info(opts)
M.instance_watch_service:info(),
}
end
state.is_enabled = M.is_enabled
return state
end

--------------------------------------------------------------------------------
-- Public API protection
--------------------------------------------------------------------------------

--
-- Arguments are listed explicitly instead of '...' because the latter does not
-- jit.
--
local function storage_api_call_safe(func, arg1, arg2, arg3, arg4)
return func(arg1, arg2, arg3, arg4)
local function storage_api_call_safe(func, _opts, ...)
return func(...)
end

--
-- Unsafe proxy is loaded with protections. But it is used rarely and only in
-- the beginning of instance's lifetime.
--
local function storage_api_call_unsafe(func, arg1, arg2, arg3, arg4)
local function storage_api_call_unsafe(func, opts, ...)
-- box.info is quite expensive. Avoid calling it again when the instance
-- is finally loaded.
if not M.is_loaded then
Expand All @@ -4049,17 +4046,18 @@ local function storage_api_call_unsafe(func, arg1, arg2, arg3, arg4)
local msg = 'storage is not configured'
return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
end
if not M.is_enabled then
local is_disabled_skip = opts and opts.is_disabled_skip
if not M.is_enabled and not is_disabled_skip then
local msg = 'storage is disabled explicitly'
return error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
end
M.api_call_cache = storage_api_call_safe
return func(arg1, arg2, arg3, arg4)
return func(...)
end

local function storage_make_api(func)
return function(arg1, arg2, arg3, arg4)
return M.api_call_cache(func, arg1, arg2, arg3, arg4)
local function storage_make_api(func, opts)
return function(...)
return M.api_call_cache(func, opts, ...)
end
end

Expand Down Expand Up @@ -4241,7 +4239,7 @@ return {
-- Instance info.
--
is_locked = storage_make_api(is_this_replicaset_locked),
info = storage_make_api(storage_info),
info = storage_make_api(storage_info, {is_disabled_skip = true}),
sharded_spaces = storage_make_api(storage_sharded_spaces),
_sharded_spaces = storage_sharded_spaces,
module_version = function() return M.module_version end,
Expand Down
Loading