Skip to main content

ReplicationQueues

Struct ReplicationQueues 

Source
pub struct ReplicationQueues { /* private fields */ }
Expand description

Central queue manager for the replication pipeline.

Maintains three stages of the pipeline with global dedup:

  1. PendingVerify – keys awaiting quorum verification.
  2. FetchQueue – quorum-passed keys waiting for a fetch slot.
  3. 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

Source

pub fn new() -> Self

Create new empty queues.

Source

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 in pending_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.
Source

pub fn get_pending(&self, key: &XorName) -> Option<&VerificationEntry>

Get a reference to a pending verification entry.

Source

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.

Source

pub fn remove_pending(&mut self, key: &XorName) -> Option<VerificationEntry>

Remove a key from pending verification.

Source

pub fn pending_keys(&self) -> Vec<XorName> ⓘ

Collect all pending verification keys (for batch processing).

Source

pub fn ready_pending_keys(&self, now: Instant) -> Vec<XorName> ⓘ

Collect pending verification keys whose retry delay has elapsed.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn pending_count(&self) -> usize

Number of keys in pending verification.

Source

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.

Source

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).

Source

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).

Source

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.

Source

pub fn fetch_queue_count(&self) -> usize

Number of keys waiting in the fetch queue.

Source

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.

Source

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.

Source

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.

Source

pub fn complete_fetch(&mut self, key: &XorName) -> Option<InFlightEntry>

Mark a fetch as completed (success or permanent failure).

Source

pub fn discard_fetch_candidate(&mut self, candidate: FetchCandidate)

Drop a dequeued fetch candidate without starting it.

Source

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.

Source

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.

Source

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.

Source

pub fn in_flight_count(&self) -> usize

Number of in-flight fetches.

Source

pub fn contains_key(&self, key: &XorName) -> bool

Check if a key is present in any pipeline stage.

Source

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.

Source

pub fn evict_stale(&mut self, max_age: Duration) -> Vec<XorName> ⓘ

Evict stale pending-verification entries older than max_age.

Trait Implementations§

Source§

impl Default for ReplicationQueues

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more