Skip to main content

LogBackend

Trait LogBackend 

Source
pub trait LogBackend {
    // Required methods
    fn append(&mut self, bytes: &[u8]) -> Result<(), LogError>;
    fn sync(&mut self) -> Result<(), LogError>;
    fn truncate(&mut self, new_len: u64) -> Result<(), LogError>;
    fn read_all(&mut self) -> Result<Vec<u8>, LogError>;
    fn len(&self) -> u64;
    fn last_checkpoint_end(&mut self) -> Result<u64, LogError>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

The filesystem primitives a Store needs from its underlying log.

The production implementation is CanonicalLog; tests and crash- injection harnesses implement this trait to arm failures on specific operations (see store::tests::FaultyLog).

Required Methods§

Source

fn append(&mut self, bytes: &[u8]) -> Result<(), LogError>

Append bytes at the current end. No fsync is implied.

§Errors

Implementations return LogError on failure. A failed append may leave partial bytes written; callers are responsible for truncating back to their pre-write offset.

Source

fn sync(&mut self) -> Result<(), LogError>

Fsync the log. Spec § 6 — data + metadata.

§Errors

Returns LogError on failure. Per spec § 7’s fsync-fails row, a sync failure is treated by callers as uncommitted.

Source

fn truncate(&mut self, new_len: u64) -> Result<(), LogError>

Truncate the log to new_len bytes (and fsync the truncation).

§Errors
Source

fn read_all(&mut self) -> Result<Vec<u8>, LogError>

Read the entire log into a buffer.

§Errors

Returns LogError on read failure.

Source

fn len(&self) -> u64

Byte length of the log.

Source

fn last_checkpoint_end(&mut self) -> Result<u64, LogError>

Scan forward from offset 0 and return the byte offset after the last Checkpoint record. Returns 0 if no Checkpoint has committed yet.

Decode errors past the last good Checkpoint stop the scan — that matches spec § 10’s orphan-truncation contract.

§Errors

Returns LogError on read failure.

Provided Methods§

Source

fn is_empty(&self) -> bool

true if the log is empty.

Implementors§