#[non_exhaustive]pub struct RetentionPolicy {
pub terminal_max_age: Duration,
pub parked_max_age: Option<Duration>,
pub batch_size: u32,
pub idempotency_key_max_age: Option<Duration>,
pub max_batches: Option<u32>,
pub max_events_per_live_task: Option<u64>,
}Expand description
How long terminal tasks are kept, and how aggressively they are removed.
#[non_exhaustive]: build it with new and the with_*
setters, which cover every field. STABILITY.md §4 lists the
configuration structs that carry this marking so a new option on any of
them is additive; this one was missed by the 0.12.0 conversion that
introduced the rule, and adding
idempotency_key_max_age is what found
it.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.terminal_max_age: DurationTerminal tasks whose last update is older than this are eligible.
Measured against updated_at, which the store maintains, and evaluated
by the database rather than the caller — an application clock that runs
fast would otherwise delete work that is younger than it looks.
parked_max_age: Option<Duration>Parked tasks (input-required, auth-required) whose last update is
older than this are eligible too. None, the default, deletes none:
a parked task is a workflow waiting on someone, and every release
before this field kept it for ever (ADR 0011; ADR 0056 amends it).
§What deleting one costs
The task is deleted, with its event log, not cancelled: a store cannot
write what a CancelTask writes (the event a stream replays, the push
notification, the audit record), and a purge that made up a
cancellation without them would leave a task that says canceled and
a history that does not. So a client that answers the task afterwards
is told it was not found, and a stream open on it ends without a
terminal state. The age is measured from updated_at, by the
database’s clock, as for terminal tasks.
A task that a turn is running on now (an unexpired turn claim) is skipped however old it is: a continuation in flight is not abandoned.
§Idempotency keys
A key must outlive the task it names, so
effective_idempotency_key_max_age
is never below this either.
batch_size: u32Rows per DELETE. Default 1,000.
The point of batching is the lock, not the throughput. One statement deleting a million rows holds locks and grows a transaction for as long as it takes; a thousand statements deleting a thousand rows each let every other query through in between.
idempotency_key_max_age: Option<Duration>Idempotency keys older than this are deleted. None keeps them for
ever, which is what every release before this one did.
§Why a key has to expire at all
A key is released when the send it guards fails, and otherwise it stays — deliberately, because it has to outlive the task it names or a late retry would execute a second time. Nothing else ever removed one. A busy deployment therefore accumulated a row per keyed send for the life of the database, and the index that makes the claim atomic grew with it.
§What expiring one costs
Exactly what the key was preventing: a retry arriving after the key expires re-executes the send. That is the trade every idempotency key has, and the reason the default is a full day rather than something tidier — it has to exceed the longest window in which a client might still retry, and clients retry in seconds.
§It is never allowed below terminal_max_age
A key expiring while the task it names is still retained is the bad
case: the retry does not replay, it creates a second task alongside
the first, and the caller ends up with two ids for one logical send.
So the sweep uses
effective_idempotency_key_max_age,
which never returns less than
terminal_max_age — the invariant holds by
construction rather than by the operator having read this paragraph.
max_batches: Option<u32>Stop after this many batches, leaving the rest for the next call.
None runs until nothing is left.
Set it to bound how long one sweep can run when the first sweep after switching retention on has years of backlog to work through.
max_events_per_live_task: Option<u64>The most events a live (non-terminal) task’s log keeps, or None, the
default: a live task’s log then grows for as long as the task runs.
With it, purge_expired also compacts the log of each live task
holding more than this many events to the newest this many, dropping
only events the stored task already reflects (audit H13, ADR 0047). A
subscriber that asks to resume from a dropped position is answered
with the task’s snapshot, as a lagged one is, never with a replay
that silently skips. 0 is taken as 1: the last event is kept, as
a continued task numbers its events on from it.
Implementations§
Source§impl RetentionPolicy
impl RetentionPolicy
Sourcepub const fn new(terminal_max_age: Duration) -> RetentionPolicy
pub const fn new(terminal_max_age: Duration) -> RetentionPolicy
A policy keeping terminal tasks for terminal_max_age, with default
batching.
Sourcepub const fn with_max_events_per_live_task(
self,
max: Option<u64>,
) -> RetentionPolicy
pub const fn with_max_events_per_live_task( self, max: Option<u64>, ) -> RetentionPolicy
Compacts each live task’s log to its newest max events; see
max_events_per_live_task. None
turns it off.
Sourcepub const fn with_parked_max_age(self, max_age: Duration) -> RetentionPolicy
pub const fn with_parked_max_age(self, max_age: Duration) -> RetentionPolicy
Deletes parked tasks (input-required, auth-required) that have sat
unanswered for max_age. Unset by default: nothing parked is deleted.
See parked_max_age for what it deletes and
what that costs. Measured in whole seconds, as
terminal_max_age is: a sub-second part is
dropped.
Sourcepub const fn with_batch_size(self, batch_size: u32) -> RetentionPolicy
pub const fn with_batch_size(self, batch_size: u32) -> RetentionPolicy
Sets the rows-per-DELETE batch size. Zero is treated as one.
Sourcepub const fn with_idempotency_key_max_age(
self,
max_age: Option<Duration>,
) -> RetentionPolicy
pub const fn with_idempotency_key_max_age( self, max_age: Option<Duration>, ) -> RetentionPolicy
Sets how long an idempotency key is kept; None keeps them for ever.
See idempotency_key_max_age for what
expiring one costs and why the sweep will not honour a value below
terminal_max_age.
Sourcepub fn effective_idempotency_key_max_age(&self) -> Option<Duration>
pub fn effective_idempotency_key_max_age(&self) -> Option<Duration>
The key age the sweep actually uses: never below
terminal_max_age, nor below
parked_max_age when one is set.
A key must outlive the task it names. Deleting one while its task is
still retained turns the next retry into a second task rather than a
replay, so a policy that asks for that is clamped rather than obeyed —
the same shape as effective_batch_size — which is pub(crate) and
feature-gated, so it cannot be linked from a public doc comment —
where a nonsensical value is floored at the nearest sensible one
instead of being honoured into a defect.
Sourcepub const fn with_max_batches(self, max_batches: u32) -> RetentionPolicy
pub const fn with_max_batches(self, max_batches: u32) -> RetentionPolicy
Bounds how many batches a single sweep runs.
Trait Implementations§
Source§impl Clone for RetentionPolicy
impl Clone for RetentionPolicy
Source§fn clone(&self) -> RetentionPolicy
fn clone(&self) -> RetentionPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Forget for RetentionPolicy
impl Freeze for RetentionPolicy
impl Move for RetentionPolicy
impl RefUnwindSafe for RetentionPolicy
impl Send for RetentionPolicy
impl Sync for RetentionPolicy
impl Unpin for RetentionPolicy
impl UnsafeUnpin for RetentionPolicy
impl UnwindSafe for RetentionPolicy
Blanket Implementations§
§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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].