Strategy to assign machine IDs based on the current node's network identifiers (hostname, FQDN, IP addresses, or OTP node name), matched against a fixed list of all possible nodes.
Each entry in node_list receives a stable zero-based index as its machine ID. IDs are
determined locally, so every node must use the same list and have a unique matching identifier.
The list is treated as a set: insertion order does not affect the assigned ID. Keep the list
within 512 distinct entries so every index is in the supported range.
Configure the strategy when starting NoNoncense.MachineId:
children = [
{NoNoncense.MachineId,
strategy: NoNoncense.MachineId.Strategy.HostIdentifiers,
strategy_opts: [node_list: [:"myapp@10.0.0.1", :"myapp@10.0.0.2"]],
instances: [[base_key: System.fetch_env!("BASE_KEY")]]}
]The default ConflictGuard detects duplicate IDs among connected Erlang nodes.
Options
:node_list(required) - identifiers (IP addresses, OTP node names, hostnames, or FQDNs) for every node in the cluster; must be identical on every node and must not contain identifiers shared across nodes (e.g. do not include:"nonode@nohost")
Use the same node list everywhere
Your node_list must be the same for every node or the generated machine IDs will not be unique.
Summary
Functions
Returns the current node's identifiers, which can be used to populate the node list.
Determine the current node's machine ID.
Types
@type opt() :: {:node_list, host_identifiers()}
Functions
@spec host_identifiers() :: host_identifiers()
Returns the current node's identifiers, which can be used to populate the node list.
The result depends on the host, for example:
NoNoncense.MachineId.Strategy.HostIdentifiers.host_identifiers()
#=> [:nonode@nohost, "host.mydomain.com", "10.11.12.13", "myhost", "fe80::1234::abcd"]
@spec id!([opt()]) :: non_neg_integer()
Determine the current node's machine ID.
Examples / doctests
# provide a list of possible node identifiers
iex> node_list = [:a, :b, :nonode@nohost, "1.1.1.1"]
iex> id!(node_list: node_list)
2
# raises when the machine ID could not be determined from the node list
iex> node_list = ["1.1.1.1"]
iex> id!(node_list: node_list)
** (RuntimeError) machine ID could not be determined