Skip to main content

Shard

Struct Shard 

Source
pub struct Shard {
    pub id: u16,
    /* private fields */
}
Expand description

A single shard with its own ring buffer and timestamp generator.

Fields§

§id: u16

Shard identifier.

Implementations§

Source§

impl Shard

Source

pub fn new(id: u16, capacity: usize) -> Self

Create a new shard.

Source

pub fn with_metrics( id: u16, capacity: usize, metrics: Arc<ShardMetricsCollector>, ) -> Self

Create a new shard with a metrics collector for dynamic scaling.

Source

pub fn counters(&self) -> Arc<ShardCounters>

Clone the atomic counter handle (for lock-free aggregation).

Source

pub fn set_metrics_collector(&mut self, metrics: Arc<ShardMetricsCollector>)

Set the metrics collector.

Source

pub fn try_push_raw(&mut self, raw: Bytes) -> Result<u64, IngestionError>

Try to push a raw event (pre-serialized bytes) into the shard’s ring buffer. Returns the assigned insertion timestamp on success.

This is the fastest ingestion path - no serialization or hashing needed.

Source

pub fn try_push(&mut self, raw: JsonValue) -> Result<u64, IngestionError>

Try to push a JSON value into the shard’s ring buffer. Returns the assigned insertion timestamp on success.

This serializes the value once before storing.

Source

pub fn pop_batch(&mut self, max: usize) -> Vec<InternalEvent>

Pop a batch of events from the ring buffer.

Allocates a fresh Vec. Prefer pop_batch_into in drain loops where the per-cycle Vec allocation should happen outside the shard mutex.

Source

pub fn pop_batch_into( &mut self, dst: &mut Vec<InternalEvent>, max: usize, ) -> usize

Pop a batch of events into a caller-owned buffer.

Append semantics: does not clear dst; reserves count slots and pushes drained elements onto the end. Returns the number drained this call. Use this in steady-state drain loops where the caller keeps a scratch Vec across cycles, so the per-cycle allocation moves out of the consumer’s critical section.

Source

pub fn try_pop(&mut self) -> Option<InternalEvent>

Try to pop a single event from the ring buffer.

Source

pub fn len(&self) -> usize

Get the current buffer length.

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty.

Source

pub fn is_full(&self) -> bool

Check if the buffer is full.

Source

pub fn fill_ratio(&self) -> f64

Get the fill ratio (0.0 - 1.0).

Source

pub fn capacity(&self) -> usize

Get the ring buffer capacity.

Source

pub fn stats(&self) -> ShardStats

Get a snapshot of shard statistics.

Source

pub fn record_batch_dispatch(&self)

Record a batch dispatch.

Auto Trait Implementations§

§

impl !Freeze for Shard

§

impl !RefUnwindSafe for Shard

§

impl Send for Shard

§

impl Sync for Shard

§

impl Unpin for Shard

§

impl UnsafeUnpin for Shard

§

impl !UnwindSafe for Shard

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