Repository navigation
refactor(lsm): gate SSTable exclusion on every index a query relies on - #3780
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
There was a problem hiding this comment.
The per-shard minimum is the right conservative rule, and the helper tests cover ordering and legacy missing-entry behavior without changing today’s supported zero/one-index paths.
This remains scaffolding: the only reachable multi-index shape, vector search with a scalar or bitmap prefilter, is still gated on the vector index alone, and there is no end-to-end divergent-catch-up test. Before activating strict catch-up semantics or relying on this for completeness, land planner-derived filter-index discovery plus an integration test that independently lags each used index; alternatively, conservatively gate on all maintained indexes until the planner can certify the selected set.
The MemWAL LSM scanner resolved one index and capped SSTable exclusion at that index's catch-up watermark. A query can rely on more than one: a hybrid search reads both a vector and a full-text index, and either may lag the other. Gating on whichever was resolved first dropped SSTables holding rows the other index had not yet indexed, and that arm silently returned fewer rows. exclusion_watermarks now takes every index the query relies on and retains to the lowest of their watermarks, and the resolver collects the vector and full-text arms together rather than returning at the first match. A plain scan still uses the compaction watermark alone. Both remaining behaviours are unchanged: an index with no catch-up entry contributes no cap, and a caught-up index falls back to the compaction watermark. Two parts of the safe-retirement query behaviour are not here because they depend on Lance changes this repository cannot yet see -- lancedb pins lance to the v10.1.0-beta.2 tag: - selecting legacy versus safe semantics from the manifest feature bit, so that on an activated table a *missing* coverage entry means "unknown" and retains SSTables rather than reading as "fully caught up"; - collecting scalar and bitmap-family indexes used as prefilters, which needs the filter's referenced columns and so must handle SQL, Substrait and Datafusion filter forms. Both land once lance carries the feature bit and this crate is bumped.
The justification cited hybrid search, which `reject_unsupported` refuses in the same file, so the multi-index path it described cannot occur. The list never holds more than one entry today. The case that is genuinely multi-index -- a vector search with a scalar or bitmap prefilter -- is not collected, because identifying it needs the planner's chosen indexes rather than the columns the filter names, and no Lance API exposes them. Says so where the collecting happens.
dc586ff to
a47f57b
Compare
hamersaw
left a comment
There was a problem hiding this comment.
Looks great, thanks for the fix!
…#3911) > Stacked on #3780. Blocked only on #3922 (`lance` → `v11.0.0-beta.6`), so CI > stays red until that lands. ## Missing coverage must mean "not known to be covered" #3780 caps the SSTable exclusion watermark at an index's recorded catch-up when there is one, and silently ignores the case where there is none. On a table that requires catch-up, an absent entry means the index is *not* known to hold the compacted rows — and the LSM base arm reads base through the index (`fast_search`, no brute-force tail), so dropping that SSTable loses those rows for that query. ```rust Some(caught_up) => watermark = watermark.min(caught_up), None if catchup_required => watermark = 0, // retain everything None => {} ``` `catchup_required` reads the manifest feature bit directly, and requires both words: a half-set manifest is treated as legacy, which is the conservative side. Without the bit the field is not maintained at all, so absence carries no information and behaviour is unchanged. ## Activation, as a table-level entry point `Table::require_mem_wal_index_catchup()` performs the one-way switch, separate from `set_lsm_write_spec`: a table carrying the bit retains every generation until something records catch-up, so it has to follow the deployment of whatever repairs coverage, not the creation of the table. This is a convenience, not the only path — a writer holding the dataset calls the equivalent on `DatasetMemWalExt`, which is what the WAL pod does. Lance enforces the preconditions either way: the MemWAL index must exist, and the table must not already carry `compacted_sstables` from before this protocol, since those numbers cannot be validated. ## Still correct after the Lance rework lance-format/lance#8481 replaced the transmitted `IndexCatchupAdvance` with a position derived at commit time from the version a transaction read. That changed how a writer earns coverage; it did not change what a reader may conclude from its absence. The rule here, and the field it reads, are unchanged. ## Tests Existing `exclusion_watermarks` unit tests carry the new argument. Coverage against a real dataset follows once #3922 lands and this can build.
exclusion_watermarksresolved a single index and capped SSTable exclusion at that index's catch-up watermark. It now takes every index the query relies on and retains to the lowest of them, and the resolver collects arms together rather than returning at the first match.This is groundwork, not a fix for a reachable bug:
reject_unsupportedrefuses hybrid search, so the vector and full-text arms are mutually exclusive and the list never holds more than one entry today. The generalisation is what the remaining work below plugs into.Unchanged: a plain scan uses the compaction watermark alone, an index with no catch-up entry contributes no cap, and a caught-up index falls back to the compaction watermark. Taking a minimum over more indexes can only lower a watermark, so the failure direction is "read an SSTable unnecessarily", never "miss rows".
Tests
Three in
lsm: the existing lagging-index test updated for the new signature;exclusion_watermark_takes_the_minimum_across_every_index_used(two indexes at 7 and 4 against compaction at 9 — each alone stops at its own watermark, together the lower governs, order-independent); andan_untracked_index_does_not_widen_a_lagging_sibling.cargo test -p lancedb --lib— 45 lsm tests, 484 in the crate.cargo fmt --checkclean.Follow-ups
This crate pins lance to a released tag, so anything needing unreleased Lance symbols waits for a bump.
FLAG_MEM_WAL_INDEX_CATCHUPset, a missing entry must mean "not caught up" and retain the SSTables, instead of leaving the compaction watermark unchanged. Needs the bit from feat(mem-wal): record index catch-up positions and withdraw them on index change lance-format/lance#8263. This must land before any table is activated — otherwise the bit is set while queries still read permissively.fast_search; a source without a compatible index contributes nothing, so retention alone does not guarantee its rows are returned. Needs a flat-search fallback or an explicit error in Lance'sLsmScanner.