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§
Sourcefn append_with_id(&self, event_id: EventId, event_bytes: &[u8]) -> Result<()>
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).
Sourcefn append_batch_with_ids(
&self,
first_event_id: EventId,
events: &[Vec<u8>],
) -> Result<()>
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.
Sourcefn next_event_id(&self) -> Result<EventId>
fn next_event_id(&self) -> Result<EventId>
Get the next EventId that will be assigned
Sourcefn iter_range(
&self,
start: EventId,
end: Option<EventId>,
) -> Result<Box<dyn EventLogIterator>>
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.
Sourcefn delete_range(&self, start: EventId, end: EventId) -> Result<usize>
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.
Sourcefn rotate(&self) -> Result<PathBuf>
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.
Sourcefn oldest_event_id(&self) -> Result<EventId>
fn oldest_event_id(&self) -> Result<EventId>
Get the oldest event ID still in storage
Sourcefn newest_event_id(&self) -> Result<EventId>
fn newest_event_id(&self) -> Result<EventId>
Get the newest event ID in storage
Sourcefn stats(&self) -> Result<EventLogStats>
fn stats(&self) -> Result<EventLogStats>
Get statistics about the event log