pub struct SegmentWriter { /* private fields */ }Expand description
Builds a .csx segment file from time-series data points.
Points are accumulated across multiple write_rows
calls and encoded during finalize.
Implementations§
Source§impl SegmentWriter
impl SegmentWriter
Sourcepub fn new(path: impl AsRef<Path>, config: SegmentWriterConfig) -> Result<Self>
pub fn new(path: impl AsRef<Path>, config: SegmentWriterConfig) -> Result<Self>
Create a new segment writer that will write to path.
§Errors
Returns an I/O error if the directory cannot be determined.
Sourcepub fn write_rows(&mut self, points: &[Point]) -> Result<()>
pub fn write_rows(&mut self, points: &[Point]) -> Result<()>
Write a batch of rows to the segment.
Can be called multiple times — all rows are accumulated and encoded
together during finalize.
§Errors
Returns SegmentError::AlreadyFinalized if the segment has been
finalized.
Sourcepub fn buffered_point_count(&self) -> usize
pub fn buffered_point_count(&self) -> usize
Returns the number of points accumulated so far.
Sourcepub fn finalize(&mut self) -> Result<SegmentMeta>
pub fn finalize(&mut self) -> Result<SegmentMeta>
Finalize the segment: sort, encode, and stream to disk with incremental CRC-32c.
§Streaming Write Architecture
Row groups are encoded one at a time and written directly to a
temp file via BufWriter<File>. An incremental CRC-32c checksum
is updated as each chunk is written. Peak memory is bounded by
O(row_group_size) — typically 1-10 MiB — not O(segment_size).
The write path uses temp-file → fsync → rename → dir-fsync
for crash-safe atomic visibility.
§Errors
Returns an error if the segment is empty or already finalized.
Sourcepub fn finalize_batch(
&mut self,
batch: &RecordBatch,
measurement: &str,
tag_columns: &[String],
) -> Result<SegmentMeta>
pub fn finalize_batch( &mut self, batch: &RecordBatch, measurement: &str, tag_columns: &[String], ) -> Result<SegmentMeta>
Finalize from a pre-sorted, pre-deduped RecordBatch.
This is the zero-copy write path used by the compaction executor.
Because the caller has already sorted and deduped the data, this
method skips schema discovery, sorting, and — most importantly —
avoids the batch_to_points round-trip that would allocate a
BTreeMap per row.
Column data is extracted directly from Arrow arrays and passed to the column encoders. Uses streaming I/O with incremental CRC-32c.
§Errors
Returns an error if the batch is empty, the writer was already finalized, or encoding/I/O fails.
Sourcepub fn finalize_batches(
&mut self,
batches: &[RecordBatch],
measurement: &str,
tag_columns: &[String],
) -> Result<SegmentMeta>
pub fn finalize_batches( &mut self, batches: &[RecordBatch], measurement: &str, tag_columns: &[String], ) -> Result<SegmentMeta>
Finalize a segment from pre-chunked RecordBatch slices.
Unlike finalize_batch, this avoids
concat_batches by iterating over the chunks directly. Each chunk
is encoded as one or more row groups and streamed to disk, bounding
peak memory to O(chunk_size × columns).
Auto Trait Implementations§
impl Freeze for SegmentWriter
impl RefUnwindSafe for SegmentWriter
impl Send for SegmentWriter
impl Sync for SegmentWriter
impl Unpin for SegmentWriter
impl UnsafeUnpin for SegmentWriter
impl UnwindSafe for SegmentWriter
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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