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
impl Journal
Sourcepub fn write<T: Pod + Zeroable + 'static>(
&mut self,
state: T,
time: u64,
horizon: Option<u64>,
)
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.
pub fn write_raw( &mut self, bytes: &[u8], align: usize, time: u64, horizon: Option<u64>, )
Sourcepub fn cleanup<T: Pod + Zeroable + 'static>(&mut self) -> Vec<(T, u64)>
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.
Sourcepub fn rollback(&mut self, time: u64)
pub fn rollback(&mut self, time: u64)
Rolls back the current state to what was active most recently at the provided time: usize.
Sourcepub fn rollback_return<T: Pod + Zeroable + 'static>(
&mut self,
time: u64,
) -> Vec<(T, u64)>
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)>.
Sourcepub fn rollback_return_raw<T, E, F>(
&mut self,
time: u64,
deserializer: F,
) -> Result<Vec<(T, u64)>, Result<E, MesoError>>
pub fn rollback_return_raw<T, E, F>( &mut self, time: u64, deserializer: F, ) -> Result<Vec<(T, u64)>, Result<E, MesoError>>
Rolls back and returns the removed entries by deserializing them.
This method will stop and return the first error encountered during deserialization.
Sourcepub fn read_state<T: Pod + Zeroable + 'static>(&self) -> Result<&T, MesoError>
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.
Sourcepub fn read_state_raw<T, E, F>(
&self,
deserializer: F,
) -> Result<Option<(T, u64)>, Result<E, MesoError>>
pub fn read_state_raw<T, E, F>( &self, deserializer: F, ) -> Result<Option<(T, u64)>, Result<E, MesoError>>
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.
Sourcepub fn read_state_mut<T: Pod + Zeroable + 'static>(
&mut self,
) -> Result<&mut T, MesoError>
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.
Sourcepub fn read_tape<T: Pod + Zeroable + 'static>(&self) -> Vec<(&T, u64)>
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.
Sourcepub fn read_tape_raw<T, E, F>(
&self,
deserializer: F,
) -> Result<Vec<(T, u64)>, Result<E, MesoError>>
pub fn read_tape_raw<T, E, F>( &self, deserializer: F, ) -> Result<Vec<(T, u64)>, Result<E, MesoError>>
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.
Sourcepub fn read_tape_mut<T: Pod + Zeroable + 'static>(
&mut self,
) -> Vec<(&mut T, u64)>
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.