pub struct InFlightSet { /* private fields */ }Expand description
The dispatcher’s in-flight (progress) set: the dispatched-but-unfinished tasks, keyed by
task id. Phase 4 of the dispatcher rationalization replaces the contended
Arc<Mutex<HashMap<i64, TaskProgress>>> with a sharded, lock-free [DashMap] — so the
ventilator’s lease (Self::lease), the sink’s return (Self::claim_result), and the reaper
sweep (Self::take_expired) no longer serialise on one global lock — plus an AtomicUsize
size counter so the per-request backpressure check (in_flight_saturated) reads the size in
O(1) without locking or scanning the map.
It also holds, for late_result_window seconds, each task the
reaper released (re-queued or dead-lettered), with the worker of every attempt, so the sink can
accept a result whose lease expired unless a result that must stand already landed
(KNOWN_ISSUES D-26). Those entries are not in flight: Self::len, Self::is_empty and
Self::ids count only leased tasks. Every transition of one task id happens under its map
shard’s lock, so a lease, a result and a reap of the same task cannot interleave.
The counters are maintained in lock-step with the map here (the only place any is mutated),
so they converge to exactly the map’s state; a momentary ±1 skew between a map mutation and its
atomic update is harmless for backpressure (self-correcting, never a leak). Shared as
Arc<InFlightSet> across the ventilator / sink / reaper threads.
Implementations§
Source§impl InFlightSet
impl InFlightSet
Sourcepub fn with_late_result_window(seconds: i64) -> Self
pub fn with_late_result_window(seconds: i64) -> Self
A new, empty in-flight set that keeps reaped tasks for late results for seconds (<= 0:
no late results are accepted).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Current number of in-flight tasks — an O(1) atomic load (the backpressure hot read), not a map scan.
Sourcepub fn awaiting_replies(&self) -> usize
pub fn awaiting_replies(&self) -> usize
Number of in-flight tasks still awaiting a reply: Self::len less those whose current
attempt answered with an unusable result or a retryable cause, which only the reaper moves
on. A bounded run’s sink stops once dispatching is done and this is zero.
Sourcepub fn settling_len(&self) -> usize
pub fn settling_len(&self) -> usize
Number of tasks held out of flight for a late result.
Sourcepub fn insert(&self, progress_task: TaskProgress)
pub fn insert(&self, progress_task: TaskProgress)
Record a dispatched task as in-flight (keyed by task.id), unconditionally. Re-inserting the
same id overwrites without double-counting. The ventilator leases through Self::lease.
Sourcepub fn lease(&self, progress_task: TaskProgress) -> bool
pub fn lease(&self, progress_task: TaskProgress) -> bool
Lease a task: record it in flight, unless it is a re-queued retry that a late result already
finished while it waited in the dispatch queue (KNOWN_ISSUES D-26) — then false, and the
caller drops it instead of converting it again. A first attempt (retries == 0: a fresh
fetch, e.g. an operator’s rerun of the task) is always leased; a held task’s earlier
attempts become its older attempts. A retry takes the last retryable cause reported while
it was queued.
Sourcepub fn remove(&self, taskid: i64) -> Option<TaskProgress>
pub fn remove(&self, taskid: i64) -> Option<TaskProgress>
Remove and return the in-flight task with taskid. Negative (mock-reply) ids are never
tracked, so they short-circuit to None; removing an already-gone task is a no-op that never
underflows the counter, and a task held for a late result is left alone.
Sourcepub fn task(&self, taskid: i64) -> Option<Task>
pub fn task(&self, taskid: i64) -> Option<Task>
The task a result for taskid would be reported against — in flight or held for a late
result — without claiming it. The sink checks the result’s service and output path against
it first, so an unplaceable result leaves the task exactly where it was (the reaper’s).
Sourcepub fn note_received(&self, taskid: i64)
pub fn note_received(&self, taskid: i64)
A result for in-flight task taskid was received and handed to its archive writer: the
reaper leaves the task alone until the writer decides the result (Self::claim_result,
Self::defer_retryable, Self::note_unusable_reply), so a result that arrives at the
deadline is not raced by a re-lease.
Sourcepub fn note_unusable_reply(&self, taskid: i64, worker: &str, received: bool)
pub fn note_unusable_reply(&self, taskid: i64, worker: &str, received: bool)
The worker worker replied for in-flight task taskid with a result that could not be used
(empty, unreadable, unwritable, unplaceable — D-18): the task stays in flight for the reaper
(retry, then dead-letter). If the reply is the current attempt’s, the task awaits no reply.
received says whether the reply was recorded by Self::note_received (an unplaceable
reply never was).
Sourcepub fn defer_retryable(
&self,
taskid: i64,
worker: &str,
cause: Vec<NewTaskMessage>,
) -> RetryDecision
pub fn defer_retryable( &self, taskid: i64, worker: &str, cause: Vec<NewTaskMessage>, ) -> RetryDecision
The worker worker reported a retryable cause for task taskid (the harness’s
Fatal:timeout:wallclock, Fatal:oom:shed, Fatal:crash:unrecorded, tagged
Info:cortex:retryable): not a result to record, but the task’s retry budget’s business.
For the attempt in flight with budget left, the cause becomes the task’s last cause and its
lease is due now: the next reap re-queues it (RetryDecision::Deferred). On the task’s last
attempt the cause is its final record (RetryDecision::Final): the caller publishes it as a
stand-in, held like an accepted failure. For a task re-queued meanwhile, the newest attempt’s
cause rides along to its retry. Otherwise — an older attempt’s cause, a task whose result
already landed, or one already dead-lettered — it is dropped.
Sourcepub fn claim_result(
&self,
taskid: i64,
worker: &str,
status: TaskStatus,
) -> ResultClaim
pub fn claim_result( &self, taskid: i64, worker: &str, status: TaskStatus, ) -> ResultClaim
Decide a result with status status for taskid from the worker worker (KNOWN_ISSUES
D-26): accept it unless a result that must stand already landed — a newer attempt’s, or a
usable one that this failure (Fatal/Invalid) must not replace. An accepted result takes
the task out of flight; if it belongs to an older attempt than the one in flight, the task is
held so the newer attempt’s result can still replace it, and a result for a re-queued task
keeps the queued retry from being leased (Self::lease).
Sourcepub fn note_publish_failed(
&self,
taskid: i64,
replaced: Option<(usize, TaskStatus)>,
)
pub fn note_publish_failed( &self, taskid: i64, replaced: Option<(usize, TaskStatus)>, )
The accepted result for held task taskid could not be published: restore the result it
replaced (replaced, from ResultClaim::Accept), or, when it replaced none, leave the
task open for any later result — a publish failure never costs the task a good result.
Sourcepub fn take_expired(&self) -> Vec<TaskProgress>
pub fn take_expired(&self) -> Vec<TaskProgress>
Take every in-flight task past its visibility-timeout deadline (the reaper sweep), except one
whose received result is still with its writer. Each one stays in the set, out of flight, for
the late-result window (unless the window is off or SETTLING_HARD_LIMIT is reached): a
result of any of its attempts may still land there.
Sourcepub fn forget_settled(&self) -> usize
pub fn forget_settled(&self) -> usize
Forget the tasks whose late-result window has passed. Returns how many. Run on the reaper’s cadence.
Sourcepub fn queued_retries(&self) -> Vec<TaskProgress>
pub fn queued_retries(&self) -> Vec<TaskProgress>
The retries the reaper queued in the ventilator that no lease or late result has taken yet,
rebuilt for a restarted ventilator (its queue died with it) to queue again rather than
reset to TODO: a reset task would be re-fetched as a new run, and its earlier attempts’
late results dropped as stale (D-28). Due at once (created_at 0).
Sourcepub fn worked_earlier_run(&self, taskid: i64, worker: &str) -> bool
pub fn worked_earlier_run(&self, taskid: i64, worker: &str) -> bool
Whether worker worked an attempt of taskid that the set still holds — so a fresh fetch
leased to it would start a new run whose results could not be told from the old run’s.
Sourcepub fn kept_on_restart(&self) -> Vec<i64>
pub fn kept_on_restart(&self) -> Vec<i64>
The task ids a restarted ventilator must not reset to TODO: every task in flight (its
result may still come) and every task held for late results — a queued retry (queued again,
Self::queued_retries), or one whose report (a late result, a stand-in) may not be written
yet: a reset row is no longer at the report’s lease mark, so finalize would drop it (D-28).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for InFlightSet
impl !RefUnwindSafe for InFlightSet
impl Send for InFlightSet
impl Sync for InFlightSet
impl Unpin for InFlightSet
impl UnsafeUnpin for InFlightSet
impl UnwindSafe for InFlightSet
Blanket Implementations§
§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read more§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read more§fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
§fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
self into a collection.fn mapped<U, F, A>(self, f: F) -> SmallVec<A>where
F: FnMut(T) -> U,
A: Array<Item = U>,
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§impl<T> IntoSql for T
impl<T> IntoSql for T
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);