pub struct Shard {
pub id: u16,
/* private fields */
}Expand description
A single shard with its own ring buffer and timestamp generator.
Fields§
§id: u16Shard identifier.
Implementations§
Source§impl Shard
impl Shard
Sourcepub fn with_metrics(
id: u16,
capacity: usize,
metrics: Arc<ShardMetricsCollector>,
) -> Self
pub fn with_metrics( id: u16, capacity: usize, metrics: Arc<ShardMetricsCollector>, ) -> Self
Create a new shard with a metrics collector for dynamic scaling.
Sourcepub fn counters(&self) -> Arc<ShardCounters> ⓘ
pub fn counters(&self) -> Arc<ShardCounters> ⓘ
Clone the atomic counter handle (for lock-free aggregation).
Sourcepub fn set_metrics_collector(&mut self, metrics: Arc<ShardMetricsCollector>)
pub fn set_metrics_collector(&mut self, metrics: Arc<ShardMetricsCollector>)
Set the metrics collector.
Sourcepub fn try_push_raw(&mut self, raw: Bytes) -> Result<u64, IngestionError>
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.
Sourcepub fn try_push(&mut self, raw: JsonValue) -> Result<u64, IngestionError>
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.
Sourcepub fn pop_batch(&mut self, max: usize) -> Vec<InternalEvent>
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.
Sourcepub fn pop_batch_into(
&mut self,
dst: &mut Vec<InternalEvent>,
max: usize,
) -> usize
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.
Sourcepub fn try_pop(&mut self) -> Option<InternalEvent>
pub fn try_pop(&mut self) -> Option<InternalEvent>
Try to pop a single event from the ring buffer.
Sourcepub fn fill_ratio(&self) -> f64
pub fn fill_ratio(&self) -> f64
Get the fill ratio (0.0 - 1.0).
Sourcepub fn stats(&self) -> ShardStats
pub fn stats(&self) -> ShardStats
Get a snapshot of shard statistics.
Sourcepub fn record_batch_dispatch(&self)
pub fn record_batch_dispatch(&self)
Record a batch dispatch.