pub struct ElectionManager { /* private fields */ }Expand description
Election manager.
Implementations§
Source§impl ElectionManager
impl ElectionManager
Sourcepub fn new(
local_peer_id: PeerId,
config: ElectionConfig,
event_tx: Sender<ElectionEvent>,
) -> Self
pub fn new( local_peer_id: PeerId, config: ElectionConfig, event_tx: Sender<ElectionEvent>, ) -> Self
Create a new election manager.
Sourcepub fn state(&self) -> ElectionState
pub fn state(&self) -> ElectionState
Get the current election state.
Sourcepub fn current_master(&self) -> Option<PeerId>
pub fn current_master(&self) -> Option<PeerId>
Get the current master.
Sourcepub fn is_follower(&self) -> bool
pub fn is_follower(&self) -> bool
Check if we are a follower.
Sourcepub fn session_id(&self) -> u64
pub fn session_id(&self) -> u64
Get the current session ID.
Sourcepub fn record_command(&self)
pub fn record_command(&self)
Increment commands seen.
Sourcepub async fn start_election(&self) -> Result<()>
pub async fn start_election(&self) -> Result<()>
Start a new election campaign.
Sourcepub fn create_message(&self) -> ElectionMessage
pub fn create_message(&self) -> ElectionMessage
Create an election message to broadcast.
Sourcepub async fn process_message(
&self,
msg: ElectionMessage,
) -> Result<Option<ElectionMessage>>
pub async fn process_message( &self, msg: ElectionMessage, ) -> Result<Option<ElectionMessage>>
Process a received election message.
Sourcepub async fn check_election_complete(
&self,
all_peers: &[PeerId],
) -> Result<bool>
pub async fn check_election_complete( &self, all_peers: &[PeerId], ) -> Result<bool>
Check if election is complete (all candidates agree on winner).
Sourcepub async fn handle_master_loss(&self) -> Result<()>
pub async fn handle_master_loss(&self) -> Result<()>
Handle master loss (triggers new election).
Sourcepub async fn check_timeout(&self) -> Result<bool>
pub async fn check_timeout(&self) -> Result<bool>
Check for election timeout.
Sourcepub async fn force_master(&self) -> Result<()>
pub async fn force_master(&self) -> Result<()>
Force become master (for single-node clusters).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ElectionManager
impl !RefUnwindSafe for ElectionManager
impl Send for ElectionManager
impl Sync for ElectionManager
impl Unpin for ElectionManager
impl UnsafeUnpin for ElectionManager
impl !UnwindSafe for ElectionManager
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