pub struct ReplicationQueues { /* private fields */ }Expand description
Central queue manager for the replication pipeline.
Maintains three stages of the pipeline with global dedup:
PendingVerify– keys awaiting quorum verification.FetchQueue– quorum-passed keys waiting for a fetch slot.InFlightFetch– keys actively being downloaded.
A key promoted from PendingVerify to fetch keeps a reserved verification
slot until it either stores successfully or returns to PendingVerify.
That reservation prevents unrelated new hints from stealing the capacity
needed to retry verification after every fetch source fails.
Implementations§
Source§impl ReplicationQueues
impl ReplicationQueues
Sourcepub fn add_pending_verify(
&mut self,
key: XorName,
entry: VerificationEntry,
) -> AdmissionResult
pub fn add_pending_verify( &mut self, key: XorName, entry: VerificationEntry, ) -> AdmissionResult
Add a key to pending verification if not already present in any queue.
Returns an AdmissionResult distinguishing the three outcomes:
Admitted— newly inserted.AlreadyPresent— Rule 8 cross-queue dedup. For a key still inpending_verify, the new advertiser is merged into its source set.CapacityRejected— the global bound was hit and no over-represented sender had reclaimable borrowed work; the incoming work is genuinely lost and the caller (e.g. bootstrap drain accounting, source-side retry) MUST treat this as still-outstanding work, not as “done”. Without this distinction a bootstrap snapshot whose hints are capacity-rejected would silently mark itself drained.
Sourcepub fn get_pending(&self, key: &XorName) -> Option<&VerificationEntry>
pub fn get_pending(&self, key: &XorName) -> Option<&VerificationEntry>
Get a reference to a pending verification entry.
Sourcepub fn set_pending_state(
&mut self,
key: &XorName,
state: VerificationState,
) -> bool
pub fn set_pending_state( &mut self, key: &XorName, state: VerificationState, ) -> bool
Advance a pending entry’s verification state, reporting whether the
key was found.
Narrow mutation API used by the verification state machine.
Sourcepub fn remove_pending(&mut self, key: &XorName) -> Option<VerificationEntry>
pub fn remove_pending(&mut self, key: &XorName) -> Option<VerificationEntry>
Remove a key from pending verification.
Sourcepub fn pending_keys(&self) -> Vec<XorName> ⓘ
pub fn pending_keys(&self) -> Vec<XorName> ⓘ
Collect all pending verification keys (for batch processing).
Sourcepub fn ready_pending_keys(&self, now: Instant) -> Vec<XorName> ⓘ
pub fn ready_pending_keys(&self, now: Instant) -> Vec<XorName> ⓘ
Collect pending verification keys whose retry delay has elapsed.
Sourcepub fn select_ready_pending_keys(
&mut self,
now: Instant,
limit: usize,
) -> Vec<XorName> ⓘ
pub fn select_ready_pending_keys( &mut self, now: Instant, limit: usize, ) -> Vec<XorName> ⓘ
Select a bounded, sender-fair set of ready verification keys.
Owners are served round-robin with persistent rotation between cycles; unused service is immediately redistributed. Within an owner’s share, protected retries and corroborated/older hints retain priority.
Sourcepub fn remove_hint_source(&mut self, source: &PeerId) -> Vec<XorName> ⓘ
pub fn remove_hint_source(&mut self, source: &PeerId) -> Vec<XorName> ⓘ
Remove a departed routing-table peer from every pending hint it advertised. Entries with no remaining live advertisers are dropped.
Returns keys that became orphaned so bootstrap accounting can retire them and re-check its drain transition.
Sourcepub fn defer_pending(&mut self, key: &XorName, retry_after: Duration) -> bool
pub fn defer_pending(&mut self, key: &XorName, retry_after: Duration) -> bool
Defer a pending key before its next verification attempt, by a flat delay.
For deferrals that are not a failed round: the caller chose not to ask (a full disk, say), so nothing was learned about the key and the unresolved-round count must not move.
Sourcepub fn defer_unresolved(
&mut self,
key: &XorName,
base_retry_after: Duration,
) -> Option<DeferralOutcome>
pub fn defer_unresolved( &mut self, key: &XorName, base_retry_after: Duration, ) -> Option<DeferralOutcome>
Defer a pending key whose verification round left it unresolved.
base_retry_after is the delay for the entry’s first such deferral.
Each consecutive one doubles it, capped at
VERIFICATION_RETRY_BACKOFF_MAX. A key that keeps failing is failing
for a reason a faster retry cannot change, so the cost of asking decays
rather than being paid in full every 15 seconds.
Returns None if the key is not pending, otherwise the resulting
DeferralOutcome, whose attempt is 1 on this entry’s first
unresolved round — the one worth reporting.
Sourcepub fn claim_no_holder_report(&mut self, key: &XorName) -> bool
pub fn claim_no_holder_report(&mut self, key: &XorName) -> bool
Claim this entry’s single no-holder warning.
Returns true the first time it is called for a given entry and false
after, so the caller can warn once and drop to debug thereafter.
Kept separate from Self::defer_unresolved on purpose. A round can
legitimately advance the failure count without producing a no-holder
result — an inconclusive quorum does exactly that — and if the two
shared state, such a round would consume the warning before the
condition it describes had ever been observed.
Sourcepub fn clear_unresolved(&mut self, key: &XorName) -> bool
pub fn clear_unresolved(&mut self, key: &XorName) -> bool
Clear an entry’s unresolved history after a round that found a holder.
The round succeeded even if the key could not move on — a full fetch queue leaves it pending — so it must not inherit the earlier backoff, and a later relapse deserves a fresh warning. Returns whether an entry was present to clear.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of keys in pending verification.
Sourcepub fn pending_count_for_owner(&self, owner: &PeerId) -> usize
pub fn pending_count_for_owner(&self, owner: &PeerId) -> usize
Number of pending entries currently charged to one capacity owner. Useful for fairness observability and invariant tests.
Sourcepub fn enqueue_fetch(
&mut self,
key: XorName,
distance: XorName,
sources: Vec<PeerId>,
) -> bool
pub fn enqueue_fetch( &mut self, key: XorName, distance: XorName, sources: Vec<PeerId>, ) -> bool
Enqueue a key for fetch with its distance and verified sources.
Returns true if the candidate was enqueued, false if it was
already present in any pipeline stage (Rule 8: cross-queue dedup) or
the fetch_queue is at MAX_FETCH_QUEUE.
Callers that have removed the key from pending_verify immediately
before this call should prefer promote_pending_to_fetch,
which performs the move atomically and leaves the pending entry in
place when the fetch queue is full (so verified work is retried on
the next cycle instead of being silently lost).
Sourcepub fn promote_pending_to_fetch(
&mut self,
key: XorName,
distance: XorName,
sources: Vec<PeerId>,
) -> bool
pub fn promote_pending_to_fetch( &mut self, key: XorName, distance: XorName, sources: Vec<PeerId>, ) -> bool
Atomically promote a key from pending_verify to fetch_queue.
Checks fetch_queue capacity FIRST, then removes the pending entry
and enqueues the fetch candidate. If fetch_queue is full, the
pending entry is left in place so the next verification cycle
can retry — preventing the silent-drop regression where a verified
key removed from pending_verify could be dropped by a full fetch
queue and lost from every stage.
Returns true on successful promotion, false when the fetch queue
is at capacity (pending entry preserved).
Sourcepub fn dequeue_fetch(&mut self) -> Option<FetchCandidate>
pub fn dequeue_fetch(&mut self) -> Option<FetchCandidate>
Dequeue the nearest fetch candidate.
Returns None when the queue is empty. Silently skips candidates
that are somehow already in-flight. Concurrency is enforced by the
fetch worker, not by this method.
A returned candidate may carry a live verification retry-slot
reservation. Callers must consume it with
Self::start_dequeued_fetch, Self::discard_fetch_candidate, or
Self::requeue_candidate_for_verification so that reservation is
either transferred, released, or restored to pending_verify.
Sourcepub fn fetch_queue_count(&self) -> usize
pub fn fetch_queue_count(&self) -> usize
Number of keys waiting in the fetch queue.
Sourcepub fn start_fetch(
&mut self,
key: XorName,
source: PeerId,
all_sources: Vec<PeerId>,
)
pub fn start_fetch( &mut self, key: XorName, source: PeerId, all_sources: Vec<PeerId>, )
Mark a key as in-flight (actively being fetched from source).
Candidates returned by Self::dequeue_fetch MUST be consumed by a
by-value dequeued-candidate method instead. They may carry a live
verification retry-slot reservation; Self::start_dequeued_fetch
transfers that reservation into the in-flight entry.
Sourcepub fn start_fetch_with_retry(
&mut self,
key: XorName,
source: PeerId,
all_sources: Vec<PeerId>,
retry_verification: Option<VerificationEntry>,
)
pub fn start_fetch_with_retry( &mut self, key: XorName, source: PeerId, all_sources: Vec<PeerId>, retry_verification: Option<VerificationEntry>, )
Mark a key as in-flight and retain verification retry metadata.
This is for direct starts where the caller already owns any retry
reservation paired with retry_verification. Candidates obtained from
Self::dequeue_fetch MUST be consumed intact via a by-value
dequeued-candidate method, otherwise their reserved verification
capacity can be orphaned.
Sourcepub fn start_dequeued_fetch(
&mut self,
candidate: FetchCandidate,
source: PeerId,
)
pub fn start_dequeued_fetch( &mut self, candidate: FetchCandidate, source: PeerId, )
Consume a dequeued fetch candidate and transfer its retry reservation into the in-flight entry.
Sourcepub fn complete_fetch(&mut self, key: &XorName) -> Option<InFlightEntry>
pub fn complete_fetch(&mut self, key: &XorName) -> Option<InFlightEntry>
Mark a fetch as completed (success or permanent failure).
Sourcepub fn discard_fetch_candidate(&mut self, candidate: FetchCandidate)
pub fn discard_fetch_candidate(&mut self, candidate: FetchCandidate)
Drop a dequeued fetch candidate without starting it.
Sourcepub fn retry_fetch(&mut self, key: &XorName) -> Option<PeerId>
pub fn retry_fetch(&mut self, key: &XorName) -> Option<PeerId>
Mark the current fetch attempt as failed and try the next untried source.
Returns the next source peer if one is available, or None if all
sources have been exhausted.
Sourcepub fn requeue_candidate_for_verification(
&mut self,
candidate: FetchCandidate,
retry_after: Duration,
) -> bool
pub fn requeue_candidate_for_verification( &mut self, candidate: FetchCandidate, retry_after: Duration, ) -> bool
Consume a dequeued candidate and restore its verification entry for a later retry when retry metadata exists.
Sourcepub fn requeue_fetch_for_verification(
&mut self,
key: &XorName,
retry_after: Duration,
) -> bool
pub fn requeue_fetch_for_verification( &mut self, key: &XorName, retry_after: Duration, ) -> bool
Complete an exhausted fetch and restore its verification entry for a later retry when retry metadata exists.
Sourcepub fn in_flight_count(&self) -> usize
pub fn in_flight_count(&self) -> usize
Number of in-flight fetches.
Sourcepub fn contains_key(&self, key: &XorName) -> bool
pub fn contains_key(&self, key: &XorName) -> bool
Check if a key is present in any pipeline stage.
Sourcepub fn is_bootstrap_work_empty(&self, bootstrap_keys: &HashSet<XorName>) -> bool
pub fn is_bootstrap_work_empty(&self, bootstrap_keys: &HashSet<XorName>) -> bool
Check if all bootstrap-related work is done.
Returns true when none of the given bootstrap keys remain in any queue.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ReplicationQueues
impl RefUnwindSafe for ReplicationQueues
impl Send for ReplicationQueues
impl Sync for ReplicationQueues
impl Unpin for ReplicationQueues
impl UnsafeUnpin for ReplicationQueues
impl UnwindSafe for ReplicationQueues
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> 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<'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> 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