Skip to content

Commit 481c402

Browse files
committed
storage: introduce box_cfg_mode
Part of #428 @TarantoolBot document Title: vshard: `box_cfg_mode` cfg option The option can be specified at the root level and regulates, whether vshard calls box.cfg, when vshard.storage is invoked. When specified to 'auto' (default), vshard configures box.cfg on its own. When specified to 'manual', it's user's responsibility to call box.cfg prior to vshard's configuration
1 parent 3bb3f7a commit 481c402

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
local t = require('luatest')
2+
local vtest = require('test.luatest_helpers.vtest')
3+
4+
local test_group = t.group()
5+
6+
local cfg_template = {
7+
sharding = {
8+
{
9+
replicas = {
10+
replica_1_a = {master = true},
11+
},
12+
},
13+
{
14+
replicas = {
15+
replica_2_a = {master = true},
16+
},
17+
},
18+
},
19+
bucket_count = 20,
20+
box_cfg_mode = 'manual',
21+
}
22+
23+
local global_cfg
24+
25+
test_group.before_all(function(g)
26+
global_cfg = vtest.config_new(cfg_template)
27+
vtest.cluster_new(g, global_cfg)
28+
vtest.cluster_bootstrap(g, global_cfg)
29+
vtest.cluster_wait_vclock_all(g)
30+
vtest.cluster_rebalancer_disable(g)
31+
end)
32+
33+
test_group.after_all(function(g)
34+
g.cluster:stop()
35+
end)
36+
37+
test_group.test_storage_disabled_error = function(g)
38+
g.replica_1_a:exec(function(cfg)
39+
local old_box = box.cfg
40+
box.cfg = function() end
41+
ilt.assert_error_msg_contains('Box must be configured', function()
42+
ivshard.storage.cfg(cfg, box.info.uuid)
43+
end)
44+
box.cfg = old_box
45+
end, {global_cfg})
46+
end
47+
48+
--
49+
-- vtest.cluster_new does exactly, what user should do,
50+
-- when using 'manual' box_cfg_mode: call box.cfg prior
51+
-- to executing vshard.storage.cfg. So, just some basic test.
52+
--
53+
test_group.test_storage_basic = function(g)
54+
t.assert(g.replica_1_a:grep_log('Box configuration was skipped'))
55+
g.replica_1_a:exec(function(uuid)
56+
local bid = _G.get_first_bucket()
57+
local ok, err = ivshard.storage.bucket_send(bid, uuid)
58+
ilt.assert_equals(err, nil)
59+
ilt.assert(ok)
60+
_G.bucket_gc_wait()
61+
end, {g.replica_2_a:replicaset_uuid()})
62+
end

test/unit-luatest/config_test.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,15 @@ g.test_enum = function()
279279
"Discovery mode must be enum {'on', 'off', 'once', nil}",
280280
vcfg.check, config)
281281
config.discovery_mode = nil
282+
283+
config.box_cfg_mode = nil
284+
for _, v in pairs({'auto', 'manual'}) do
285+
config.box_cfg_mode = v
286+
t.assert(vcfg.check(config))
287+
end
288+
config.box_cfg_mode = 'bad'
289+
t.assert_error_msg_content_equals(
290+
"Box.cfg mode must be enum {'auto', 'manual', nil}",
291+
vcfg.check, config)
292+
config.box_cfg_mode = nil
282293
end

vshard/cfg.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ local cfg_template = {
419419
name = 'Scheduler bucket move quota', type = 'non-negative number',
420420
is_optional = true, default = consts.DEFAULT_SCHED_MOVE_QUOTA
421421
},
422+
box_cfg_mode = {
423+
name = 'Box.cfg mode', type = 'enum', is_optional = true,
424+
default = 'auto', enum = {'auto', 'manual'},
425+
}
422426
}
423427

424428
--

vshard/storage/init.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3883,7 +3883,13 @@ local function storage_cfg_xc(cfgctx)
38833883
error('Error injection: cfg')
38843884
end
38853885

3886-
if not cfgctx.is_reload then
3886+
if cfgctx.new_cfg.box_cfg_mode == 'manual' then
3887+
if type(box.cfg) == 'function' then
3888+
local msg = "Box must be configured, when box_cfg_mode is 'manual'"
3889+
error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED, msg))
3890+
end
3891+
log.info("Box configuration was skipped")
3892+
elseif not cfgctx.is_reload then
38873893
storage_cfg_master_prepare(cfgctx)
38883894
storage_cfg_build_local_box_cfg(cfgctx)
38893895

0 commit comments

Comments
 (0)