Skip to content

fix(mem-wal): carry fragments through UpdateMemWalState - #8438

Merged
jackye1995 merged 1 commit into
lance-format:mainfrom
xuanyu-z:fix/memwal-state-preserves-fragments
Aug 11, 2026
Merged

jackye1995 merged 1 commit into
lance-format:mainfrom
xuanyu-z:fix/memwal-state-preserves-fragments

Conversation

@xuanyu-z

@xuanyu-z xuanyu-z commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

What

Operation::UpdateMemWalState builds its manifest from scratch and never populates final_fragments, so the commit publishes a manifest with no fragments. Every row in the table disappears.

Nothing errors. The operation touches indexes rather than data, so it is declared compatible with concurrent Append / CreateIndex and no conflict is raised — the commit succeeds and the data is gone.

Compare UpdateBases, the arm immediately below: also index/metadata-only, and it does carry the fragment list forward.

Fix

final_fragments.extend(maybe_existing_fragments?.clone());

Reachability

No caller in this repo commits a standalone UpdateMemWalState today. MemWAL compaction progress is recorded by MergeInsertBuilder::mark_sstables_as_compacted, which rides an Operation::Update — a data operation that populates fragments normally. So the bug is latent here, not active.

It becomes reachable the moment anything commits the operation on its own, which the MemWAL index catch-up work (#8263) does.

Tests

test_update_mem_wal_state_preserves_fragments: commit UpdateMemWalState on a dataset with rows, assert the fragment list and row count are unchanged. Verified it fails without the fix (left: [], right: [0]).

The existing tests in index/mem_wal.rs already commit this operation against a dataset holding 10 rows — they pass because none of them read the rows afterwards, asserting only on conflict behavior and compacted_sstables.

cargo test -p lance --lib -- mem_wal transaction — 636 passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 10, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

The focused carry-forward restores the metadata-only transaction invariant at the manifest boundary and is preferable to changing Manifest::new_from_previous, where an empty fragment list can be intentional. The regression test covers both fragment and row visibility.

@Xuanwo Xuanwo added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 10, 2026
@xuanyu-z
xuanyu-z force-pushed the fix/memwal-state-preserves-fragments branch from dee21d3 to b61bb56 Compare August 10, 2026 17:43
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 10, 2026
@xuanyu-z
xuanyu-z force-pushed the fix/memwal-state-preserves-fragments branch from b61bb56 to e791287 Compare August 10, 2026 17:48

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

The focused carry-forward restores the metadata-only transaction invariant at the manifest boundary and is preferable to changing Manifest::new_from_previous, where an empty fragment list can be intentional. The regression test covers both fragment and row visibility.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 10, 2026
UpdateMemWalState builds its manifest from scratch and never populated
final_fragments, so the commit published an empty fragment list, dropping
every row in the table. No conflict is raised: the operation touches indexes
and is declared compatible with concurrent data commits.
@xuanyu-z
xuanyu-z force-pushed the fix/memwal-state-preserves-fragments branch from e791287 to 7b44d7f Compare August 11, 2026 04:36
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Aug 11, 2026
@jackye1995
jackye1995 merged commit e954501 into lance-format:main Aug 11, 2026
56 of 57 checks passed
hamersaw added a commit to hamersaw/lance that referenced this pull request Nov 25, 2026
The writer-version cutoff could not tell a genuinely emptied table from a
pre-lance-format#8438 one: every commit restamps the writer version, so a metadata-only
commit carried an untrusted empty fragment list past the check.

Drop the empty-fragments guard instead. Within the RTE path the table is
emptied by the compaction merge_insert itself, so its catch-up always reads an
empty table and must be credited. The pre-lance-format#8438 state requires a standalone
UpdateMemWalState from Lance <= 10.x, which no production table carries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Xuanwo pushed a commit that referenced this pull request Nov 25, 2026
…version proves (#10140)

MemWAL index catch-up coverage is derived at commit time as "the index
spans every fragment of the read version". An empty fragment list was
refused outright, because a manifest written before #8438 (where
`UpdateMemWalState` published no fragments) looks identical, and there
the SSTables are the last copy of the rows.

The cost of that refusal: a table emptied by deletes never credits any
index. `trim_eligible_generation` on the WAL side then never sees
catch-up for the maintained indexes, so the compacted SSTables are never
trimmed, and the catch-up planner reschedules a no-op job every few
seconds, indefinitely. `optimize_indices` returns early because
`mem_wal_catch_up_would_advance` is false. A checkpoint waiting on the
trim never returns. It un-wedges only when a later write adds a
fragment. It reproduces deterministically: empty base, enable MemWAL,
upsert some keys, delete them all, checkpoint. It also hits a table that
started with rows once the compaction deletes the last one.

This is reachable on the normal RTE path, not only through out-of-band
deletes. The compaction `merge_insert` applies the WAL's delete
tombstones and drops fully deleted fragments in the same commit that
advances `compacted_sstables`. The catch-up for that generation
therefore always reads an empty table, even with compaction and catch-up
strictly serialized.

The fix removes the empty-fragments guard, so an empty read version is
trivially covered and credited. The state the guard protected requires a
standalone `UpdateMemWalState` committed by Lance <= 10.x: the first
in-repo caller (#8263) and the fix (#8438) both first shipped in
v11.0.0. No production table was written that way.

An earlier revision trusted empty manifests by writer version instead.
That does not work: every commit restamps `writer_version`, so a
metadata-only commit such as `UpdateConfig` carries an untrusted empty
fragment list past the check.

Tests: `an_emptied_table_is_credited` in `mem_wal_index_coverage`
replaces the writer-version cases; `cargo test -p lance-table --lib
mem_wal_index_coverage` (30 passed); `cargo clippy --all --tests
--benches -- -D warnings` clean. The end-to-end repro (checkpoint
returns, SSTables trim) was verified against the earlier revision, which
credited the same case.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Daniel Rammer <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants