pub struct AdaptiveCompletionPolicy { /* private fields */ }Expand description
A bounded, restart-safe adaptive completion policy.
The policy adjusts its target chunk size toward target_duration,
clamped to bounds, based on the most recently committed chunk’s
observed duration. Install it via
crate::ChunkStep::with_completion_policy (directly, or nested inside
a CompositeCompletionPolicy at any depth): stream_registrations
reports its namespaced ItemStream registration under the same
identity returned by identity, bound to this exact
instance, so the confirmed target survives restart through the same
commit-boundary mechanism as any other component state – never a second
persistence path, and never two registrations that could drift onto
different instances.
§Restart safety
A process crash before a chunk commits leaves the previously committed
target authoritative: ItemStream::open restores exactly that target
from the durable envelope, never a value a still-open, not-yet-committed
attempt only speculated.
§Same-process rollback safety
ItemStream::update never mutates the confirmed target: it only
computes a candidate from the confirmed baseline and this attempt’s
freshly observed duration, storing it as a separate, speculative
pending value. That candidate is promoted to confirmed – becoming
visible to CompletionPolicy::is_complete – only when
CompletionPolicy::end_chunk observes
ChunkAttemptOutcome::Committed; every other outcome discards it. A
rolled-back attempt that gets replayed therefore always recomputes its
candidate from the same unmodified confirmed baseline, never a
corrupted or partially-applied one, and a rollback can never leave a
speculative target looking authoritative. The recomputed candidate
itself is not guaranteed identical to the discarded one: it is a
function of this replay’s freshly observed duration, which genuinely
can differ from the rolled-back attempt’s (only a fully deterministic
clock, as a test might inject, makes the two identical).
Implementations§
Source§impl AdaptiveCompletionPolicy
impl AdaptiveCompletionPolicy
Sourcepub fn new(
identity: ComponentStreamIdentity,
bounds: AdaptiveBounds,
target_duration: ChunkTimeThreshold,
clock: Arc<dyn Clock>,
) -> Arc<Self> ⓘ
pub fn new( identity: ComponentStreamIdentity, bounds: AdaptiveBounds, target_duration: ChunkTimeThreshold, clock: Arc<dyn Clock>, ) -> Arc<Self> ⓘ
Constructs an adaptive policy starting at bounds’s minimum target.
Returns Arc<Self> rather than Self: the policy holds a weak
self-reference so stream_registrations
can bind its persisted state to this exact instance regardless of
whether it ends up installed directly or nested inside a
CompositeCompletionPolicy.
Sourcepub const fn identity(&self) -> &ComponentStreamIdentity
pub const fn identity(&self) -> &ComponentStreamIdentity
Returns the namespace this policy’s persisted decision is registered under.
Sourcepub fn current_target(&self) -> ChunkSize
pub fn current_target(&self) -> ChunkSize
Returns the current confirmed target: the authoritative decision as
of the last chunk this process has observed commit (or restored at
ItemStream::open). Never a speculative, not-yet-committed
candidate.
Trait Implementations§
Source§impl CompletionPolicy for AdaptiveCompletionPolicy
impl CompletionPolicy for AdaptiveCompletionPolicy
Source§fn begin_chunk(&self)
fn begin_chunk(&self)
Source§fn is_complete(&self, items_read: ChunkCount) -> bool
fn is_complete(&self, items_read: ChunkCount) -> bool
Source§fn end_chunk(&self, outcome: ChunkAttemptOutcome)
fn end_chunk(&self, outcome: ChunkAttemptOutcome)
begin_chunk started. Read moreSource§fn fingerprint(&self) -> String
fn fingerprint(&self) -> String
Source§fn stream_registrations(
&self,
) -> Vec<(ComponentStreamIdentity, Arc<BoxedStream>, StreamStateContract)>
fn stream_registrations( &self, ) -> Vec<(ComponentStreamIdentity, Arc<BoxedStream>, StreamStateContract)>
ItemStream registration(s),
bound to the exact same instance this policy makes completion
decisions from – never a second, independently constructed instance
that could drift out of sync with it. Read moreSource§impl ItemStream for AdaptiveCompletionPolicy
impl ItemStream for AdaptiveCompletionPolicy
Source§async fn open(
&self,
context: StreamOpenContext<'_>,
) -> Result<StreamOpenOutcome, StreamOpenError>
async fn open( &self, context: StreamOpenContext<'_>, ) -> Result<StreamOpenOutcome, StreamOpenError>
Source§async fn update(
&self,
_context: StreamUpdateContext<'_>,
) -> Result<ComponentStateEnvelope, StreamUpdateError>
async fn update( &self, _context: StreamUpdateContext<'_>, ) -> Result<ComponentStateEnvelope, StreamUpdateError>
Source§async fn close(
&self,
_context: StreamCloseContext<'_>,
) -> Result<StreamCloseOutcome, StreamCloseError>
async fn close( &self, _context: StreamCloseContext<'_>, ) -> Result<StreamCloseOutcome, StreamCloseError>
Auto Trait Implementations§
impl !Freeze for AdaptiveCompletionPolicy
impl !RefUnwindSafe for AdaptiveCompletionPolicy
impl !UnwindSafe for AdaptiveCompletionPolicy
impl Send for AdaptiveCompletionPolicy
impl Sync for AdaptiveCompletionPolicy
impl Unpin for AdaptiveCompletionPolicy
impl UnsafeUnpin for AdaptiveCompletionPolicy
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
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