ClusterHelper.ClusterState (ClusterHelper v1.0.1)

Copy Markdown View Source

Pure domain state transformations for cluster membership.

All functions in this module are pure — they take state and return new state with no side effects. This keeps the core business logic (scopes, roles, generations) testable and independent of GenServer or ETS.

Summary

Functions

Marks a node as known in a scope.

Adds roles to a scope, returning updated state and the roles that were actually new (not already present).

Adds a scope to the state, initialising all per-scope maps.

Returns true if the scope exists in the state.

Returns a new empty state.

Updates the remote generation for a node in a scope.

Removes a node from the known set in a scope.

Removes a node from all known-node sets across all scopes.

Removes a node's remote generation from all scopes.

Removes roles from a scope, returning updated state and the roles that were actually removed (existed in the set).

Removes a scope and all its data from the state.

Types

gen_map()

@type gen_map() :: %{required(node()) => integer()}

node_set()

@type node_set() :: MapSet.t(node())

role_set()

@type role_set() :: MapSet.t(term())

t()

@type t() :: %{
  optional(:scopes) => MapSet.t(atom()),
  optional(:roles) => %{required(atom()) => role_set()},
  optional(:known_nodes) => %{required(atom()) => node_set()},
  optional(:generations) => %{required(atom()) => integer()},
  optional(:remote_generations) => %{required(atom()) => gen_map()}
}

Functions

add_known_node(state, scope, node)

@spec add_known_node(t(), atom(), node()) :: t()

Marks a node as known in a scope.

add_roles(state, scope, new_roles)

@spec add_roles(t(), atom(), [term()]) :: {t(), [term()], integer()}

Adds roles to a scope, returning updated state and the roles that were actually new (not already present).

add_scope(state, scope)

@spec add_scope(t(), atom()) :: t()

Adds a scope to the state, initialising all per-scope maps.

has_scope?(state, scope)

@spec has_scope?(t(), atom()) :: boolean()

Returns true if the scope exists in the state.

new()

@spec new() :: t()

Returns a new empty state.

put_remote_generation(state, scope, node, gen)

@spec put_remote_generation(t(), atom(), node(), integer()) :: t()

Updates the remote generation for a node in a scope.

remove_known_node(state, scope, node)

@spec remove_known_node(t(), atom(), node()) :: t()

Removes a node from the known set in a scope.

remove_known_node_from_all(state, node)

@spec remove_known_node_from_all(t(), node()) :: t()

Removes a node from all known-node sets across all scopes.

remove_remote_gen_from_all(state, node)

@spec remove_remote_gen_from_all(t(), node()) :: t()

Removes a node's remote generation from all scopes.

remove_roles(state, scope, roles_to_remove)

@spec remove_roles(t(), atom(), [term()]) :: {t(), [term()], integer()}

Removes roles from a scope, returning updated state and the roles that were actually removed (existed in the set).

remove_scope(state, scope)

@spec remove_scope(t(), atom()) :: t()

Removes a scope and all its data from the state.