Skip to main content

BatchWorker

Struct BatchWorker 

Source
pub struct BatchWorker { /* private fields */ }
Expand description

Batch worker state.

Manages batch assembly for a single shard.

Implementations§

Source§

impl BatchWorker

Source

pub fn new( shard_id: u16, config: BatchConfig, next_sequence_published: Arc<AtomicU64>, producer_nonce: u64, ) -> Self

Create a new batch worker.

next_sequence_published is the bus-owned mirror of next_sequence. Pass Arc::new(AtomicU64::new(0)) if the caller doesn’t need to observe the post-exit sequence; production paths share it with bus::remove_shard_internal.

producer_nonce is stamped on every produced Batch for cross-process dedup. The bus passes its loaded nonce in; tests can use any u64 (typically 0 or the per-process default).

Source

pub fn add_events(&mut self, events: Vec<InternalEvent>) -> Option<Batch>

Add events to the current batch.

Returns a completed batch if thresholds are met, or None if more events are needed.

§Empty-input side effect

Passing an empty events vec is not a no-op. The BatchWorker’s recv-timeout arm calls add_events(vec![]) specifically to drive a check_timeout round, which may flush the in-memory current_batch if max_delay has elapsed since the last event arrived. Callers who want “true no-op on empty input” must check events.is_empty() themselves before calling.

Pre-fix this side effect was not documented and surprised callers expecting add_events([]) to be inert. The fix is documentation only — the BatchWorker’s timeout flush relies on this behavior, so removing the side effect would break the timeout-flush mechanism in bus.rs.

Source

pub fn check_timeout(&mut self) -> Option<Batch>

Check if the batch should be flushed due to timeout.

Pre-fix perf #38 in docs/performance/net-perf-analysis.md this was private and the bus’s timeout branch called add_events(vec![]) as the indirection — an empty Vec allocation per timeout tick purely as a sentinel. The method is now pub so callers can express the intent directly without the alloc and without the documented “empty add_events has a side effect” footgun.

Source

pub fn flush(&mut self) -> Batch

Force flush the current batch, even if thresholds aren’t met.

Source

pub fn has_pending(&self) -> bool

Check if there are pending events.

Source

pub fn pending_count(&self) -> usize

Get the number of pending events.

Source

pub fn target_batch_size(&self) -> usize

Get the current target batch size.

Source

pub fn time_until_timeout(&self) -> Option<Duration>

Get time until the current batch times out.

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<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, 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