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>
impl<J: Clone> UploadQueue<J>
Sourcepub fn new(budget: u64, stall_after: Duration) -> Self
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.
Sourcepub fn with_windows(self, windows: LaneWindows) -> Self
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.
Sourcepub fn with_retry_budget(self, retries: u32) -> Self
pub fn with_retry_budget(self, retries: u32) -> Self
Open every lane after this with a retry budget of retries.
Sourcepub fn lane_retries(&mut self, server: &ServerKey) -> LaneRetries
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.
Sourcepub fn sessions_window(&self, server: &ServerKey, now: Instant) -> u32
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.
Sourcepub fn servers(&self) -> impl Iterator<Item = &ServerKey>
pub fn servers(&self) -> impl Iterator<Item = &ServerKey>
The servers that hold a lane, in round-robin order.
Sourcepub fn queued(&self, server: &ServerKey) -> usize
pub fn queued(&self, server: &ServerKey) -> usize
Jobs still queued (not in flight) on server’s lane; zero for a server with none.
Sourcepub fn set_windows(&mut self, server: &ServerKey, windows: LaneWindows)
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.
Sourcepub fn set_advice(
&mut self,
server: &ServerKey,
advice: ServerAdvice,
received: Instant,
)
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.
Sourcepub fn set_session_cap(&mut self, server: &ServerKey, cap: u32)
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.
Sourcepub fn set_session_ranges(
&mut self,
id: GrantId,
advice: &ServerAdvice,
) -> Option<u32>
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.
Sourcepub fn enqueue(&mut self, server: &ServerKey, job: QueuedJob<J>)
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.
Sourcepub fn rebuild_lane(
&mut self,
server: &ServerKey,
jobs: impl IntoIterator<Item = QueuedJob<J>>,
) -> Vec<GrantId>
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).
Sourcepub fn withdraw(&mut self, selects: impl Fn(&J) -> bool) -> Vec<GrantId>
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.
Sourcepub fn defer(&mut self, server: &ServerKey, until: Instant)
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.
Sourcepub fn next(&mut self, now: Instant) -> Option<Grant<J>>
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.
Sourcepub fn reserve_range(
&mut self,
id: GrantId,
len: u64,
now: Instant,
) -> Result<RangeId, RangeRefused>
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.
Sourcepub fn release_range(&mut self, range: RangeId, now: Instant) -> bool
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.
Sourcepub fn waiting_for_budget(&self) -> usize
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.
Sourcepub fn ranges_in_flight(&self, id: GrantId) -> usize
pub fn ranges_in_flight(&self, id: GrantId) -> usize
Ranges grant id holds in flight; zero for a grant no longer in flight.
Sourcepub fn progress(&mut self, id: GrantId, now: Instant) -> bool
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.
Sourcepub fn complete(&mut self, id: GrantId, now: Instant) -> bool
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).
Sourcepub fn requeue(&mut self, id: GrantId) -> bool
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.
Sourcepub fn retry(&mut self, id: GrantId) -> RetryAdmission<J>
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.
Sourcepub fn reclaim_stalled(&mut self, now: Instant) -> Vec<GrantId>
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§
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> 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
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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