← Back to Pull requests

fix(memiavl): keep read-only Load from modifying the live WAL #132

Closed
unknown closed this pull request without merging on Oct 15, 2026 18:59 UTC
View on GitHub
unknown unknown commented on Oct 07, 2026 15:04 UTC
Author

What

Read-only memiavl.Load and GetLatestVersion now use a new readOnlyWAL that never changes WAL files. Historical queries (loadAtVersion in store/rootmulti) hit this path while the node writes.

Issue

The read-only path ran OpenWAL, which repairs the WAL, without the file lock:

  • tidwall's Open finishes an in-progress TruncateFront. If a reader does it first, the writer's later WAL writes fail (file already closed) and Commit panics.

  • memiavl's tail repair can cut a half-written entry from under the writer (code reading; not reproduced).
  • Solution

  • readOnlyWAL treats a half-written last entry as unwritten and reads .START/.END files the way wal.Open would recover them, retrying if the tail is renamed mid-open.

  • The DB holds the WAL as a walReader, plus a writeAheadLog writer only when writable; the exported CatchupWAL keeps its *wal.Log signature.

  • Writable Load keeps OpenWAL, since it holds the lock. GetLatestVersion no longer repairs the tail or creates a missing WAL dir, and returns the snapshot version when the WAL is empty.

  • Close is safe to call twice; CommittedVersion then returns wal.ErrClosed.

  • Load closes the tree when the WAL fails, fixing a leak of 3 mmap'd files per store per failed historical load. OpenWAL returns ErrCorrupt instead of (nil, nil) and repairs the tail wal.Open loaded, not the last file by name.

  • Limitation: TargetVersion: 0 loads still read the current symlink; loadAtVersion always sets a target.
  • #102 reverted this (5c62232) and gets it back by merging master after this lands, with no revert. #103 carries it and adds Sync() to the writer interface.

    Diff: 212 lines (+159 / -53) across 2 files Reviewer: thomas-nguy Review duration: 11755m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 212 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.321
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #132"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.5% (MEDIUM) · Higher = larger blast radius
    36.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.4% · Safe to merge
    14.4%