pub struct WriteBuffer { /* private fields */ }Expand description
In-memory write buffer for time-series data points.
Implementations§
Source§impl WriteBuffer
impl WriteBuffer
Sourcepub fn new(config: WriteBufferConfig) -> Self
pub fn new(config: WriteBufferConfig) -> Self
Create a new write buffer with the given configuration.
Sourcepub fn state(&self) -> BufferState
pub fn state(&self) -> BufferState
Current buffer state.
Sourcepub fn stats(&self) -> &BufferStats
pub fn stats(&self) -> &BufferStats
Return a snapshot of current buffer statistics.
Sourcepub fn push(&mut self, point: DataPoint) -> WriteBufferResult<()>
pub fn push(&mut self, point: DataPoint) -> WriteBufferResult<()>
Push a data point into the buffer.
§Errors
Returns WriteBufferError::BufferFull when the buffer is at capacity
and backpressure should be applied by the caller.
Sourcepub fn push_batch(
&mut self,
points: impl IntoIterator<Item = DataPoint>,
) -> usize
pub fn push_batch( &mut self, points: impl IntoIterator<Item = DataPoint>, ) -> usize
Push multiple data points at once.
Points are added until the buffer is full; returns the number actually pushed.
Sourcepub fn should_flush(&self) -> bool
pub fn should_flush(&self) -> bool
True if the current policy conditions require a flush.
Sourcepub fn flush(&mut self) -> WriteBufferResult<Vec<DataPoint>>
pub fn flush(&mut self) -> WriteBufferResult<Vec<DataPoint>>
Flush all buffered data points, sorted by timestamp.
Writes a WAL entry if enable_wal is set and a sink is provided.
Returns the flushed points in ascending timestamp order.
Sourcepub fn flush_with_wal<W: WalSink>(
&mut self,
wal: &mut W,
) -> WriteBufferResult<Vec<DataPoint>>
pub fn flush_with_wal<W: WalSink>( &mut self, wal: &mut W, ) -> WriteBufferResult<Vec<DataPoint>>
Flush with a WAL sink.
Sourcepub fn partial_flush(
&mut self,
count: usize,
) -> WriteBufferResult<Vec<DataPoint>>
pub fn partial_flush( &mut self, count: usize, ) -> WriteBufferResult<Vec<DataPoint>>
Flush only the oldest data points (those with the smallest timestamps).
count specifies how many points to flush (0 = use config default).
Points are sorted by timestamp before selection.
Auto Trait Implementations§
impl Freeze for WriteBuffer
impl RefUnwindSafe for WriteBuffer
impl Send for WriteBuffer
impl Sync for WriteBuffer
impl Unpin for WriteBuffer
impl UnsafeUnpin for WriteBuffer
impl UnwindSafe for WriteBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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