pub struct QuorumStateMachine { /* private fields */ }Expand description
The hand-rolled KIP-595 + KIP-996 quorum state machine.
The state machine is pure and deterministic. It consumes Events, reads
the log through LogView, takes the current time as an injected
SimInstant, and produces a list of Actions for the caller to
execute. It never touches the clock, the wire, or the log bytes directly.
Implementations§
Source§impl QuorumStateMachine
impl QuorumStateMachine
Sourcepub fn apply_voter_set(
&mut self,
voters: VoterSet,
now: SimInstant,
) -> Vec<Action>
pub fn apply_voter_set( &mut self, voters: VoterSet, now: SimInstant, ) -> Vec<Action>
Apply the latest voter set read from the Raft log or a snapshot.
KIP-853 requires replicas to use an uncommitted VotersRecord
immediately. The durable engine owns record history and invokes this
method again with the preceding set if the log is truncated.
Sourcepub fn set_kraft_version(&mut self, version: u16)
pub fn set_kraft_version(&mut self, version: u16)
Apply a committed KRaftVersionRecord.
Sourcepub fn commit_voter_set(&mut self)
pub fn commit_voter_set(&mut self)
Forget the preceding voter view once the latest voter record commits.
Sourcepub fn current_or_adjacent_voter_entry(&self, id: NodeId) -> Option<&Voter>
pub fn current_or_adjacent_voter_entry(&self, id: NodeId) -> Option<&Voter>
Voter id from the current voter set, or from the adjacent set of an
uncommitted KIP-853 change. A leader that only the adjacent set names is
still followed (see handle_begin_quorum_epoch), so its endpoints are
looked up the same way.
Sourcepub fn finish_local_leader_removal(&mut self, now: SimInstant) -> Vec<Action>
pub fn finish_local_leader_removal(&mut self, now: SimInstant) -> Vec<Action>
Complete removal of the local leader after the reduced voter set has committed. Fetch serving continues until the engine invokes this edge.
The removed leader becomes a discovering observer and arms its fetch
timer. No later leader announces itself to a node outside the voter
set, so the Fetch that the timer sends is how this node finds the new
leader. Kafka’s removed leader also goes on as an observer of its
successor, and DescribeQuorum on that successor lists it.
Source§impl QuorumStateMachine
impl QuorumStateMachine
Sourcepub fn adopt_replica_progress(&mut self, id: NodeId, progress: ReplicaProgress)
pub fn adopt_replica_progress(&mut self, id: NodeId, progress: ReplicaProgress)
Give the voter id the progress it had while it was an observer, as
Kafka does when a replica joins the voter set
(LeaderState.updateVoterAndObserverStates reuses its ReplicaState).
Nothing happens unless this replica leads and id is another voter.
Source§impl QuorumStateMachine
impl QuorumStateMachine
Sourcepub fn resign_for_shutdown(&mut self, now: SimInstant) -> Vec<Action>
pub fn resign_for_shutdown(&mut self, now: SimInstant) -> Vec<Action>
Resign the leadership this replica holds because it is shutting down.
A leader becomes Resigned and sends EndQuorumEpoch, naming the other
voters by descending fetch offset as its preferred successors. This is
pollLeader with a GracefulShutdown set. Any other role holds no
leadership to hand over, and nothing changes.
Sourcepub fn graceful_shutdown_complete(&self) -> bool
pub fn graceful_shutdown_complete(&self) -> bool
Whether a shutting-down replica has nothing left to hand over.
This is Kafka’s KafkaRaftClient.maybeCompleteShutdown: an observer, the
only voter, and a replica that knows a leader other than itself stop at
once. A leader, a resigned leader, and a voter between leaders keep
running until a remote leader is known, which is what lets the quorum
elect a successor without them.
Source§impl QuorumStateMachine
impl QuorumStateMachine
Sourcepub fn advance_epoch_for_vote(
&mut self,
candidate: ReplicaKey,
epoch: u32,
now: SimInstant,
) -> Vec<Action>
pub fn advance_epoch_for_vote( &mut self, candidate: ReplicaKey, epoch: u32, now: SimInstant, ) -> Vec<Action>
Kafka’s transitionToUnattached on seeing a vote or pre-vote from
candidate at an epoch above ours: adopt that epoch as an unattached
replica with no leader and no vote. A request at our own epoch, or below
it, changes nothing, and neither does one between replicas that are not
both voters, which this replica denies without acting on its epoch.
KafkaRaftClient.handleVoteRequest makes this transition before it checks
the voter key the request names, so the engine calls it for a request it
will refuse for its key, and the response then carries the new epoch.
Source§impl QuorumStateMachine
impl QuorumStateMachine
Sourcepub fn new(
me: NodeId,
state: QuorumState,
timeouts: QuorumTimeouts,
) -> QuorumStateMachine
pub fn new( me: NodeId, state: QuorumState, timeouts: QuorumTimeouts, ) -> QuorumStateMachine
timeouts.election is the base extent of an election timer, before
jitter, and callers vary it per node for liveness. timeouts.fetch is
the fetch watchdog.
This constructor rounds both values to whole milliseconds. That is the
domain of both the verified jitter kernel and the SimInstant clock.
pub fn quorum_state(&self) -> &QuorumState
pub fn role(&self) -> &Role
Sourcepub fn known_leader(&self) -> Option<NodeId>
pub fn known_leader(&self) -> Option<NodeId>
The leader this replica knows for its epoch: the one it follows, or the one a prospective gave up on when it began its pre-vote.
This is Kafka’s QuorumState.hasLeader, which counts a
ProspectiveState’s retained leader. A response that names the leader
of the current epoch moves a replica to it only while this is None.
pub fn is_voter(&self) -> bool
pub fn on_event( &mut self, event: Event, log: &dyn LogView, now: SimInstant, ) -> Vec<Action>
Trait Implementations§
Source§impl Clone for QuorumStateMachine
impl Clone for QuorumStateMachine
Source§fn clone(&self) -> QuorumStateMachine
fn clone(&self) -> QuorumStateMachine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QuorumStateMachine
impl Debug for QuorumStateMachine
impl Eq for QuorumStateMachine
Source§impl Hash for QuorumStateMachine
impl Hash for QuorumStateMachine
Source§impl PartialEq for QuorumStateMachine
impl PartialEq for QuorumStateMachine
impl StructuralPartialEq for QuorumStateMachine
Auto Trait Implementations§
impl Freeze for QuorumStateMachine
impl RefUnwindSafe for QuorumStateMachine
impl Send for QuorumStateMachine
impl Sync for QuorumStateMachine
impl Unpin for QuorumStateMachine
impl UnsafeUnpin for QuorumStateMachine
impl UnwindSafe for QuorumStateMachine
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
impl<F> FnGhost for F
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);