pub struct Voter<S>where
S: LastVoteStore,{ /* private fields */ }Expand description
A voting member. Wraps the durable LastVoteStore and applies the
vote rule. The voter is the seat of correctness: the watermark rule and
the durable double-vote guard both live here.
Implementations§
Source§impl<S> Voter<S>where
S: LastVoteStore,
impl<S> Voter<S>where
S: LastVoteStore,
pub fn new(id: impl Into<String>, store: S) -> Voter<S>
pub fn id(&self) -> &str
Sourcepub fn current_term(&self) -> Result<u64, LastVoteError>
pub fn current_term(&self) -> Result<u64, LastVoteError>
This voter’s current term — the highest term it has durably recorded.
Sourcepub fn consider(
&self,
req: &VoteRequest,
commit_watermark: u64,
) -> Result<VoteDecision, LastVoteError>
pub fn consider( &self, req: &VoteRequest, commit_watermark: u64, ) -> Result<VoteDecision, LastVoteError>
Consider a vote request against the current commit_watermark.
The decision order is deliberate:
- Watermark first — the safety core. A candidate that cannot carry an acknowledged write is refused regardless of term, so the durability guarantee can never be traded away for liveness.
- Stale term — reject candidates from a superseded term.
- Double-vote guard — within a term, a voter grants exactly one candidate; a re-ask by the same candidate is idempotently re-granted.
For a real (non-dry-run) grant, the new (term, candidate) is
persisted before Granted is returned, so the durability holds
across a crash at any point after the caller observes the grant.
Auto Trait Implementations§
impl<S> Freeze for Voter<S>where
S: Freeze,
impl<S> RefUnwindSafe for Voter<S>where
S: RefUnwindSafe,
impl<S> Send for Voter<S>where
S: Send,
impl<S> Sync for Voter<S>where
S: Sync,
impl<S> Unpin for Voter<S>where
S: Unpin,
impl<S> UnsafeUnpin for Voter<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for Voter<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request