pub struct ClusterManager { /* private fields */ }Expand description
Cluster Manager — coordinates consensus, membership, and partition assignment
Implementations§
Source§impl ClusterManager
impl ClusterManager
Sourcepub fn new(self_id: u32, partition_count: u32) -> Self
pub fn new(self_id: u32, partition_count: u32) -> Self
Create a new cluster manager
§Arguments
self_id: This node’s unique IDpartition_count: Total partitions for the cluster
Sourcepub fn registry(&self) -> &Arc<NodeRegistry>
pub fn registry(&self) -> &Arc<NodeRegistry>
Get the underlying node registry (for partition routing)
Sourcepub fn current_term(&self) -> u64
pub fn current_term(&self) -> u64
Get the current term
Sourcepub async fn current_role(&self) -> MemberRole
pub async fn current_role(&self) -> MemberRole
Get this node’s current role
Sourcepub async fn add_member(&self, member: ClusterMember)
pub async fn add_member(&self, member: ClusterMember)
Register a new member in the cluster
Sourcepub async fn remove_member(&self, node_id: u32) -> Option<ClusterMember>
pub async fn remove_member(&self, node_id: u32) -> Option<ClusterMember>
Remove a member from the cluster
Sourcepub fn update_member_heartbeat(
&self,
node_id: u32,
wal_offset: u64,
healthy: bool,
)
pub fn update_member_heartbeat( &self, node_id: u32, wal_offset: u64, healthy: bool, )
Update a member’s health status and WAL offset
Sourcepub fn get_member(&self, node_id: u32) -> Option<ClusterMember>
pub fn get_member(&self, node_id: u32) -> Option<ClusterMember>
Get a member by ID
Sourcepub fn all_members(&self) -> Vec<ClusterMember>
pub fn all_members(&self) -> Vec<ClusterMember>
Get all members
Sourcepub fn healthy_members(&self) -> Vec<ClusterMember>
pub fn healthy_members(&self) -> Vec<ClusterMember>
Get healthy members
Sourcepub fn member_count(&self) -> usize
pub fn member_count(&self) -> usize
Get the number of members
Sourcepub async fn handle_vote_request(&self, request: &VoteRequest) -> VoteResponse
pub async fn handle_vote_request(&self, request: &VoteRequest) -> VoteResponse
Handle a vote request (simplified Raft RequestVote RPC)
Grants vote if:
- Request term >= our term
- We haven’t voted for someone else in this term
- Candidate’s WAL offset >= our knowledge of the log
Sourcepub async fn start_election(&self) -> u64
pub async fn start_election(&self) -> u64
Start an election: increment term and vote for self
Returns the new term. Caller should then send VoteRequests to other nodes.
Sourcepub async fn become_leader(&self, term: u64)
pub async fn become_leader(&self, term: u64)
Declare self as leader after winning an election
Should only be called after receiving a majority of votes.
Sourcepub async fn accept_leader(&self, leader_id: u32, term: u64)
pub async fn accept_leader(&self, leader_id: u32, term: u64)
Accept a leader (after receiving an AppendEntries or heartbeat from a valid leader)
Sourcepub fn select_leader_candidate(&self) -> Option<u32>
pub fn select_leader_candidate(&self) -> Option<u32>
Select the best candidate for leader from healthy members
Deterministic: highest WAL offset wins; on tie, lowest node ID wins.
Sourcepub async fn status(&self) -> ClusterStatus
pub async fn status(&self) -> ClusterStatus
Get full cluster status
Auto Trait Implementations§
impl !Freeze for ClusterManager
impl !RefUnwindSafe for ClusterManager
impl Send for ClusterManager
impl Sync for ClusterManager
impl Unpin for ClusterManager
impl UnsafeUnpin for ClusterManager
impl !UnwindSafe for ClusterManager
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more