Open
Description
#!/usr/bin/env tarantool
local yaml = require('yaml')
local cbuilder = require('luatest.cbuilder')
local config_1 = cbuilder:new()
:use_replicaset('r-001')
:add_instance('i-001', {})
:set_instance_option('i-001', 'replication.timeout', 0.1)
:config()
print(yaml.encode(config_1))
--[[
---
groups:
group-001:
replicasets:
r-001:
instances:
i-001: # !! (just one)
replication:
timeout: 0.1
credentials:
users:
replicator:
password: secret
roles:
- replication
client:
password: secret
roles:
- super
iproto:
listen:
- uri: unix/:./{{ instance_name }}.iproto
advertise:
peer:
login: replicator
replication:
timeout: 0.1
...
]]--
local config_2 = cbuilder:new(config_1)
-- I forgot to write :use_replicaset('r-001') here
:set_instance_option('i-001', 'replication.timeout', 1000)
:config()
print(yaml.encode(config_2))
--[[
---
groups:
group-001:
replicasets:
replicaset-001:
instances:
i-001: # !! (duplicate)
replication:
timeout: 1000
r-001:
instances:
i-001: # !! (initial)
replication:
timeout: 0.1
credentials:
users:
replicator:
password: secret
roles:
- replication
client:
password: secret
roles:
- super
iproto:
listen:
- uri: unix/:./{{ instance_name }}.iproto
advertise:
peer:
login: replicator
replication:
timeout: 0.1
...
]]--
So, now we have to add :use_replicaset('r-001')
, when updating the configuration.
Since the instance name is unique across a cluster1, we can find the given instance across all groups/replicasets instead of assuming default ones group-001
and replicaset-001
. At least, if an explicit :use_group()
and/or :use_replicaset()
are not given.
If the instance is not found, raise an error instead of creating it, because there is a designated :add_instance()
function.