Skip to content

Commit

Permalink
router: disable box.cfg
Browse files Browse the repository at this point in the history
There is no reason for router to have box configured. It needs neither
storage nor listening on a port. This is breaking change, so user's
code, which relies on vshard.router.cfg to call box.cfg must be changed.

Closes #353
Closes #428

@TarantoolBot document
Title: vshard: disable box.cfg on routers

Since vshard 0.1.25 vshard.router.cfg doesn't call box.cfg and this must
be done manually outside of vshard.
  • Loading branch information
Serpentian authored and Gerold103 committed Dec 6, 2023
1 parent a530455 commit bc1c3c4
Show file tree
Hide file tree
Showing 28 changed files with 145 additions and 172 deletions.
4 changes: 3 additions & 1 deletion example/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ replicasets = {'cbf06940-0790-498b-948d-042b62cf3d29',

-- Call a configuration provider
cfg = dofile('localcfg.lua')
-- vshard.router.cfg doesn't support box.cfg options.
cfg = require('vshard.cfg').extract_vshard(cfg)
if arg[1] == 'discovery_disable' then
cfg.discovery_mode = 'off'
end
cfg.listen = 3300

box.cfg{listen = 3300}
-- Start the database with sharding
vshard = require('vshard')
vshard.router.cfg(cfg)
8 changes: 4 additions & 4 deletions test/failover/cluster_changes.result
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test_run:switch('router_1')
-- First test case: reverse weights, when only replica exists,
-- and no replica candidate.
--
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
wait_state('All replicas are ok')
Expand All @@ -67,7 +67,7 @@ vshard.router.info().alerts
reverse_weights()
---
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
vshard.router.info()
Expand Down Expand Up @@ -274,7 +274,7 @@ test_run:switch('router_1')
remove_some_replicas()
---
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
info = vshard.router.info()
Expand Down Expand Up @@ -370,7 +370,7 @@ test_run:switch('router_1')
add_some_replicas()
---
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
#vshard.router.info().alerts > 1
Expand Down
8 changes: 4 additions & 4 deletions test/failover/cluster_changes.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ test_run:switch('router_1')
-- First test case: reverse weights, when only replica exists,
-- and no replica candidate.
--
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
wait_state('All replicas are ok')
vshard.router.info().alerts

reverse_weights()
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
vshard.router.info()
wait_state('All replicas are ok')
vshard.router.info()
Expand Down Expand Up @@ -71,7 +71,7 @@ vshard.storage.cfg(cfg, names.replica_uuid[NAME])
--
test_run:switch('router_1')
remove_some_replicas()
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
info = vshard.router.info()
while #info.alerts ~= 6 do fiber.sleep(0.1) info = vshard.router.info() end
info
Expand All @@ -90,7 +90,7 @@ vshard.storage.cfg(cfg, names.replica_uuid[NAME])
--
test_run:switch('router_1')
add_some_replicas()
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
#vshard.router.info().alerts > 1
wait_state('All replicas are ok')
vshard.router.info()
Expand Down
12 changes: 6 additions & 6 deletions test/failover/failover.result
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test_run:switch('router_1')
---
- true
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
while not test_run:grep_log('router_1', 'New replica box_1_d%(storage%@') do fiber.sleep(0.1) end
Expand Down Expand Up @@ -356,7 +356,7 @@ test_run:switch('router_2')
---
- true
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
priority_order()
Expand Down Expand Up @@ -394,7 +394,7 @@ test_run:switch('router_3')
---
- true
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
priority_order()
Expand Down Expand Up @@ -432,7 +432,7 @@ test_run:switch('router_4')
---
- true
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
priority_order()
Expand Down Expand Up @@ -473,7 +473,7 @@ log.info(string.rep('padding', 200))
cfg.failover_ping_timeout = 0.0000001
---
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
while not test_run:grep_log('router_1', 'Ping error from', 1000) do fiber.sleep(0.01) end
Expand Down Expand Up @@ -511,7 +511,7 @@ err
cfg.failover_ping_timeout = nil
---
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
test_run:switch('default')
Expand Down
12 changes: 6 additions & 6 deletions test/failover/failover.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test_run:cmd('switch default')
--
create_router('router_1')
test_run:switch('router_1')
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
while not test_run:grep_log('router_1', 'New replica box_1_d%(storage%@') do fiber.sleep(0.1) end
priority_order()
vshard.router.bucket_discovery(1).uuid == rs_uuid[1]
Expand Down Expand Up @@ -143,7 +143,7 @@ test_run:switch('default')

create_router('router_2')
test_run:switch('router_2')
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
priority_order()
vshard.router.bucket_discovery(1).uuid == rs_uuid[1]
vshard.router.bucket_discovery(31).uuid == rs_uuid[2]
Expand All @@ -152,7 +152,7 @@ test_run:switch('default')

create_router('router_3')
test_run:switch('router_3')
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
priority_order()
vshard.router.bucket_discovery(1).uuid == rs_uuid[1]
vshard.router.bucket_discovery(31).uuid == rs_uuid[2]
Expand All @@ -161,7 +161,7 @@ test_run:switch('default')

create_router('router_4')
test_run:switch('router_4')
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
priority_order()
vshard.router.bucket_discovery(1).uuid == rs_uuid[1]
vshard.router.bucket_discovery(31).uuid == rs_uuid[2]
Expand All @@ -174,7 +174,7 @@ vshard.router.bucket_discovery(61).uuid == rs_uuid[3]
test_run:switch('router_1')
log.info(string.rep('padding', 200))
cfg.failover_ping_timeout = 0.0000001
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
while not test_run:grep_log('router_1', 'Ping error from', 1000) do fiber.sleep(0.01) end

t = string.rep('a', 1024 * 1024 * 500)
Expand All @@ -187,7 +187,7 @@ res, err = future:wait_result(5)
err
#res[1]
cfg.failover_ping_timeout = nil
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)

test_run:switch('default')
kill_router('router_1')
Expand Down
2 changes: 1 addition & 1 deletion test/failover/failover_errinj.result
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_run:switch('router_1')
---
- true
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
-- Check that already run failover step is restarted on
Expand Down
2 changes: 1 addition & 1 deletion test/failover/failover_errinj.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_run:cmd('create server router_1 with script="failover/router_1.lua"')
test_run:cmd('start server router_1')
test_run:switch('router_1')

vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
-- Check that already run failover step is restarted on
-- configuration change (if some replicasets are removed from
-- config).
Expand Down
1 change: 1 addition & 0 deletions test/failover/router_1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ os = require('os')
fiber = require('fiber')
local names = dofile('names.lua')
log = require('log')
util = require('util')
rs_uuid = names.rs_uuid
replica_uuid = names.replica_uuid
local port
Expand Down
18 changes: 18 additions & 0 deletions test/lua_libs/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ local function map_bucket_protection(test_run, cluster, value)
[[vshard.storage.internal.is_bucket_protected = ...]], value)
end

local function box_router_cfg(cfg, router)
local vcfg = require('vshard.cfg')
local vshard_cfg = vcfg.extract_vshard(cfg)
local box_cfg = vcfg.extract_box(cfg, {})
box.cfg(box_cfg)
if router == nil then
-- Static router configuration
return vshard.router.cfg(vshard_cfg)
end
if type(router) == 'table' then
-- Named router reconfiguration
return router:cfg(vshard_cfg)
end
-- Named router creation
return vshard.router.new(router, vshard_cfg)
end

return {
check_error = check_error,
shuffle_masters = shuffle_masters,
Expand All @@ -231,4 +248,5 @@ return {
git_checkout = git_checkout,
portable_error = portable_error,
is_timeout_error = is_timeout_error,
box_router_cfg = box_router_cfg,
}
1 change: 0 additions & 1 deletion test/misc/bad_uuid_router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require('console').listen(os.getenv('ADMIN'))

-- Call a configuration provider
cfg = require('bad_uuid_config').cfg
cfg.listen = 3300

-- Start the database with sharding
vshard = require('vshard')
Expand Down
4 changes: 2 additions & 2 deletions test/misc/reconfigure.result
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ cfg.collect_lua_garbage = true
cfg.invalid_option = 'kek'
---
...
vshard.router.cfg(cfg)
string.match(require('util').check_error(vshard.router.cfg, cfg, 'invalid_option'), 'Unrecognized cfg options')
---
- error: 'Incorrect value for option ''invalid_option'': unexpected option'
- Unrecognized cfg options
...
not vshard.router.static.collect_lua_garbage
---
Expand Down
2 changes: 1 addition & 1 deletion test/misc/reconfigure.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ _ = test_run:switch('router_1')
not vshard.router.static.collect_lua_garbage
cfg.collect_lua_garbage = true
cfg.invalid_option = 'kek'
vshard.router.cfg(cfg)
string.match(require('util').check_error(vshard.router.cfg, cfg, 'invalid_option'), 'Unrecognized cfg options')
not vshard.router.static.collect_lua_garbage
cfg.invalid_option = nil
cfg.collect_lua_garbage = nil
Expand Down
15 changes: 6 additions & 9 deletions test/multiple_routers/multiple_routers.result
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test_run:cmd("start server router_1")
_ = test_run:cmd("switch router_1")
---
...
vshard.router.cfg(configs.cfg_1)
util.box_router_cfg(configs.cfg_1)
---
...
vshard.router.bootstrap()
Expand Down Expand Up @@ -85,7 +85,7 @@ vshard.router.static:route(1) == vshard.router.route(1)
- true
...
-- Configure extra router.
router_2 = vshard.router.new('router_2', configs.cfg_2)
router_2 = util.box_router_cfg(configs.cfg_2, 'router_2')
---
...
router_2:bootstrap()
Expand Down Expand Up @@ -118,7 +118,7 @@ router_2:call(1, 'read', 'do_select', {2})
routers = {}
---
...
for i = 3, 10 do routers[i] = vshard.router.new('router_' .. i, configs.cfg_2) end
for i = 3, 10 do routers[i] = util.box_router_cfg(configs.cfg_2, 'router_' .. i) end
---
...
routers[3]:call(1, 'read', 'do_select', {2})
Expand Down Expand Up @@ -147,7 +147,7 @@ next(fiber_names) == nil
- true
...
-- Reconfigure one of routers do not affect the others.
routers[3]:cfg(configs.cfg_1)
util.box_router_cfg(configs.cfg_1, routers[3])
---
...
routers[3]:call(1, 'read', 'do_select', {1})
Expand All @@ -166,14 +166,11 @@ routers[4]:call(1, 'read', 'do_select', {2})
---
- [[2, 2]]
...
routers[3]:cfg(configs.cfg_2)
util.box_router_cfg(configs.cfg_2, routers[3])
---
...
-- Try to create router with the same name.
util = require('util')
---
...
util.check_error(vshard.router.new, 'router_2', configs.cfg_2)
util.box_router_cfg(configs.cfg_2, 'router_2')
---
- null
- code: 21
Expand Down
13 changes: 6 additions & 7 deletions test/multiple_routers/multiple_routers.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_run:cmd("start server router_1")

-- Configure default (static) router.
_ = test_run:cmd("switch router_1")
vshard.router.cfg(configs.cfg_1)
util.box_router_cfg(configs.cfg_1)
vshard.router.bootstrap()
_ = test_run:cmd("switch storage_1_2_a")
wait_rebalancer_state('The cluster is balanced ok', test_run)
Expand All @@ -34,7 +34,7 @@ vshard.router.call(1, 'read', 'do_select', {1})
vshard.router.static:route(1) == vshard.router.route(1)

-- Configure extra router.
router_2 = vshard.router.new('router_2', configs.cfg_2)
router_2 = util.box_router_cfg(configs.cfg_2, 'router_2')
router_2:bootstrap()
_ = test_run:cmd("switch storage_2_2_a")
wait_rebalancer_state('The cluster is balanced ok', test_run)
Expand All @@ -47,7 +47,7 @@ router_2:call(1, 'read', 'do_select', {2})

-- Create several routers to the same cluster.
routers = {}
for i = 3, 10 do routers[i] = vshard.router.new('router_' .. i, configs.cfg_2) end
for i = 3, 10 do routers[i] = util.box_router_cfg(configs.cfg_2, 'router_' .. i) end
routers[3]:call(1, 'read', 'do_select', {2})
-- Check that they have their own background fibers.
fiber_names = {}
Expand All @@ -58,16 +58,15 @@ for _, xfiber in pairs(fiber.info()) do fiber_names[xfiber.name] = nil end
next(fiber_names) == nil

-- Reconfigure one of routers do not affect the others.
routers[3]:cfg(configs.cfg_1)
util.box_router_cfg(configs.cfg_1, routers[3])
routers[3]:call(1, 'read', 'do_select', {1})
#routers[3]:call(1, 'read', 'do_select', {2}) == 0
#routers[4]:call(1, 'read', 'do_select', {1}) == 0
routers[4]:call(1, 'read', 'do_select', {2})
routers[3]:cfg(configs.cfg_2)
util.box_router_cfg(configs.cfg_2, routers[3])

-- Try to create router with the same name.
util = require('util')
util.check_error(vshard.router.new, 'router_2', configs.cfg_2)
util.box_router_cfg(configs.cfg_2, 'router_2')

-- Reload router module.
_, old_rs_1 = next(vshard.router.static.replicasets)
Expand Down
1 change: 1 addition & 0 deletions test/multiple_routers/router_1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ configs = dofile('configs.lua')

-- Start the database with sharding
vshard = require('vshard')
util = require('util')
box.cfg{}
2 changes: 1 addition & 1 deletion test/rebalancer/restart_during_rebalancing.result
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ add_replicaset()
add_second_replicaset()
---
...
vshard.router.cfg(cfg)
util.box_router_cfg(cfg)
---
...
--
Expand Down
Loading

0 comments on commit bc1c3c4

Please sign in to comment.