Manages cluster membership: monitors node connections, orchestrates join/leave flows, and coordinates data sync for new followers.
Subscribes to :net_kernel nodeup/nodedown events. When a new node connects (via libcluster or manual Node.connect), checks if it needs to be added to the Raft groups. When a node disconnects, starts a removal timer.
Modes
:standalone— no cluster configured, no-op:cluster— cluster_nodes configured, actively managing membership
Summary
Functions
Adds a node to the cluster. Triggers data sync if needed.
Returns a specification to start this module under a supervisor.
Gracefully leaves the cluster (called on the departing node).
Returns the current cluster mode (:standalone or :cluster).
Returns a map of all known nodes and their status.
Removes a node from the cluster gracefully.
Returns sync status for this node (:synced, :syncing, or :not_started).
Functions
Adds a node to the cluster. Triggers data sync if needed.
The node must be reachable via Erlang distribution (Node.connect or libcluster).
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec leave() :: :ok | {:error, term()}
Gracefully leaves the cluster (called on the departing node).
@spec mode() :: :standalone | :cluster
Returns the current cluster mode (:standalone or :cluster).
@spec node_status() :: map()
Returns a map of all known nodes and their status.
Removes a node from the cluster gracefully.
If the node is a leader for any shard, leadership is transferred first.
@spec start_link(keyword()) :: GenServer.on_start()
@spec sync_status() :: :synced | :syncing | :not_started
Returns sync status for this node (:synced, :syncing, or :not_started).