pub struct LeaderSelector { /* private fields */ }Expand description
Simple leader selector that determines leadership based on cluster membership
Implementations§
Source§impl LeaderSelector
impl LeaderSelector
Sourcepub fn with_cluster(nodes: HashSet<NodeId>) -> Self
pub fn with_cluster(nodes: HashSet<NodeId>) -> Self
Create a new leader selector with initial cluster nodes
Sourcepub fn determine_leader(&self) -> Option<NodeId>
pub fn determine_leader(&self) -> Option<NodeId>
Determine the leader from the current cluster view
Returns the first node in the sorted cluster view, or None if empty
Sourcepub fn update_cluster_view(&mut self, nodes: HashSet<NodeId>) -> Option<NodeId>
pub fn update_cluster_view(&mut self, nodes: HashSet<NodeId>) -> Option<NodeId>
Update the cluster view with new set of nodes
Returns the new leader if it changed, or None if no change
Sourcepub fn add_node(&mut self, node_id: NodeId) -> Option<NodeId>
pub fn add_node(&mut self, node_id: NodeId) -> Option<NodeId>
Add a node to the cluster view
Returns the new leader if it changed
Sourcepub fn remove_node(&mut self, node_id: NodeId) -> Option<NodeId>
pub fn remove_node(&mut self, node_id: NodeId) -> Option<NodeId>
Remove a node from the cluster view
Returns the new leader if it changed
Sourcepub fn get_leader(&self) -> Option<NodeId>
pub fn get_leader(&self) -> Option<NodeId>
Get the current leader
Sourcepub fn is_leader(&self, node_id: NodeId) -> bool
pub fn is_leader(&self, node_id: NodeId) -> bool
Check if a specific node is the current leader
Sourcepub fn get_cluster_view(&self) -> &[NodeId]
pub fn get_cluster_view(&self) -> &[NodeId]
Get the current cluster view
Sourcepub fn get_leadership_info(&self) -> LeadershipInfo
pub fn get_leadership_info(&self) -> LeadershipInfo
Get current leadership information
Sourcepub fn cluster_size(&self) -> usize
pub fn cluster_size(&self) -> usize
Get the number of nodes in the cluster
Trait Implementations§
Source§impl Clone for LeaderSelector
impl Clone for LeaderSelector
Source§fn clone(&self) -> LeaderSelector
fn clone(&self) -> LeaderSelector
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LeaderSelector
impl Debug for LeaderSelector
Auto Trait Implementations§
impl Freeze for LeaderSelector
impl RefUnwindSafe for LeaderSelector
impl Send for LeaderSelector
impl Sync for LeaderSelector
impl Unpin for LeaderSelector
impl UnwindSafe for LeaderSelector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more