Skip to main content

Queue

Struct Queue 

Source
pub struct Queue<E: Context, V: CodecShared> { /* private fields */ }
Expand description

A durable, at-least-once delivery queue with per-item acknowledgment.

Items are durably stored in a journal and survive crashes. Queue::init returns the queue, which writes items, and its Reader, which delivers them. The reader must acknowledge each item individually after processing. Items can be acknowledged out of order, enabling parallel processing.

§Operations

  • append / commit: Write items to the journal, then persist them and publish them to the reader. Appended items are lost on restart if not committed.
  • enqueue: Append + commit in one step. The item is durable before return.
  • sync: Commit, then prune completed sections below the reader’s ack floor.
  • Reader::recv / Reader::try_recv: Return the next unacked committed item in FIFO order.
  • Reader::ack / Reader::ack_up_to: Mark items as processed (in-memory only).

§Acknowledgment

Acks are tracked in-memory with an ack_floor (all positions below are acked) plus an RMap of acked positions above the floor. When items are acked contiguously from the floor, the floor advances automatically.

Acks are not persisted. The durable equivalent is the journal’s pruning boundary, advanced by sync. On restart, all non-pruned items are re-delivered regardless of prior ack state.

§Crash Recovery

On restart, ack_floor is set to the journal’s pruning boundary. Items that were pruned are gone. Everything else is re-delivered. Applications must handle duplicates (idempotent processing).

Storage-mutating functions consume the queue and return it only on success: an error (or a dropped future) destroys the handle. The reader then delivers every published item and returns None.

Implementations§

Source§

impl<E: Context, V: CodecShared> Queue<E, V>

Source

pub async fn init( context: E, cfg: Config<V::Cfg>, ) -> Result<(Self, Reader<E, V>), Error>

Initialize a queue from storage, returning it with its Reader.

On first initialization, creates an empty queue. On restart, the reader begins from the journal’s pruning boundary (providing at-least-once delivery for all non-pruned items). Both handles must be dropped before the queue is reopened.

§Errors

Returns an error if the underlying journal cannot be initialized.

Source

pub async fn enqueue(self, item: &V) -> Result<(Self, u64), Error>

Append and commit an item, returning its position. The reader can receive the item once this returns.

§Errors

Returns an error if the underlying storage operation fails.

Source

pub async fn enqueue_bulk( self, items: impl IntoIterator<Item = impl Borrow<V>>, ) -> Result<(Self, Range<u64>), Error>

Append a batch of items with a single commit, returning positions [start, end). The reader can receive the items once this returns.

§Errors

Returns an error if any append or the final commit fails.

Source

pub async fn append(self, item: &V) -> Result<(Self, u64), Error>

Append an item without committing, returning its position. The reader can receive the item after the next Self::commit or Self::sync.

§Errors

Returns an error if the underlying storage operation fails.

Source

pub async fn commit(self) -> Result<Self, Error>

Durably persist appended items and publish them to the reader.

This does not persist acknowledgements. For a stronger guarantee that eliminates potential recovery and prunes acknowledged items, use Self::sync instead.

Source

pub async fn sync(self) -> Result<Self, Error>

Durably persist the queue, guaranteeing the current state will survive a crash, and that no recovery will be needed on startup.

This also prunes items below the reader’s ack floor and publishes the result to the reader.

Source

pub fn size(&self) -> u64

Returns the total number of items that have been appended.

Source

pub async fn destroy(self) -> Result<(), Error>

Destroy the queue, removing all data from disk.

Trait Implementations§

Source§

impl<E: Context, V: CodecShared> Debug for Queue<E, V>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E, V> !RefUnwindSafe for Queue<E, V>

§

impl<E, V> !UnwindSafe for Queue<E, V>

§

impl<E, V> Freeze for Queue<E, V>
where Journal<E, V>: Freeze, Sender<Arc<Reader<'static, E, V>>>: Freeze,

§

impl<E, V> Send for Queue<E, V>
where Journal<E, V>: Send, Sender<Arc<Reader<'static, E, V>>>: Send,

§

impl<E, V> Sync for Queue<E, V>
where Journal<E, V>: Sync, Sender<Arc<Reader<'static, E, V>>>: Sync,

§

impl<E, V> Unpin for Queue<E, V>
where Journal<E, V>: Unpin, Sender<Arc<Reader<'static, E, V>>>: Unpin,

§

impl<E, V> UnsafeUnpin for Queue<E, V>
where Journal<E, V>: UnsafeUnpin, Sender<Arc<Reader<'static, E, V>>>: UnsafeUnpin,

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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> Threaded<T> for T

Source§

type Rest = ()

The outputs beyond the threaded value.
Source§

fn split(self) -> (T, ())

Splits into the threaded value and the extra outputs.
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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