pub struct RoundConsensusTracker {
pub policy: QuorumPolicy,
pub stats: ConsensusStats,
/* private fields */
}Expand description
Central registry for federated learning round consensus.
All public methods are safe to call from multiple threads concurrently.
Internal state is protected by a single RwLock; the design keeps
critical sections short to minimise contention.
Fields§
§policy: QuorumPolicyPolicy applied to every quorum evaluation.
stats: ConsensusStatsAggregate statistics.
Implementations§
Source§impl RoundConsensusTracker
impl RoundConsensusTracker
Sourcepub fn new(policy: QuorumPolicy) -> Self
pub fn new(policy: QuorumPolicy) -> Self
Create a new tracker with the given quorum policy.
Sourcepub fn begin_round(
&self,
round_id: RoundId,
expected_peers: Vec<String>,
) -> Result<(), ConsensusError>
pub fn begin_round( &self, round_id: RoundId, expected_peers: Vec<String>, ) -> Result<(), ConsensusError>
Register a new round. Returns ConsensusError::RoundAlreadyExists
if a round with the same ID already exists.
Sourcepub fn cast_vote(&self, vote: PeerVote) -> Result<QuorumResult, ConsensusError>
pub fn cast_vote(&self, vote: PeerVote) -> Result<QuorumResult, ConsensusError>
Cast a vote for a round.
After recording the vote the quorum policy is evaluated. If the
policy reaches a terminal verdict (Commit or Abort) the round’s
status is updated atomically and the corresponding stat counter is
incremented.
§Errors
ConsensusError::RoundNotFound— no such roundConsensusError::RoundNotActive— round is already committed/abortedConsensusError::DuplicateVote— peer already voted in this round
Sourcepub fn check_round(&self, round_id: &RoundId) -> Option<QuorumResult>
pub fn check_round(&self, round_id: &RoundId) -> Option<QuorumResult>
Evaluate the current quorum state of a round without casting a new
vote. Returns None if the round does not exist.
Sourcepub fn abort_round(
&self,
round_id: &RoundId,
reason: &str,
) -> Result<(), ConsensusError>
pub fn abort_round( &self, round_id: &RoundId, reason: &str, ) -> Result<(), ConsensusError>
Forcibly abort a round.
§Errors
ConsensusError::RoundNotFound— no such roundConsensusError::RoundNotActive— round already in terminal state
Sourcepub fn complete_rounds(&self) -> Vec<u64>
pub fn complete_rounds(&self) -> Vec<u64>
Return the IDs of all rounds currently in a terminal state (committed or aborted).
Sourcepub fn active_round_count(&self) -> usize
pub fn active_round_count(&self) -> usize
Return the number of rounds currently in the Active state.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RoundConsensusTracker
impl !RefUnwindSafe for RoundConsensusTracker
impl Send for RoundConsensusTracker
impl Sync for RoundConsensusTracker
impl Unpin for RoundConsensusTracker
impl UnsafeUnpin for RoundConsensusTracker
impl UnwindSafe for RoundConsensusTracker
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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