Skip to main content

SegmentWriter

Struct SegmentWriter 

Source
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

Source

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.

Source

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.

Source

pub fn buffered_point_count(&self) -> usize

Returns the number of points accumulated so far.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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