Skip to content
Snippets Groups Projects
Commit cd90b91c authored by Alexander Turenko's avatar Alexander Turenko Committed by Alexander Turenko
Browse files

config: raise error if replicaset can't be built

We can't just pass it over and start the instance:

1. If it is an initial bootstrap (there is no data for the given
   instance yet), the instance will form its own replicaset instead of
   joining into the existing one.
2. If it is a startup of an existing instance, the local data may be
   outdated and serving requests is undesirable.

Part of #8810

NO_DOC=the old behavior was not released, the documentation request will
       be registered manually
NO_CHANGELOG=see NO_DOC
parent d8abfe34
No related branches found
No related tags found
No related merge requests found
local log = require('internal.config.utils.log')
local function peer_uris(configdata)
local names = configdata:names()
local peers = configdata:peers()
if #peers <= 1 then
return nil
......@@ -11,11 +13,10 @@ local function peer_uris(configdata)
local iproto = configdata:get('iproto', {peer = peer_name}) or {}
local uri = iproto.advertise or iproto.listen
if uri == nil then
-- XXX: Raise an error in the case?
log.warn('box_cfg.apply: neither iproto.advertise nor ' ..
'iproto.listen provided for peer %q; do not construct ' ..
'box.cfg.replication', peer_name)
return nil
error(('box_cfg.apply: unable to build replicaset %q of group ' ..
'%q: instance %q has neither iproto.advertise nor ' ..
'iproto.listen options'):format(names.replicaset_name,
names.group_name, peer_name), 0)
end
table.insert(uris, uri)
end
......
......@@ -3,6 +3,7 @@ local yaml = require('yaml')
local fio = require('fio')
local t = require('luatest')
local treegen = require('test.treegen')
local justrun = require('test.justrun')
local server = require('test.luatest_helpers.server')
local helpers = require('test.config-luatest.helpers')
......@@ -75,3 +76,52 @@ g.test_example_replicaset = function(g)
local config_file = fio.abspath('doc/examples/config/replicaset.yaml')
helpers.start_example_replicaset(g, dir, config_file)
end
g.test_no_advertise_no_listen = function(g)
local dir = treegen.prepare_directory(g, {}, {})
local config = {
credentials = {
users = {
guest = {
roles = {'super'},
},
},
},
groups = {
['group-001'] = {
replicasets = {
['replicaset-001'] = {
instances = {
['instance-001'] = {
database = {
rw = true,
},
iproto = {
listen =
'unix/:./{{ instance_name }}.iproto',
},
},
-- No iproto.advertise or iproto.listen.
['instance-002'] = {},
['instance-003'] = {},
},
},
},
},
},
}
local config_file = treegen.write_script(dir, 'config.yaml',
yaml.encode(config))
local env = {}
local args = {'--name', 'instance-001', '--config', config_file}
local opts = {nojson = true, stderr = true}
local res = justrun.tarantool(dir, env, args, opts)
t.assert_equals(res, {
exit_code = 1,
stderr = 'LuajitError: box_cfg.apply: unable to build replicaset ' ..
'"replicaset-001" of group "group-001": instance "instance-002" ' ..
'has neither iproto.advertise nor iproto.listen options\n' ..
'fatal error, exiting the event loop',
})
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment