Skip to main content

OpLog

Trait OpLog 

Source
pub trait OpLog: Send {
    // Required methods
    fn append(&mut self, entry: OpEntry) -> Result<ContentHash, LogError>;
    fn head(&self) -> Option<ContentHash>;
    fn len(&self) -> u64;
    fn get(&self, seq: u64) -> Option<OpEntry>;
    fn last(&self) -> Option<&OpEntry>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn sync(&mut self) -> Result<(), LogError> { ... }
}
Expand description

The log-backend seam (D16). Conformance suite: tests/it/conformance.rs, run against every implementation.

Implementations must reject appends whose parent is not the current head, and a rejected append must not mutate the log.

Required Methods§

Source

fn append(&mut self, entry: OpEntry) -> Result<ContentHash, LogError>

Appends entry and returns its content hash (the new head).

§Errors

Returns LogError::HeadMismatch when entry.parent is not the current head, or a backend-specific LogError on storage failure.

Source

fn head(&self) -> Option<ContentHash>

Content hash of the newest entry, or None for an empty log.

Source

fn len(&self) -> u64

Number of entries in the log.

Source

fn get(&self, seq: u64) -> Option<OpEntry>

Entry at sequence number seq, or None if out of range.

Source

fn last(&self) -> Option<&OpEntry>

Borrows the newest entry without cloning it.

The sequencer uses this immediately after a successful append so its cached policy state is updated only after storage accepted the entry. Implementations must therefore return the entry whose hash is OpLog::head.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the log has no entries.

Source

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

Makes every prior OpLog::append durable — survives power loss, not merely process death.

Until this returns Ok, an appended entry may exist only in the OS page cache. That matters here beyond losing a tail: the pre-receive hook submits a ref op before git applies the ref, so an unsynced log can leave git holding a ref whose authorising op does not exist. Two sources of truth then disagree, and the next push fails its CAS against a view that never saw the update.

The sequencer calls this once per batch rather than once per append, and only acknowledges submitters afterwards.

§Errors

Backend-specific LogError on storage failure. A failure here must be treated as “the batch is not durable”, never as success.

Default: a no-op, correct for backends that never outlive the process (see MemLog).

Implementors§