Skip to main content

FeatherWriter

Struct FeatherWriter 

Source
pub struct FeatherWriter { /* private fields */ }
Expand description

Manages multiple FeatherBuffers and handles encoding, rotation, and flushing to the object store.

The write() method is the single entry point for clients: they supply a data value (of generic type T) and the manager encodes it (using T’s metadata via EncodeToRecordBatch), routes it by CatalogPathPrefix, and writes it to the appropriate FileWriter. When a writer’s buffer is full or rotation criteria are met, its contents are flushed to the object store and it is replaced.

Implementations§

Source§

impl FeatherWriter

Source

pub fn new( base_path: String, store: Arc<dyn ObjectStore>, clock: Rc<RefCell<dyn Clock>>, rotation_config: RotationConfig, included_types: Option<HashSet<String>>, per_instrument_types: Option<HashSet<String>>, flush_interval_ms: Option<u64>, ) -> Self

Creates a new FeatherWriter instance.

Source

pub async fn write<T>(&mut self, data: T) -> Result<(), Box<dyn Error>>
where T: EncodeToRecordBatch + CatalogPathPrefix + 'static,

Writes a single data value. This is the user entry point. The data is encoded into a RecordBatch and written to the appropriate FileWriter. If the writer’s buffer reaches capacity or meets rotation criteria (based on the rotation configuration), the FileWriter is flushed to the object store and replaced.

Source

pub async fn write_batch<T>( &mut self, data: Vec<T>, ) -> Result<(), Box<dyn Error>>
where T: EncodeToRecordBatch + CatalogPathPrefix + 'static,

Writes a batch of data values as one or more RecordBatches.

Uses T::chunk_metadata to derive the file schema metadata. This protects types like OrderBookDelta from having their file metadata poisoned by a leading sentinel row (e.g. BookAction::Clear, which carries price_precision=0, size_precision=0).

Per-instrument types are partitioned by instrument so a mixed-instrument batch lands in the correct file for each instrument.

Source

pub async fn flush(&mut self) -> Result<(), Box<dyn Error>>

Flushes all active FeatherBuffers by writing any remaining buffered bytes to the object store.

This is called automatically based on flush_interval_ms if configured, but can also be called manually by the client.

Note: In Rust, we use in-memory buffers. Flushing writes the current buffer to the object store and creates a new buffer for continued writing. This is different from Python which just flushes OS buffers.

Source

pub async fn close(&mut self) -> Result<(), Box<dyn Error>>

Closes all writers by flushing and removing them.

After calling this, no further writes should be performed.

Source

pub fn is_closed(&self) -> bool

Returns whether the writer has been closed (all writers cleared).

Source

pub fn get_current_file_info(&self) -> HashMap<String, (u64, String)>

Returns information about the current files being written.

Each entry maps a writer key (type_str and optional instrument_id) to its current buffer size and file path.

Source

pub fn get_next_rotation_time( &self, type_str: &str, instrument_id: Option<&str>, ) -> Option<UnixNanos>

Returns the next rotation time for a specific writer key, if set.

Source

pub fn is_duplicate_event_id(&mut self, event_id: &UUID4) -> bool

Returns whether the given event ID has already been seen, adding it to the cache if new.

Source

pub async fn write_data(&mut self, data: Data) -> Result<(), Box<dyn Error>>

Writes a Data enum value to the appropriate writer.

This is a convenience method that routes the Data enum to the appropriate typed write method.

Source

pub async fn write_instrument( &mut self, instrument: InstrumentAny, ) -> Result<(), Box<dyn Error>>

Writes an instrument to the appropriate writer.

Instruments are written to feather files and organized by instrument ID. This method supports writing instruments that implement EncodeToRecordBatch and CatalogPathPrefix.

Source

pub fn subscribe_to_message_bus( writer: Rc<RefCell<Self>>, ) -> Result<ShareableMessageHandler, Box<dyn Error>>

Subscribes to all messages on the message bus (pattern “*”).

This will automatically write all supported data types that are published on the message bus to the feather files.

The writer must be wrapped in Rc<RefCell<>> to be shareable with the message bus handler.

Note: The handler spawns async tasks to write data, so writes happen asynchronously and won’t block the message bus.

Source

pub fn unsubscribe_from_message_bus(handler: &ShareableMessageHandler)

Unsubscribes from the message bus.

Auto Trait Implementations§

Blanket Implementations§

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more