Skip to main content

UploadQueue

Struct UploadQueue 

Source
pub struct UploadQueue<J> { /* private fields */ }
Expand description

The per-server upload queue with one shared byte budget. See the module docs.

Implementations§

Source§

impl<J: Clone> UploadQueue<J>

Source

pub fn new(budget: u64, stall_after: Duration) -> Self

An empty queue whose lanes share budget bytes in flight (at least one byte), and give their reservations up after stall_after without progress. Lanes open with the default LaneWindows and a DEFAULT_LANE_RETRY_BUDGET.

Source

pub fn with_windows(self, windows: LaneWindows) -> Self

Open every lane after this with windows as its own caps. A lane already open keeps its caps; Self::set_windows changes one.

Source

pub fn with_retry_budget(self, retries: u32) -> Self

Open every lane after this with a retry budget of retries.

Source

pub fn budget(&self) -> u64

The shared byte budget.

Source

pub fn in_use(&self) -> u64

The bytes reserved by ranges in flight, across every lane.

Source

pub fn lane_retries(&mut self, server: &ServerKey) -> LaneRetries

server’s shared retry budget, opening its lane if it has none. Hand it to the client that drives the lane’s sessions (UploadClient::with_lane_retries) so the client’s request retries and this queue’s Self::retry spend from one pool.

Source

pub fn sessions_window(&self, server: &ServerKey, now: Instant) -> u32

W for server at now: the lane’s own cap lowered by fresh advice and the live-session cap; the default cap for a server with no lane.

Source

pub fn servers(&self) -> impl Iterator<Item = &ServerKey>

The servers that hold a lane, in round-robin order.

Source

pub fn queued(&self, server: &ServerKey) -> usize

Jobs still queued (not in flight) on server’s lane; zero for a server with none.

Source

pub fn in_flight(&self, server: &ServerKey) -> usize

Jobs in flight on server’s lane.

Source

pub fn is_empty(&self) -> bool

Whether no lane holds any work, queued or in flight.

Source

pub fn set_windows(&mut self, server: &ServerKey, windows: LaneWindows)

Set server’s own caps (power saver or a thermal state lowers them), opening its lane if it has none. A narrower window takes effect as work finishes; nothing in flight is revoked, and a session already granted keeps its P.

Source

pub fn set_advice( &mut self, server: &ServerKey, advice: ServerAdvice, received: Instant, )

Record the X-Capsule-Advice server sent at received, replacing any earlier advice. Its sessions lowers W until its ttl runs out; its ranges lowers P for the sessions granted after it. Advice can only lower the lane’s own caps, never raise them.

Source

pub fn set_session_cap(&mut self, server: &ServerKey, cap: u32)

Cap W at the account’s live-session cap on server (at least one), so the lane never opens a session the server would refuse for being one too many.

Source

pub fn set_session_ranges( &mut self, id: GrantId, advice: &ServerAdvice, ) -> Option<u32>

Narrow grant id’s P to the in-flight cap its server advertised for that session (the ranges of the advice on its create or HEAD). A session’s P never widens. Returns the session’s P, or None when the grant is no longer in flight.

Source

pub fn enqueue(&mut self, server: &ServerKey, job: QueuedJob<J>)

Queue job at the back of its tier on server’s lane, opening the lane if it has none.

Source

pub fn rebuild_lane( &mut self, server: &ServerKey, jobs: impl IntoIterator<Item = QueuedJob<J>>, ) -> Vec<GrantId>

Replace everything server’s lane holds with jobs, derived from that server’s own truth on resume. Any job still in flight on the lane is superseded and its range reservations released (the caller has stopped it); its id is returned and later reports on it are ignored. The lane’s windows, advice and retry budget are kept, and so is any pause still running (a server’s Retry-After binds whatever work the lane holds).

Source

pub fn withdraw(&mut self, selects: impl Fn(&J) -> bool) -> Vec<GrantId>

Remove every job selects picks from every lane, queued or in flight: the redaction a delete makes of one asset’s upload (Organization — Deletion State Machine), which spans every server the asset was queued for. A job in flight is superseded and its range reservations released (the caller stops it); its id is returned and later reports on it are ignored. Every other job keeps its place, and no lane’s windows or pause change.

Source

pub fn defer(&mut self, server: &ServerKey, until: Instant)

Hold server’s lane until until (its backoff, or the server’s Retry-After). Other lanes are served meanwhile. A later deadline replaces an earlier one.

Source

pub fn next(&mut self, now: Instant) -> Option<Grant<J>>

Admit the next job, if any lane can run one now. Admission reserves no bytes; the session’s ranges do, through Self::reserve_range.

Lanes are tried round-robin from the one after the lane served last. A lane is passed over while it is paused, has no queued job, or already holds its W sessions in flight; a lane never skips past its own head, so tier order holds inside it.

Source

pub fn reserve_range( &mut self, id: GrantId, len: u64, now: Instant, ) -> Result<RangeId, RangeRefused>

Reserve len bytes of the shared budget for one range grant id is about to send.

The reservation is the range’s length clamped to the budget, so a range longer than the whole budget still runs once the budget is otherwise free. It is refused while the session holds its P ranges in flight (RangeRefused::WindowFull) or the budget left cannot hold it (RangeRefused::BudgetFull); the caller waits for a release and asks again. A reservation counts as progress on the lane.

The budget serves waiting grants first-come: a grant refused for the budget joins a line in the order it first asked, and while that line holds an earlier grant every later ask is refused too, however little it wants. So a holder that releases its range and asks for the next one in the same breath goes behind whoever was already waiting, and a range clamped to the whole budget runs once the reservations ahead of it drain, rather than waiting for every holder to stop on its own. A grant that leaves flight leaves the line with it; a caller that stops asking for a grant it still holds must complete, requeue or retry it, or the line waits on it.

Source

pub fn release_range(&mut self, range: RangeId, now: Instant) -> bool

Range range returned (sent, refused or abandoned): release its bytes. It counts as progress on its lane. Returns whether the reservation was still held; one released with its session (a completion, requeue, revocation or rebuild) is already gone.

Source

pub fn waiting_for_budget(&self) -> usize

Grants still in flight that wait in the budget’s line for a range, first-come. A caller that wakes its waiters on a release wakes them again after a reservation while this is not zero, so the next in line asks once the one ahead of it has been served.

Source

pub fn ranges_in_flight(&self, id: GrantId) -> usize

Ranges grant id holds in flight; zero for a grant no longer in flight.

Source

pub fn progress(&mut self, id: GrantId, now: Instant) -> bool

Record that grant id moved bytes, so its lane is not counted as stalled. Returns whether the grant is still in flight.

Source

pub fn complete(&mut self, id: GrantId, now: Instant) -> bool

Grant id finished (sent, merged, or failed for good): release every range it still holds. Returns whether the grant was still in flight. The successes a lane’s retry budget earns back from are the requests that succeeded, which the client driving the lane records on the shared budget (Self::lane_retries).

Source

pub fn requeue(&mut self, id: GrantId) -> bool

Grant id must run again because it was interrupted, not because it failed (a stall cut or a cancelled task): release its ranges and return its job to the front of its tier. Charges no retry. Returns whether the grant was still in flight.

Source

pub fn retry(&mut self, id: GrantId) -> RetryAdmission<J>

Grant id failed with an error the classification permits retrying: release its ranges and spend one retry from its lane’s shared budget. While the budget holds, the job returns to the front of its tier; once it is spent, the job leaves the queue and is handed back, so a server that fails everything costs at most the lane’s budget.

Source

pub fn reclaim_stalled(&mut self, now: Instant) -> Vec<GrantId>

Take the budget back from every lane whose jobs in flight have made no progress for the stall bound: their sessions and every range reservation they hold. Each such lane’s jobs return to the front of their tiers, charging no retry, and the lane is not served for at least one more stall bound (longer where a later deadline is already held), so the budget goes to the lanes still moving. Returns the revoked grants, which the caller stops.

Trait Implementations§

Source§

impl<J: Debug> Debug for UploadQueue<J>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<J> Freeze for UploadQueue<J>

§

impl<J> RefUnwindSafe for UploadQueue<J>
where J: RefUnwindSafe,

§

impl<J> Send for UploadQueue<J>
where J: Send,

§

impl<J> Sync for UploadQueue<J>
where J: Sync,

§

impl<J> Unpin for UploadQueue<J>
where J: Unpin,

§

impl<J> UnsafeUnpin for UploadQueue<J>

§

impl<J> UnwindSafe for UploadQueue<J>
where J: UnwindSafe,

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
§

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

§

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

§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

impl<T> Instrument for T

§

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

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

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> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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
§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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