Skip to main content

Outbox

Struct Outbox 

Source
pub struct Outbox<S: OutboxSink> { /* private fields */ }
Expand description

The handle callers stage through; owns the queue and its writer task.

Implementations§

Source§

impl<S: OutboxSink> Outbox<S>

Source

pub fn new(sink: S, concurrency: usize, limits: OutboxLimits) -> Arc<Self> ⓘ

Creates the outbox around sink and starts its writer.

concurrency is the most writes run at once across every tenant and lane, which bounds the connections the sink may hold; limits are the most items and bytes admitted at once, which bound the memory queued, waiting, retrying, and in-flight work may hold.

§Panics

Panics when called outside a Tokio runtime, because the writer task is spawned immediately.

Source

pub fn sink(&self) -> &S

Borrows the sink this outbox writes through.

Source

pub fn stage(&self, tenant: DataTenantId, item: impl Into<S::Item>)

Queues one item for tenant without waiting and never fails.

The item is admitted and counted pending before it is sent, so the writer can never release it first. Admission happens under the queue’s read lock, so nothing is admitted once shutdown has taken the queue. When either unreserved limit would be passed the item is shed: counted lost with LossReason::Shed and recorded by Self::shed. Once shutdown has begun, or if the writer is gone, the item is counted lost with LossReason::Shutdown and logged.

Source

pub fn reserve( self: &Arc<Self>, slots: usize, ) -> Result<Reservation<S>, OutboxFull>

Reserves slots items of capacity for a producer that must refuse its caller instead of losing what it stages.

The reservation is admitted at once and holds its slots until each is staged through it or it is dropped, which releases the unused rest. An item staged through it keeps its slot until it is written or lost. Unreserved items never count against reservations.

§Errors

Returns OutboxFull, admitting nothing, when the reservation would take reservations past RESERVED_SHARE of the capacity.

Source

pub fn pending(&self) -> usize

Returns the number of items not yet written.

Source

pub async fn settle(&self, deadline: Instant) -> usize

Waits until deadline for everything staged so far to be written, without closing the outbox, and returns how many items remain.

The outbox keeps accepting items throughout; callers that read the sink’s destination right after staging use this to observe their items.

Source

pub async fn shutdown(&self, deadline: Instant) -> usize

Stops taking items, keeps writing and retrying until deadline, and returns how many items were lost at the deadline.

The staging sender is dropped before the first await, which is a one-way fence: everything staged before it drains, and every later Outbox::stage is refused and counted lost without entering the queue. Shed counts not yet recorded are recorded at the fence. Items still unwritten at the deadline are abandoned with the writer, which cancels any in-flight write; once the writer is gone they are counted in outbox_events_lost_total with LossReason::Shutdown, logged, and released from pending() and outbox_pending, which both end at zero, and released from their admission shares. When shutdown is called concurrently, exactly one caller reports the loss and settles both shares, and the others report zero. Unspent Reservation slots stay held until their reservation drops.

Trait Implementations§

Source§

impl<S> AuditStage for Outbox<S>
where S: OutboxSink, S::Item: From<AuditEvent>,

Source§

fn stage(&self, tenant: DataTenantId, event: AuditEvent)

Stages event on this outbox through its ordinary non-blocking Outbox::stage.

Source§

impl<S: OutboxSink> Debug for Outbox<S>

Names the outbox and its pending count, so values carrying a handle — a staged write that hands off to a second outbox — stay debuggable.

Source§

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

Write the sink’s name and a relaxed snapshot of the pending count; queued items and the sink itself are never formatted.

§Errors

Returns the formatter’s error when it rejects a write.

Auto Trait Implementations§

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

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

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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