fix(mem_wal): advance visibility cursor on WAL durability, not indexing#6754
Merged
Merged
Conversation
Symptom: with empty `index_configs`, every batch after the first was
silently invisible to scans even though `BatchStore` held the data.
Root cause: `WalFlushHandler::flush_from_batch_store` only advanced the
visibility cursor through `IndexStore::insert_batches_parallel`, which
was skipped when `indexes: Option<Arc<IndexStore>>` was `None`.
Additionally, `MemTable.indexes` initialized to `None` meant the scanner
and flush handler each materialized throwaway `IndexStore` instances via
`unwrap_or_else`, so even after wiring up an unconditional advance the
two ends would not share a cursor.
Fix: initialize `MemTable.indexes` to `Some(Arc::new(IndexStore::new()))`
so scanner and flush handler share a stable `Arc`. With that shared Arc,
the existing in-function advance at `insert_batches_parallel` correctly
fires for an empty registry. Rename `max_indexed_batch_position` →
`max_visible_batch_position` to reflect the new semantic ("durable, safe
to read", not "indexed up to here"), and expose the advance as `pub` so
it is callable from the WAL flush path.
Also expose `mem_wal::util` as `pub mod util` so external consumers can
import the four shard-path/bit-reversal helpers instead of duplicating
them.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
index_configs, the WAL flush handler only advanced the visibility cursor throughIndexStore::insert_batches_parallel, which theNonebranch offlush_from_batch_storeskipped. The cursor stayed at 0 for the memtable's lifetime, so scanners returned only batch 0 even though theBatchStoreheld more. Compounding this,MemTable.indexesinitialized toNonemeant the scanner and flush handler each minted throwawayIndexStoreinstances viaunwrap_or_else, so an unconditional advance would still not share state. Fix: initializeMemTable.indexestoSome(Arc::new(IndexStore::new()))so both ends share a stableArc, and the existing in-function advance fires correctly for empty registries.max_indexed_batch_position→max_visible_batch_position. The cursor now means "durable in the WAL, safe to read," not "indexed up to here." The advance method is nowpubfor callers that drive the cursor from outside the index path.pub mod util: changedmod util→pub mod utilso external crates can importshard_base_path,shard_wal_path,parse_bit_reversed_filename,bit_reverse_u64instead of duplicating them. Helpers were alreadypubat the function level.Test plan
test_wal_flush_advances_visibility_with_empty_indexes— opens a flusher, appends 3 batches, flushes with an emptyIndexStore, assertsmax_visible_batch_position == 2.test_wal_flush_advances_visibility_with_btree_index— same shape with a BTree index registered.cargo test -p lance --lib dataset::mem_wal— 234 / 234 pass.cargo check -p lance --tests --benchesclean.cargo clippy -p lance --tests --benches -- -D warningsclean.cargo fmt --checkclean.🤖 Generated with Claude Code