aarondb/durable_log

durable_log — independent deterministic durable-log reference

This pure local reference is deliberately separate from fact storage. It models the port contract used by later durable adapters: ordered offsets, retained tails, verified snapshots, idempotent append, and an atomic projection-checkpoint boundary. It is not a filesystem implementation.

Types

pub type CheckpointFault {
  NoFault
  FailBeforeCommit
}

Constructors

  • NoFault
  • FailBeforeCommit
pub type DurableLog {
  DurableLog(
    source: String,
    next_offset: Int,
    entries: List(Entry),
    snapshots: List(Snapshot),
    checkpoints: List(ProjectionCheckpoint),
  )
}

Constructors

pub type DurableLogError {
  CursorExpired(requested: Int, earliest_available: Int)
  CorruptEntry(offset: Int)
  SnapshotUnavailable(offset: Int)
  CheckpointFaultInjected
}

Constructors

  • CursorExpired(requested: Int, earliest_available: Int)
  • CorruptEntry(offset: Int)
  • SnapshotUnavailable(offset: Int)
  • CheckpointFaultInjected
pub type Entry {
  Entry(
    offset: Int,
    payload: String,
    idempotency_key: String,
    checksum: String,
  )
}

Constructors

  • Entry(
      offset: Int,
      payload: String,
      idempotency_key: String,
      checksum: String,
    )
pub type Offset =
  Int
pub type ProjectionCheckpoint {
  ProjectionCheckpoint(projection: String, offset: Int)
}

Constructors

  • ProjectionCheckpoint(projection: String, offset: Int)
pub type Snapshot {
  Snapshot(offset: Int, state: String, checksum: String)
}

Constructors

  • Snapshot(offset: Int, state: String, checksum: String)
pub type SourceId =
  String

Values

pub fn append(
  log: DurableLog,
  payload: String,
  idempotency_key: String,
) -> #(DurableLog, Entry)

Append is idempotent for a source-local key. Retrying returns its first entry.

pub fn checkpoint(
  log: DurableLog,
  projection: String,
) -> option.Option(ProjectionCheckpoint)
pub fn commit_checkpoint(
  log: DurableLog,
  checkpoint: ProjectionCheckpoint,
  fault: CheckpointFault,
) -> Result(DurableLog, DurableLogError)

This boundary represents one storage transaction: projection state is owned by the adapter, and its successful application advances this checkpoint together.

pub fn corrupt_entry(log: DurableLog, offset: Int) -> DurableLog

Test-only fault-model hook: a decoder must fail rather than skip altered bytes.

pub fn new(source: String) -> DurableLog
pub fn retain_after(
  log: DurableLog,
  offset: Int,
) -> Result(DurableLog, DurableLogError)

Drop entries through an offset only when a verified recovery snapshot covers it.

pub fn scan_after(
  log: DurableLog,
  cursor: Int,
) -> Result(List(Entry), DurableLogError)

Read the retained tail strictly after cursor after validating every entry.

pub fn snapshot(
  log: DurableLog,
  offset: Int,
  state: String,
) -> Result(DurableLog, DurableLogError)

Persist a verified snapshot at an already committed position.

pub fn snapshot_then_tail(
  log: DurableLog,
  through: Int,
) -> Result(#(Snapshot, List(Entry)), DurableLogError)

Bootstrap state from the latest verified snapshot at or before through, then tail it.

Search Document