PaxosKV.Cluster (paxos_kv v0.6.0)
Copy MarkdownManages the cluster state and node membership.
This module tracks which nodes are part of the distributed cluster, monitors node connections, and maintains the configured cluster size. It provides functions to query the current cluster state and check if a quorum is present.
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns the configured cluster size.
Returns the list of currently connected nodes in the cluster.
Returns both the connected nodes list and the cluster size as a tuple.
Checks if the cluster currently has a quorum.
Dynamically resizes the cluster to a new size.
Subscribes the caller process or the spcified pid for :quorum_reached and
:quorum_lost cluster events. The events are delivered as standard erlang
messages.
The opposite of subscribe/0,1. It removes the given pid from
the list of subscribed processes.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Returns the configured cluster size.
This is the total number of nodes expected to participate in the cluster, not necessarily the number of currently connected nodes.
Examples
iex> PaxosKV.Cluster.cluster_size()
3
Returns the list of currently connected nodes in the cluster.
Examples
iex> PaxosKV.Cluster.nodes()
[:node1@localhost, :node2@localhost]
Returns both the connected nodes list and the cluster size as a tuple.
Examples
iex> PaxosKV.Cluster.nodes_and_cluster_size()
{[:node1@localhost, :node2@localhost], 3}
Checks if the cluster currently has a quorum.
A quorum exists when more than half of the configured cluster size nodes are connected.
Examples
iex> PaxosKV.Cluster.quorum?()
true
Dynamically resizes the cluster to a new size.
Attempts to update the cluster size on all nodes. Returns :ok if all
nodes successfully updated to the new size, :not_in_sync if nodes
disagreed, or {:error, reason} if the operation failed.
Examples
iex> PaxosKV.Cluster.resize_cluster(5)
:ok
Subscribes the caller process or the spcified pid for :quorum_reached and
:quorum_lost cluster events. The events are delivered as standard erlang
messages.
The opposite of subscribe/0,1. It removes the given pid from
the list of subscribed processes.