Commit Graph
2 Commits
Author SHA1 Message Date
Omar Sobh 8a502be65c Polish: cargo fix pass (auto-remove unused imports)
Build with clawstor cache / Cargo build (clawstor-cached) (pull_request) Failing after 3s
2026-07-14 13:06:49 -07:00
Omar SobhandClaude Opus 4.7 bd0b4972b9 Phase 4d: typed WalMutation frames
Build with clawstor cache / Cargo build (clawstor-cached) (pull_request) Successful in 10s
Adds the encoding layer that turns the raw WAL (opaque bytes)
into a typed queue of client-mode mutations, ready for Phase 4e
to wire actual RPCs through.

Frame (self-describing, forward-compatible):

  version : u8  = 0x01
  kind    : u8  = one of the Kind discriminants
  body    : [u8]  kind-specific

Body encodings mirror the existing on-wire shapes so a future
replay path can splice a WAL record straight into an RPC payload.

Variants (Kinds 0x01–0x06):
  PutRef, PutRefVersioned, PutTag, PutTagVersioned,
  DeleteTag, SetTagExpiry

Blob-put mutations are deliberately NOT modeled — blob data is
too large to keep in the WAL. The roaming-client design stages
blobs on local disk and records a reference to them once the
local BlobPutStream completes.

Public helpers:
  append_mutation(&mut wal, &m) -> Result<seq>
  replay_mutations(&wal, start_seq)
      -> Vec<(seq, Result<WalMutation, WalMutationError>)>

Unknown-kind records surface as `Err(UnknownKind(byte))`, not
a panic — forward-compat when a newer writer wrote a record
this reader doesn't understand. Malformed records also surface
as Err so the caller can decide (log-and-skip vs abort replay).

Tests (9, all green): kind-byte stability, roundtrip every
variant, rejects empty/short/bad-version/unknown-kind,
malformed bodies (wrong length, over-declared key_len, trailing
garbage on DeleteTag), non-UTF-8 keys, append+replay through a
real on-disk WAL, and replay-survives-unknown-kind mid-stream.

No new deps — hand-rolled error type in-tree (no thiserror).
515 lines, well under the 1300 ceiling.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-07-14 00:55:24 -07:00