Commit Graph
1 Commits
Author SHA1 Message Date
Omar SobhandClaude Opus 4.7 9ece4a6e13 Phase 4d: WalQueue caller-facing wrapper
Build with clawstor cache / Cargo build (clawstor-cached) (pull_request) Successful in 10s
Collapses the enqueue + drain + truncate dance around
WriteAheadLog + wal_mutation + wal_replay into one API so
downstream callers (Phase 4e: cmd_pin & friends) don't have
to orchestrate three modules themselves.

Two-call flow:

    let mut q = WalQueue::open(state_dir.join("wal")).await?;
    q.enqueue(&WalMutation::PutTagVersioned { .. }).await?;
    // ...later, on reconnect:
    let report = q.drain(&conn).await?;

drain() advances the watermark to the last successfully-
applied (or Superseded) seq whether or not the drive stopped
on a hard error mid-stream. Nothing is truncated past the
failure point, so the failing record and everything after
it are retried on the next drain.

Introspection surface (`pending_count` / `oldest_pending_seq`
/ `newest_pending_seq` / `snapshot` / `is_empty`) is what a
metrics endpoint or CLI status view wants. `wal()` escape
hatch exposes the backing WAL for advanced callers.

Tests (6, all green — 4 unit + 2 end-to-end over QUIC):
  * empty queue reports empty bounds
  * enqueue updates bounds correctly
  * snapshot decodes in seq order and preserves kind info
  * drain clears the queue and applies to peer (verifies via
    call_get_ref + call_get_tag_versioned)
  * drain over a pre-seeded dominant version returns
    Superseded and still drains the queue
  * enqueue survives reopen — bounds recover through
    WriteAheadLog::open scan

346 lines, well under the 1300 ceiling.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-07-14 01:11:49 -07:00