Skip to main content

EventLog

Trait EventLog 

Source
pub trait EventLog: Send + Sync {
    // Required methods
    fn append_with_id(
        &self,
        event_id: EventId,
        event_bytes: &[u8],
    ) -> Result<()>;
    fn append_batch_with_ids(
        &self,
        first_event_id: EventId,
        events: &[Vec<u8>],
    ) -> Result<()>;
    fn next_event_id(&self) -> Result<EventId>;
    fn iter_range(
        &self,
        start: EventId,
        end: Option<EventId>,
    ) -> Result<Box<dyn EventLogIterator>>;
    fn get(&self, event_id: EventId) -> Result<Option<Vec<u8>>>;
    fn delete_range(&self, start: EventId, end: EventId) -> Result<usize>;
    fn rotate(&self) -> Result<PathBuf>;
    fn oldest_event_id(&self) -> Result<EventId>;
    fn newest_event_id(&self) -> Result<EventId>;
    fn sync(&self) -> Result<()>;
    fn stats(&self) -> Result<EventLogStats>;
}
Expand description

Event log storage backend

Provides fast append-only event storage separate from the canonical KV store. This enables:

  • Higher write throughput (no ACID overhead)
  • Event rotation and archival
  • Multiple concurrent writers (with file locking)

Required Methods§

Source

fn append_with_id(&self, event_id: EventId, event_bytes: &[u8]) -> Result<()>

Append an event with a pre-allocated EventId

This should be fast - just append bytes to a file. EventId must be provided by the caller (allocated from canonical store).

Source

fn append_batch_with_ids( &self, first_event_id: EventId, events: &[Vec<u8>], ) -> Result<()>

Append multiple events in a batch with pre-allocated EventIds

The first event will have event_id = first_event_id, subsequent events will have first_event_id + 1, first_event_id + 2, etc.

Source

fn next_event_id(&self) -> Result<EventId>

Get the next EventId that will be assigned

Source

fn iter_range( &self, start: EventId, end: Option<EventId>, ) -> Result<Box<dyn EventLogIterator>>

Iterate over events in a range

Returns events from start (inclusive) to end (exclusive). If end is None, iterates to the latest event.

Source

fn get(&self, event_id: EventId) -> Result<Option<Vec<u8>>>

Get a single event by ID

Source

fn delete_range(&self, start: EventId, end: EventId) -> Result<usize>

Delete events up to (and including) the given EventId

Used after archival to free up space. Returns the number of events deleted.

Source

fn rotate(&self) -> Result<PathBuf>

Rotate the current log file

Closes the current file and starts a new one. Returns the path to the rotated file.

Source

fn oldest_event_id(&self) -> Result<EventId>

Get the oldest event ID still in storage

Source

fn newest_event_id(&self) -> Result<EventId>

Get the newest event ID in storage

Source

fn sync(&self) -> Result<()>

Sync all writes to disk

Source

fn stats(&self) -> Result<EventLogStats>

Get statistics about the event log

Implementors§