Skip to content

Commit 2410058

Browse files
committed
storage: introduce schema_management_mode
The new option allows to turn off automatic creation and upgrade of functions, users, and privileges of all sorts. For that the mode has to be specified to 'manual_access'. The default value 'auto' makes vshard behave like before this option's introduction. Note that the option is intentionally not documented so as not to encourage people to use it. The best approach is to let the schema to be maintained fully automatically. Closes #435 NO_DOC=internal
1 parent 134affb commit 2410058

File tree

5 files changed

+136
-17
lines changed

5 files changed

+136
-17
lines changed

test/luatest_helpers/vtest.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ local function cluster_new(g, cfg)
221221

222222
local grant_range = cfg.test_user_grant_range
223223
ivtest.clear_test_cfg_options(cfg)
224+
225+
if cfg.schema_management_mode == 'manual_access' then
226+
local vexports = require('vshard.storage.exports')
227+
local username = 'storage'
228+
box.schema.user.create(username, {
229+
password = username,
230+
-- Yes, intentionally false to ensure that the user wasn't
231+
-- created by vshard.
232+
if_not_exists = false,
233+
})
234+
local exports = vexports.log[#vexports.log]
235+
exports = vexports.compile(exports)
236+
vexports.deploy_funcs(exports)
237+
vexports.deploy_privs(exports, username)
238+
box.schema.user.grant(username, 'replication')
239+
end
224240
ivshard.storage.cfg(cfg, box.info.uuid)
225241

226242
if grant_range ~= nil then
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
local t = require('luatest')
2+
local vtest = require('test.luatest_helpers.vtest')
3+
local vutil = require('vshard.util')
4+
5+
local group_config = {{mode = 'auto'}, {mode = 'manual_access'}}
6+
7+
if vutil.feature.memtx_mvcc then
8+
table.insert(group_config, {
9+
mode = 'auto', memtx_use_mvcc_engine = true
10+
})
11+
table.insert(group_config, {
12+
mode = 'manual_access', memtx_use_mvcc_engine = true
13+
})
14+
end
15+
16+
local test_group = t.group('storage_schema_management_mode', group_config)
17+
18+
local cfg_template = {
19+
sharding = {
20+
{
21+
master = 'auto',
22+
replicas = {
23+
replica_1_a = {read_only = false},
24+
replica_1_b = {read_only = true},
25+
},
26+
},
27+
{
28+
master = 'auto',
29+
replicas = {
30+
replica_2_a = {read_only = false},
31+
},
32+
},
33+
},
34+
bucket_count = 10,
35+
}
36+
37+
test_group.before_all(function(g)
38+
cfg_template.memtx_use_mvcc_engine = g.params.memtx_use_mvcc_engine
39+
cfg_template.schema_management_mode = g.params.mode
40+
local cfg = vtest.config_new(cfg_template)
41+
42+
vtest.cluster_new(g, cfg)
43+
vtest.cluster_bootstrap(g, cfg)
44+
vtest.cluster_rebalancer_disable(g)
45+
end)
46+
47+
test_group.after_all(function(g)
48+
g.cluster:drop()
49+
g.cluster = nil
50+
end)
51+
52+
test_group.test_boot_with_mode_manual_access = function(g)
53+
local bid = g.replica_1_a:exec(function(uuid)
54+
local bid = _G.get_first_bucket()
55+
local ok, err = ivshard.storage.bucket_send(bid, uuid,
56+
{timeout = iwait_timeout})
57+
ilt.assert_equals(err, nil)
58+
ilt.assert(ok)
59+
_G.bucket_gc_wait()
60+
return bid
61+
end, {g.replica_2_a:replicaset_uuid()})
62+
--
63+
-- Switch to another mode. Still works fine.
64+
--
65+
local test_template = table.deepcopy(cfg_template)
66+
if test_template.schema_management_mode == 'auto' then
67+
test_template.schema_management_mode = 'manual_access'
68+
else
69+
test_template.schema_management_mode = 'auto'
70+
end
71+
vtest.cluster_cfg(g, vtest.config_new(test_template))
72+
g.replica_2_a:exec(function(bid, uuid)
73+
local ok, err = ivshard.storage.bucket_send(bid, uuid,
74+
{timeout = iwait_timeout})
75+
ilt.assert_equals(err, nil)
76+
ilt.assert(ok)
77+
_G.bucket_gc_wait()
78+
end, {bid, g.replica_1_a:replicaset_uuid()})
79+
end

test/unit-luatest/config_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,14 @@ g.test_enum = function()
299299
"Box.cfg mode must be enum {'auto', 'manual', nil}",
300300
vcfg.check, config)
301301
config.box_cfg_mode = nil
302+
303+
for _, v in pairs({'auto', 'manual_access'}) do
304+
config.schema_management_mode = v
305+
t.assert(vcfg.check(config))
306+
end
307+
config.schema_management_mode = 'bad'
308+
t.assert_error_msg_content_equals(
309+
"Schema management mode must be enum {'auto', 'manual_access', nil}",
310+
vcfg.check, config)
311+
config.schema_management_mode = nil
302312
end

vshard/cfg.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ local cfg_template = {
410410
box_cfg_mode = {
411411
name = 'Box.cfg mode', type = 'enum', is_optional = true,
412412
default = 'auto', enum = {'auto', 'manual'},
413-
}
413+
},
414+
schema_management_mode = {
415+
name = 'Schema management mode', type = 'enum',
416+
is_optional = true, default = 'auto', enum = {'auto', 'manual_access'},
417+
},
414418
}
415419

416420
--

vshard/storage/schema.lua

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ if not M then
1919
-- and be not nullable. Values in this part are considered as bucket
2020
-- identifiers.
2121
shard_index = nil,
22+
-- How to manage the schema. Auto - do everything automatically,
23+
-- manual - expect some things to be done externally outside of vshard.
24+
management_mode = 'auto',
2225
errinj = {
2326
ERRINJ_UPGRADE = false,
2427
},
@@ -78,12 +81,6 @@ end
7881
--
7982
local function schema_init_0_1_15_0(username, password)
8083
llog.info("Initializing schema %s", schema_version_make({0, 1, 15, 0}))
81-
box.schema.user.create(username, {
82-
password = password,
83-
if_not_exists = true,
84-
})
85-
box.schema.user.grant(username, 'replication', nil, nil,
86-
{if_not_exists = true})
8784

8885
local bucket = box.schema.space.create('_bucket')
8986
bucket:format({
@@ -94,11 +91,19 @@ local function schema_init_0_1_15_0(username, password)
9491
bucket:create_index('pk', {parts = {'id'}})
9592
bucket:create_index('status', {parts = {'status'}, unique = false})
9693

97-
local exports = lvexports.log[1]
98-
assert(exports.version == '0.1.15.0')
99-
exports = lvexports.compile(exports)
100-
lvexports.deploy_funcs(exports)
101-
lvexports.deploy_privs(exports, username)
94+
if M.management_mode == 'auto' then
95+
box.schema.user.create(username, {
96+
password = password,
97+
if_not_exists = true,
98+
})
99+
box.schema.user.grant(username, 'replication', nil, nil,
100+
{if_not_exists = true})
101+
local exports = lvexports.log[1]
102+
assert(exports.version == '0.1.15.0')
103+
exports = lvexports.compile(exports)
104+
lvexports.deploy_funcs(exports)
105+
lvexports.deploy_privs(exports, username)
106+
end
102107
box.space._schema:replace({'vshard_version', 0, 1, 15, 0})
103108
end
104109

@@ -130,7 +135,7 @@ end
130135
-- to a certain vshard version.
131136
--
132137
local function schema_upgrade_core_features()
133-
if M.is_core_up_to_date then
138+
if M.is_core_up_to_date or M.management_mode ~= 'auto' then
134139
return
135140
end
136141
local version = schema_current_version()
@@ -186,8 +191,10 @@ local function schema_upgrade(target_version, username, password)
186191
next_version)
187192
exports = lvexports.compile(exports)
188193
handler.upgrade()
189-
lvexports.deploy_funcs(exports)
190-
lvexports.deploy_privs(exports, username)
194+
if M.management_mode == 'auto' then
195+
lvexports.deploy_funcs(exports)
196+
lvexports.deploy_privs(exports, username)
197+
end
191198
end)
192199
if ok and errinj == 'end' then
193200
ok, err1 = false, 'Errinj in end'
@@ -204,8 +211,10 @@ local function schema_upgrade(target_version, username, password)
204211
prev_version)
205212
exports = lvexports.compile(exports)
206213
handler.downgrade()
207-
lvexports.deploy_funcs(exports)
208-
lvexports.deploy_privs(exports, username)
214+
if M.management_mode == 'auto' then
215+
lvexports.deploy_funcs(exports)
216+
lvexports.deploy_privs(exports, username)
217+
end
209218
end)
210219
if not ok then
211220
llog.info("Couldn't downgrade schema to %s - fatal error: "..
@@ -259,6 +268,7 @@ end
259268

260269
local function schema_cfg(cfg)
261270
M.shard_index = cfg.shard_index
271+
M.management_mode = cfg.schema_management_mode
262272
end
263273

264274
M.current_version = schema_current_version

0 commit comments

Comments
 (0)