feat(mem-wal): snapshot-consistent as-of cut for fresh-tier membership#7215
Open
hamersaw wants to merge 1 commit into
Open
feat(mem-wal): snapshot-consistent as-of cut for fresh-tier membership#7215hamersaw wants to merge 1 commit into
hamersaw wants to merge 1 commit into
Conversation
Add `AsOfCut { active_generation, active_batch_count }` and
`LsmScanner::contains_pks_as_of` (with `fresh_tier_block_list` threading the
cut) so a caller can evaluate fresh-tier PK membership against the exact tier
a prior scan observed, instead of the live tier.
The active memtable is the only fresh-tier source that grows between two
reads; everything strictly below its generation (frozen memtables, flushed
generations) is immutable. The cut includes lower generations whole, bounds
the active generation to its first `active_batch_count` batches (by append
index), and excludes higher generations and flushed generations
>= active_generation. This uses only the batch count and generation -- both
always available -- and only ever excludes rows the scan did not observe, so
a stale cut under-counts (a tolerable stale read) rather than dropping a row.
Sophon's WAL block-list uses this to pin its two-phase supersession check to
the snapshot the read arm scanned, closing a cross-arm transient missing-row.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
AsOfCut { active_generation, active_batch_count }andLsmScanner::contains_pks_as_of(withfresh_tier_block_listthreading the cut) so a caller can evaluate fresh-tier PK membership against the exact tier a prior scan observed, instead of the live tier.Why
Sophon's WAL block-list runs as two independent RPCs (the read arm and a supersession check) that each snapshot the live fresh tier at their own call time. Under concurrent writes the two snapshots disagree, so a base row can be dropped as "superseded" by the check while the arm never delivered a replacement — a transient missing row. The fix pins both phases to the same cut; this PR is the lance half that lets the check reconstruct the arm's snapshot.
How the cut works
The active memtable is the only fresh-tier source that grows between two reads; everything strictly below its generation (frozen memtables, flushed generations) is immutable. So the as-of filter:
active_generationwhole (immutable, fully observed),active_batch_countbatches (by append index),active_generationand flushed generations>= active_generation(produced after the snapshot).It uses only
batch_store.len()and the memtable generation — both always available on the read path — and only ever excludes rows the scan did not observe, so a stale cut under-counts (a tolerable stale read) rather than over-counts (which would drop a row with no replacement).Tests
fresh_tier_block_listas-of unit tests: active-memtable batch-count bound, newer-gen-excluded / lower-gen-included-whole, flushed-gen at/above active excluded.🤖 Generated with Claude Code