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

config: verify replicaset to contain an instance

It is very easy to misplace a config option to a different level, for
example create an empty replicaset `sharding` with storage role, instead
of configuring sharding option to `storage`:
```
groups:
  g-001:
    replicasets:
      sharding:
        roles:
        - storage
      r-001:
        instances:
          i-001: {}
```

This patch adds validation that forbids creating an empty group or
replicaset. Note that a group or a replicaset could still be defined
in multiple config sources and may appear empty in one of them, the
check is performed on the merged cluster config.

Closes #9895

NO_DOC=bugfix
parent d36e7d54
No related branches found
No related tags found
No related merge requests found
## bugfix/config
* Added additional validation to a cluster's configuration.
Now it is forbidden to create an empty group or
replicaset (gh-9895).
......@@ -731,12 +731,32 @@ local function validate_anon(found, peers, failover, leader)
end
end
local function validate_misplacing(cconfig)
for group_name, group_cfg in pairs(cconfig.groups) do
if group_cfg.replicasets == nil or
next(group_cfg.replicasets) == nil then
error(('group %q should include at ' ..
'least one replicaset.'):format(group_name), 0)
end
for replicaset_name, replicaset_cfg in pairs(group_cfg.replicasets) do
if replicaset_cfg.instances == nil or
next(replicaset_cfg.instances) == nil then
error(('replicaset %q should include at ' ..
'least one instance.'):format(replicaset_name), 0)
end
end
end
end
local function new(iconfig, cconfig, instance_name)
-- Find myself in a cluster config, determine peers in the same
-- replicaset.
local found = cluster_config:find_instance(cconfig, instance_name)
assert(found ~= nil)
validate_misplacing(cconfig)
-- Precalculate configuration with applied defaults.
local iconfig_def = instance_config:apply_default(iconfig)
......
......@@ -281,3 +281,33 @@ g.test_instance_uri_errors = function(g)
end)
end)
end
-- Attempt to pass an empty group and an empty replicaset.
g.test_misplace_option = function(g)
local config = cbuilder.new()
:use_group('g-001')
:use_replicaset('r-001')
:add_instance('i-001', {})
:use_group('sharding')
:set_group_option('roles', {'storage'})
:config()
cluster.startup_error(g, config, "group \"sharding\" should " ..
"include at least one replicaset.")
local config = cbuilder.new()
:use_group('g-001')
:use_replicaset('r-001')
:add_instance('i-001', {})
:use_replicaset('sharding')
:set_replicaset_option('roles', {'storage'})
:config()
cluster.startup_error(g, config, "replicaset \"sharding\" should " ..
"include at least one instance.")
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