Description
Related dev. issue(s): tarantool/tarantool#9680
Product: Tarantool
Since: 3.1
Root document:
- https://www.tarantool.io/en/doc/latest/reference/reference_lua/config/
- See also: https://www.tarantool.io/en/doc/latest/release/3.1.0/#accessing-configuration-of-other-cluster-members
SME: @Totktonada
Details
config:instances()
Lists all instances of the cluster.
Returns a table of the following format.
{
[<instance_name>] = {
instance_name = <...>,
replicaset_name = <...>,
group_name = <...>,
},
<...>
}
If an action should be performed for each instance of the given cluster,
it can be written this way:
for instance_name in pairs(config:instances()) do
action(instance_name)
end
If replicaset/group names matter, the instances may be filtered this
way:
-- Perform an action for all instances of the given replicaset.
for instance_name, def in pairs(config:instances()) do
if def.replicaset_name == box.info.replicaset.name then
action(instance_name)
end
end
config:get(<...>, {instance = '<...>'})
The new instance
option of the config:get()
method allows to
retrieve a configuration value of another instance from the given
cluster.
Example:
-- Collect all the enabled roles within the cluster.
local enabled_roles = {}
for instance_name in pairs(config:instances()) do
local roles = config:get('roles', {instance = instance_name})
for _, role in ipairs(roles) do
enabled_roles[role] = true
end
end
Note: There is a difference between a missing instance
option and the
instance
option that is equal to the given instance name. The former
returns an instance configuration taking into account instance
configuration sources (environment variables). The latter takes into
account only cluster configuration, so the environment variables are
ignored.
Requested by @ Totktonada in tarantool/tarantool@30a9c1c.