forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: automatically set missing names
For now it's impossible to use config module in order to recover from snaps, which don't have names set in them. Calling box.cfg with names on recovery fails with MISMATCH error, which is caused by difficult implementation of setting names on first box.cfg, as names can be set only on rw instance. This commit doesn't call box.cfg with names, if these names are missing from the snapshot file. Instead it creates a fiber, which will set names, when it's possible to do so. Only master sets the names for the whole cluster. Closes tarantool#8978 NO_DOC=tarantool/doc#3661 NO_CHANGELOG=following commits
- Loading branch information
1 parent
2b157ab
commit 271d464
Showing
2 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
local t = require('luatest') | ||
local treegen = require('test.treegen') | ||
local server = require('test.luatest_helpers.server') | ||
local replica_set = require('luatest.replica_set') | ||
local yaml = require('yaml') | ||
local uuid = require('uuid') | ||
local fun = require('fun') | ||
|
||
local g = t.group('set-names-automatically') | ||
|
||
local function initialize_xlogs(g, uuids) | ||
g.replica_set = replica_set:new({}) | ||
local box_cfg = { | ||
replicaset_uuid = uuids['replicaset-001'], | ||
replication = { | ||
server.build_listen_uri('instance-001', g.replica_set.id), | ||
server.build_listen_uri('instance-002', g.replica_set.id), | ||
}, | ||
} | ||
|
||
box_cfg.instance_uuid = uuids['instance-001'] | ||
local instance_1 = g.replica_set:build_and_add_server( | ||
{alias = 'instance-001', box_cfg = box_cfg}) | ||
|
||
box_cfg.instance_uuid = uuids['instance-002'] | ||
local instance_2 = g.replica_set:build_and_add_server( | ||
{alias = 'instance-002', box_cfg = box_cfg}) | ||
|
||
g.replica_set:start() | ||
g.replica_set:wait_for_fullmesh() | ||
for _, replica in ipairs(g.replica_set.servers) do | ||
replica:exec(function() | ||
box.snapshot() | ||
end) | ||
end | ||
|
||
g.replica_set:stop() | ||
return instance_1.workdir, instance_2.workdir | ||
end | ||
|
||
g.before_all(function(g) | ||
treegen.init(g) | ||
local uuids = { | ||
['replicaset-001'] = uuid.str(), | ||
['instance-001'] = uuid.str(), | ||
['instance-002'] = uuid.str(), | ||
} | ||
|
||
local workdir_1, workdir_2 = initialize_xlogs(g, uuids) | ||
local config = { | ||
credentials = { | ||
users = { | ||
guest = { | ||
roles = {'super'}, | ||
}, | ||
}, | ||
}, | ||
|
||
iproto = { | ||
listen = 'unix/:./{{ instance_name }}.iproto', | ||
}, | ||
|
||
groups = { | ||
['group-001'] = { | ||
replicasets = { | ||
['replicaset-001'] = { | ||
database = { | ||
replicaset_uuid = uuids['replicaset-001'] | ||
}, | ||
instances = { | ||
['instance-001'] = { | ||
snapshot = { dir = workdir_1, }, | ||
wal = { dir = workdir_1, }, | ||
database = { | ||
instance_uuid = uuids['instance-001'], | ||
mode = 'rw', | ||
}, | ||
}, | ||
['instance-002'] = { | ||
snapshot = { dir = workdir_2, }, | ||
wal = { dir = workdir_2, }, | ||
database = { | ||
instance_uuid = uuids['instance-002'] | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
local cfg = yaml.encode(config) | ||
local dir = treegen.prepare_directory(g, {}, {}) | ||
local config_file = treegen.write_script(dir, 'cfg.yaml', cfg) | ||
local opts = {config_file = config_file, chdir = dir} | ||
g.instance_1 = server:new(fun.chain(opts, {alias = 'instance-001'}):tomap()) | ||
g.instance_2 = server:new(fun.chain(opts, {alias = 'instance-002'}):tomap()) | ||
|
||
g.instance_1:start({wait_until_ready = false}) | ||
g.instance_2:start({wait_until_ready = false}) | ||
t.helpers.retrying({}, function() | ||
g.instance_1:connect_net_box() | ||
g.instance_2:connect_net_box() | ||
end) | ||
end) | ||
|
||
g.after_all(function(g) | ||
g.replica_set:drop() | ||
g.instance_1:drop() | ||
g.instance_2:drop() | ||
treegen.clean(g) | ||
end) | ||
|
||
g.test_names_are_set = function(g) | ||
g.instance_1:exec(function() | ||
local info = box.info | ||
t.helpers.retrying({}, function() | ||
t.assert_equals(info.replicaset.name, 'replicaset-001') | ||
t.assert_equals(info.name, 'instance-001') | ||
end) | ||
end) | ||
|
||
g.instance_2:exec(function() | ||
local info = box.info | ||
t.helpers.retrying({}, function() | ||
t.assert_equals(info.replicaset.name, 'replicaset-001') | ||
t.assert_equals(info.name, 'instance-002') | ||
end) | ||
end) | ||
end |