Ferricstore.Cluster.Manager (ferricstore v0.3.3)

Copy Markdown View Source

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

add_node(node, role \\ :voter)

@spec add_node(node(), atom()) :: :ok | {:error, term()}

Adds a node to the cluster. Triggers data sync if needed.

The node must be reachable via Erlang distribution (Node.connect or libcluster).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

leave()

@spec leave() :: :ok | {:error, term()}

Gracefully leaves the cluster (called on the departing node).

mode()

@spec mode() :: :standalone | :cluster

Returns the current cluster mode (:standalone or :cluster).

node_status()

@spec node_status() :: map()

Returns a map of all known nodes and their status.

remove_node(node)

@spec remove_node(node()) :: :ok | {:error, term()}

Removes a node from the cluster gracefully.

If the node is a leader for any shard, leadership is transferred first.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

sync_status()

@spec sync_status() :: :synced | :syncing | :not_started

Returns sync status for this node (:synced, :syncing, or :not_started).