pub struct ClusterState {
pub nodes: HashMap<NodeId, ClusterNode>,
pub local_id: NodeId,
pub config_epoch: u64,
pub slot_map: SlotMap,
pub state: ClusterHealth,
}Expand description
The complete state of the cluster as seen by a node.
Fields§
§nodes: HashMap<NodeId, ClusterNode>All known nodes in the cluster, indexed by ID.
local_id: NodeIdThis node’s ID.
config_epoch: u64Current configuration epoch (increases on topology changes).
slot_map: SlotMapSlot-to-node mapping.
state: ClusterHealthCluster state: ok, fail, or unknown.
Implementations§
Source§impl ClusterState
impl ClusterState
Sourcepub fn single_node(local_node: ClusterNode) -> Self
pub fn single_node(local_node: ClusterNode) -> Self
Creates a new cluster state for a single-node cluster.
Sourcepub fn new(local_id: NodeId) -> Self
pub fn new(local_id: NodeId) -> Self
Creates a new empty cluster state (for joining an existing cluster).
Sourcepub fn local_node(&self) -> Option<&ClusterNode>
pub fn local_node(&self) -> Option<&ClusterNode>
Returns the local node.
Sourcepub fn local_node_mut(&mut self) -> Option<&mut ClusterNode>
pub fn local_node_mut(&mut self) -> Option<&mut ClusterNode>
Returns a mutable reference to the local node.
Sourcepub fn add_node(&mut self, node: ClusterNode)
pub fn add_node(&mut self, node: ClusterNode)
Adds a node to the cluster.
Sourcepub fn remove_node(&mut self, node_id: NodeId) -> Option<ClusterNode>
pub fn remove_node(&mut self, node_id: NodeId) -> Option<ClusterNode>
Removes a node from the cluster.
Sourcepub fn slot_owner(&self, slot: u16) -> Option<&ClusterNode>
pub fn slot_owner(&self, slot: u16) -> Option<&ClusterNode>
Returns the node that owns the given slot.
Sourcepub fn primaries(&self) -> impl Iterator<Item = &ClusterNode>
pub fn primaries(&self) -> impl Iterator<Item = &ClusterNode>
Returns all primary nodes.
Sourcepub fn replicas(&self) -> impl Iterator<Item = &ClusterNode>
pub fn replicas(&self) -> impl Iterator<Item = &ClusterNode>
Returns all replica nodes.
Sourcepub fn replicas_of(
&self,
primary_id: NodeId,
) -> impl Iterator<Item = &ClusterNode>
pub fn replicas_of( &self, primary_id: NodeId, ) -> impl Iterator<Item = &ClusterNode>
Returns replicas of a specific primary.
Sourcepub fn update_health(&mut self)
pub fn update_health(&mut self)
Computes and updates the cluster health state.
Sourcepub fn cluster_info(&self) -> String
pub fn cluster_info(&self) -> String
Generates the response for CLUSTER INFO command.
Sourcepub fn cluster_nodes(&self) -> String
pub fn cluster_nodes(&self) -> String
Generates the response for CLUSTER NODES command.
Sourcepub fn moved_redirect(
&self,
slot: u16,
) -> Result<(u16, SocketAddr), ClusterError>
pub fn moved_redirect( &self, slot: u16, ) -> Result<(u16, SocketAddr), ClusterError>
Generates MOVED redirect information for a slot.