pub struct BatchWriter { /* private fields */ }Expand description
High-throughput write path that buffers metric points and flushes in batches.
§Usage
use oxirs_tsdb::write::batch_writer::{BatchWriter, BatchWriterConfig, MetricPoint};
use std::path::Path;
let cfg = BatchWriterConfig::default();
let mut bw = BatchWriter::open(Path::new("/tmp/tsdb_wal.bin"), cfg)?;
bw.write_point(MetricPoint::new("cpu", 1_700_000_000_000, 42.5))?;
let seq = bw.flush()?;
println!("flushed; last seq = {seq}");Implementations§
Source§impl BatchWriter
impl BatchWriter
Sourcepub fn open(path: &Path, config: BatchWriterConfig) -> TsdbResult<Self>
pub fn open(path: &Path, config: BatchWriterConfig) -> TsdbResult<Self>
Open (or create) a BatchWriter backed by a CRC-protected WAL at path.
Sourcepub fn total_flushed(&self) -> u64
pub fn total_flushed(&self) -> u64
Return total points flushed since creation.
Sourcepub fn buffered_count(&self) -> usize
pub fn buffered_count(&self) -> usize
Return the number of points currently buffered.
Sourcepub fn batch_capacity(&self) -> usize
pub fn batch_capacity(&self) -> usize
Return the configured batch capacity.
Sourcepub fn write_point(&mut self, point: MetricPoint) -> TsdbResult<()>
pub fn write_point(&mut self, point: MetricPoint) -> TsdbResult<()>
Enqueue a single metric point.
If the buffer is full, automatically flushes first.
Sourcepub fn write_batch(&mut self, points: &[MetricPoint]) -> TsdbResult<u64>
pub fn write_batch(&mut self, points: &[MetricPoint]) -> TsdbResult<u64>
Enqueue a batch of metric points, flushing automatically when needed.
Returns the WAL sequence number of the last committed record.
Sourcepub fn flush(&mut self) -> TsdbResult<u64>
pub fn flush(&mut self) -> TsdbResult<u64>
Flush all buffered points to the WAL.
Returns the WAL sequence number of the last committed record, or 0 if the buffer was empty.
Sourcepub fn replay_wal(path: &Path) -> TsdbResult<Vec<MetricPoint>>
pub fn replay_wal(path: &Path) -> TsdbResult<Vec<MetricPoint>>
Replay the WAL from disk (e.g. after a crash).
Auto Trait Implementations§
impl Freeze for BatchWriter
impl RefUnwindSafe for BatchWriter
impl Send for BatchWriter
impl Sync for BatchWriter
impl Unpin for BatchWriter
impl UnsafeUnpin for BatchWriter
impl UnwindSafe for BatchWriter
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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