Skip to main content

Batch

Struct Batch 

Source
pub struct Batch {
    pub shard_id: u16,
    pub events: Vec<InternalEvent>,
    pub sequence_start: u64,
    pub process_nonce: u64,
}
Expand description

A batch of events for adapter dispatch.

Batches are formed by shard workers and contain strictly ordered events from a single shard.

Fields§

§shard_id: u16

The shard this batch belongs to.

§events: Vec<InternalEvent>

Events in insertion order.

§sequence_start: u64

Sequence number of the first event in this batch. Used for idempotent retry handling.

§process_nonce: u64

Per-process nonce sampled once at process start. Adapters that persist (shard_id, sequence_start) for dedup (JetStream Nats-Msg-Id, Redis stream MAXLEN keys, etc.) must include this in the dedup key — otherwise a producer that restarts within the backend’s dedup window collides with its prior incarnation on (shard, 0, 0) and the new batches are silently discarded as duplicates.

BatchWorker::next_sequence is process-local and resets to zero on restart; the nonce is the global discriminator that makes the composite key globally unique across restarts even though the per-process counter is not durable.

Implementations§

Source§

impl Batch

Source

pub fn new( shard_id: u16, events: Vec<InternalEvent>, sequence_start: u64, ) -> Self

Create a new batch using the per-process nonce (batch_process_nonce). Convenience for tests and for callers that don’t thread a custom producer nonce through. Production paths constructed via the bus go through Self::with_nonce with the bus’s loaded producer_nonce_path value so retries dedup across process restart.

Source

pub fn with_nonce( shard_id: u16, events: Vec<InternalEvent>, sequence_start: u64, producer_nonce: u64, ) -> Self

Create a new batch with an explicit producer nonce. Used by the bus’s BatchWorker and remove_shard_internal’s stranded-flush so adapters keying dedup on (producer_nonce, shard, sequence_start, i) see the same nonce across process restart when the bus is configured with a producer_nonce_path.

A producer_nonce == 0 is coerced to 1 to preserve the non-zero invariant that batch_process_nonce and dedup_state::PersistentProducerNonce::create_new already uphold (each generates non-zero u64s and re-rolls on the astronomical 1-in-2^64 zero draw).

The zero coercion is defense-in-depth against future codecs: a downstream caller that constructs a Batch::with_nonce(..., 0) directly (e.g. tests, hand-built fixtures) would otherwise emit dedup_id keys starting 0: — collision-prone with any future codec that reserves 0 as “no nonce, use the legacy path.” Today’s adapter/jetstream.rs::on_batch just formats process_nonce as {:x} with no special-casing, so the hazard is latent rather than active. Coercing to 1 keeps the invariant that every shipped batch has a non-zero producer nonce regardless of caller hygiene.

Source

pub fn len(&self) -> usize

Returns the number of events in this batch.

Source

pub fn is_empty(&self) -> bool

Returns true if this batch is empty.

Trait Implementations§

Source§

impl Clone for Batch

Source§

fn clone(&self) -> Batch

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Batch

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Batch

§

impl RefUnwindSafe for Batch

§

impl Send for Batch

§

impl Sync for Batch

§

impl Unpin for Batch

§

impl UnsafeUnpin for Batch

§

impl UnwindSafe for Batch

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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