Skip to content

Commit 6cff2d1

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 6aac10a commit 6cff2d1

File tree

4 files changed

+94
-5
lines changed

4 files changed

+94
-5
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
g.replica_1_a:exec(function(uuid)
55+
local bid = _G.get_first_bucket()
56+
local ok, err = ivshard.storage.bucket_send(bid, uuid)
57+
ilt.assert_equals(err, nil)
58+
ilt.assert(ok)
59+
_G.bucket_gc_wait()
60+
end, {g.replica_2_a:replicaset_uuid()})
61+
end

test/unit-luatest/config_test.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,15 @@ g.test_enum = function()
120120
"Discovery mode must be enum {'on', 'off', 'once', nil}",
121121
vcfg.check, config)
122122
config.discovery_mode = nil
123+
124+
config.box_cfg_mode = nil
125+
for _, v in pairs({'auto', 'manual'}) do
126+
config.box_cfg_mode = v
127+
t.assert(vcfg.check(config))
128+
end
129+
config.box_cfg_mode = 'bad'
130+
t.assert_error_msg_content_equals(
131+
"Box.cfg mode must be enum {'auto', 'manual', nil}",
132+
vcfg.check, config)
133+
config.box_cfg_mode = nil
123134
end

vshard/cfg.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ local cfg_template = {
376376
name = 'Scheduler bucket move quota', type = 'non-negative number',
377377
is_optional = true, default = consts.DEFAULT_SCHED_MOVE_QUOTA
378378
},
379+
box_cfg_mode = {
380+
name = 'Box.cfg mode', type = 'enum', is_optional = true,
381+
default = 'auto', enum = {'auto', 'manual'},
382+
}
379383
}
380384

381385
--

vshard/storage/init.lua

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,13 +1957,24 @@ local function buckets_discovery(opts)
19571957
return ret
19581958
end
19591959

1960+
local function storage_box_cfg(cfg)
1961+
if M.box_cfg_mode == 'manual' then
1962+
if type(box.cfg) == 'function' then
1963+
error(lerror.vshard(lerror.code.STORAGE_IS_DISABLED,
1964+
"Box must be configured, when box_cfg_mode = 'manual' is used"))
1965+
end
1966+
return true
1967+
end
1968+
return pcall(box.cfg, cfg)
1969+
end
1970+
19601971
--
19611972
-- The only thing, that must be done to abort a master demote is
19621973
-- a reset of read_only.
19631974
--
19641975
local function local_on_master_disable_abort()
19651976
if not M.current_cfg or M.current_cfg.read_only == nil then
1966-
box.cfg{read_only = false}
1977+
storage_box_cfg({read_only = false})
19671978
end
19681979
end
19691980

@@ -1975,7 +1986,7 @@ end
19751986
local function local_on_master_disable_prepare()
19761987
log.info("Resigning from the replicaset master role...")
19771988
if not M.current_cfg or M.current_cfg.read_only == nil then
1978-
box.cfg({read_only = true})
1989+
storage_box_cfg({read_only = true})
19791990
sync(M.sync_timeout)
19801991
end
19811992
end
@@ -2006,7 +2017,7 @@ end
20062017
--
20072018
local function local_on_master_enable_abort()
20082019
if not M.current_cfg or M.current_cfg.read_only == nil then
2009-
box.cfg({read_only = true})
2020+
storage_box_cfg({read_only = true})
20102021
end
20112022
end
20122023

@@ -2026,7 +2037,7 @@ end
20262037
--
20272038
local function local_on_master_enable()
20282039
if not M.current_cfg or M.current_cfg.read_only == nil then
2029-
box.cfg({read_only = false})
2040+
storage_box_cfg({read_only = false})
20302041
end
20312042
M._on_master_enable:run()
20322043
-- Start background process to collect garbage.
@@ -3396,6 +3407,8 @@ local function storage_cfg(cfg, this_replica_uuid, is_reload)
33963407
--
33973408
local old_sync_timeout = M.sync_timeout
33983409
M.sync_timeout = vshard_cfg.sync_timeout
3410+
-- TODO: refactor this to use the context.
3411+
M.box_cfg_mode = vshard_cfg.box_cfg_mode
33993412

34003413
if was_master and not is_master then
34013414
local_on_master_disable_prepare()
@@ -3450,7 +3463,7 @@ local function storage_cfg(cfg, this_replica_uuid, is_reload)
34503463
real_rs_uuid, this_replicaset.uuid))
34513464
end
34523465
end
3453-
local ok, err = pcall(box.cfg, box_cfg)
3466+
local ok, err = storage_box_cfg(box_cfg)
34543467
while M.errinj.ERRINJ_CFG_DELAY do
34553468
lfiber.sleep(0.01)
34563469
end

0 commit comments

Comments
 (0)