pub struct LeaderElection { /* private fields */ }Expand description
Leader election coordinator
Implementations§
Source§impl LeaderElection
impl LeaderElection
Sourcepub fn new(
node_id: String,
group_id: String,
config: ElectionConfig,
event_tx: Option<Sender<ElectionEvent>>,
) -> Self
pub fn new( node_id: String, group_id: String, config: ElectionConfig, event_tx: Option<Sender<ElectionEvent>>, ) -> Self
Create a new leader election coordinator
Sourcepub fn register_member(&self, node_id: String, priority: u32)
pub fn register_member(&self, node_id: String, priority: u32)
Register a cluster member
Sourcepub fn update_member_liveness(&self, node_id: &str, is_alive: bool)
pub fn update_member_liveness(&self, node_id: &str, is_alive: bool)
Update member liveness
Sourcepub fn remove_member(&self, node_id: &str)
pub fn remove_member(&self, node_id: &str)
Remove a member
Sourcepub fn state(&self) -> ElectionState
pub fn state(&self) -> ElectionState
Get current election state
Sourcepub fn leader(&self) -> Option<LeaderInfo>
pub fn leader(&self) -> Option<LeaderInfo>
Get current leader info
Sourcepub fn current_term(&self) -> u64
pub fn current_term(&self) -> u64
Get current term
Sourcepub fn fencing_token(&self) -> u64
pub fn fencing_token(&self) -> u64
Get fencing token (for write operations)
Sourcepub async fn start_election(&self) -> Result<bool, ElectionError>
pub async fn start_election(&self) -> Result<bool, ElectionError>
Start an election
Sourcepub fn handle_vote_request(&self, request: &VoteRequest) -> Vote
pub fn handle_vote_request(&self, request: &VoteRequest) -> Vote
Process a vote request from another candidate
Sourcepub async fn handle_vote(&self, vote: Vote) -> Result<bool, ElectionError>
pub async fn handle_vote(&self, vote: Vote) -> Result<bool, ElectionError>
Process a vote response
Sourcepub async fn accept_leader(
&self,
leader_info: LeaderInfo,
) -> Result<(), ElectionError>
pub async fn accept_leader( &self, leader_info: LeaderInfo, ) -> Result<(), ElectionError>
Accept a new leader (for followers)
Sourcepub async fn renew_lease(&self) -> Result<(), ElectionError>
pub async fn renew_lease(&self) -> Result<(), ElectionError>
Renew leadership lease (call periodically when leader)
Sourcepub async fn step_down(&self) -> Result<(), ElectionError>
pub async fn step_down(&self) -> Result<(), ElectionError>
Step down from leadership
Sourcepub fn needs_election(&self) -> bool
pub fn needs_election(&self) -> bool
Check if election is needed (leader lease expired)
Sourcepub async fn check_lease(&self)
pub async fn check_lease(&self)
Check lease and update state if expired
Sourcepub fn validate_fencing_token(&self, token: u64) -> bool
pub fn validate_fencing_token(&self, token: u64) -> bool
Validate a fencing token for write operations
Sourcepub fn stats(&self) -> ElectionStats
pub fn stats(&self) -> ElectionStats
Get election statistics
Auto Trait Implementations§
impl !Freeze for LeaderElection
impl !RefUnwindSafe for LeaderElection
impl Send for LeaderElection
impl Sync for LeaderElection
impl Unpin for LeaderElection
impl UnsafeUnpin for LeaderElection
impl !UnwindSafe for LeaderElection
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
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>
Converts
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>
Converts
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