Skip to main content

Journal

Struct Journal 

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

Journal is a type-erased arena-based batch logger designed for high-performance logging of structured data with minimal allocation overhead.

This logger uses memory arenas to efficiently store logged data in contiguous memory, reducing allocation overhead and improving cache locality. Data is stored in a type-erased manner, allowing different types to be logged to the same arena while maintaining type safety through the Pod + Zeroable trait bounds.

Implementations§

Source§

impl Journal

Source

pub fn init(size: usize) -> Self

Creates a new Journal logger with the specified arena size.

Source

pub fn write<T: Pod + Zeroable + 'static>( &mut self, state: T, time: u64, horizon: Option<u64>, )

Writes a value with an associated timestamp to the logger.

The value is stored in the current arena with proper alignment. If the arena doesn’t have enough space, it will be flushed and a new arena allocated. If the value is too large for any arena, it will be allocated separately.

Source

pub fn write_raw( &mut self, bytes: &[u8], align: usize, time: u64, horizon: Option<u64>, )

Source

pub fn cleanup<T: Pod + Zeroable + 'static>(&mut self) -> Vec<(T, u64)>

Cleans up the logger and returns all logged data by value.

After calling this method, the logger is reset to its initial state with all memory deallocated.

Source

pub fn rollback(&mut self, time: u64)

Rolls back the current state to what was active most recently at the provided time: usize.

Source

pub fn rollback_return<T: Pod + Zeroable + 'static>( &mut self, time: u64, ) -> Vec<(T, u64)>

Rolls back the current state to the most recent entry at or before time. This method removes all log entries with a timestamp greater than time. Instead of dropping the removed entries, it reconstructs and returns them as a Vec<(T, u64)>.

Source

pub fn rollback_return_raw<T, E, F>( &mut self, time: u64, deserializer: F, ) -> Result<Vec<(T, u64)>, Result<E, MesoError>>
where F: FnMut(&[u8]) -> Result<T, E>,

Rolls back and returns the removed entries by deserializing them.

This method will stop and return the first error encountered during deserialization.

Source

pub fn read_state<T: Pod + Zeroable + 'static>(&self) -> Result<&T, MesoError>

Reads the most recently written value from the logger.

Returns a reference to the last value that was written to the logger, cast to the specified type.

Source

pub fn read_state_raw<T, E, F>( &self, deserializer: F, ) -> Result<Option<(T, u64)>, Result<E, MesoError>>
where F: FnOnce(&[u8]) -> Result<T, E>,

Reads and deserializes the most recent state using a provided function.

Returns Ok(None) if the journal is empty. Returns Err(E) if deserialization fails.

Source

pub fn read_state_mut<T: Pod + Zeroable + 'static>( &mut self, ) -> Result<&mut T, MesoError>

Reads the most recently written value from the logger as a mutable reference.

Similar to read_state() but the reference returned is mutable.

Source

pub fn read_tape<T: Pod + Zeroable + 'static>(&self) -> Vec<(&T, u64)>

Reads all flushed entries from the tape as immutable references.

Returns a vector of tuples containing references to the logged data and their associated timestamps. Only includes data that has been flushed to the tape, not data in the current arena.

Source

pub fn read_tape_raw<T, E, F>( &self, deserializer: F, ) -> Result<Vec<(T, u64)>, Result<E, MesoError>>
where F: FnMut(&[u8]) -> Result<T, E>,

Reads and deserializes all flushed entries from the tape using a provided function.

This method will stop and return the first error encountered during deserialization.

Source

pub fn read_tape_mut<T: Pod + Zeroable + 'static>( &mut self, ) -> Vec<(&mut T, u64)>

Reads all flushed entries from the tape as mutable references.

Similar to read_tape(), but returns mutable references that allow modification of the logged data in place.

Source

pub fn read_all<T: Pod + Zeroable + 'static>(&self) -> Vec<(&T, u64)>

Reads all logged entries in timestamped order as immutable references. Assumes all logs are the same Pod type.

Source

pub fn read_all_raw<T, E, F>( &self, deserializer: F, ) -> Result<Vec<(T, u64)>, Result<E, MesoError>>
where F: FnMut(&[u8]) -> Result<T, E>,

Reads and deserializes all logged entries using a provided function.

This method will stop and return the first error encountered during deserialization.

Trait Implementations§

Source§

impl Debug for Journal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Journal

Source§

fn drop(&mut self)

Automatic cleanup when the logger is dropped.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Journal

Source§

impl Sync for Journal

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.

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