Repository navigation
fix(index): commit the live coverage an optimize merge writes on a tagged fragment-reuse history - #11426
Conversation
|
@claude review |
| Some(MergeClaim::Declined) => { | ||
| if unindexed.is_empty() { | ||
| return Ok(None); |
There was a problem hiding this comment.
🟡 (optional) Distributed callers on a steady-state tagged table now get an optimize plan whose tasks do nothing, on every planning cycle. The new Declined early return (Ok(None) when unindexed is empty) is not mirrored by unsplit_index_needs_rewrite (optimize.rs:875). That predicate still plans a task whenever two or more segments are selected. Fix: when nothing is unindexed on a tagged history, have the planner run tagged_merge_claim on the same selection and plan nothing on Declined. Same pattern at 2 sites (append.rs:1007, append.rs:2277).
Why this was flagged
Trigger: a table with a tagged FRI history and no unindexed fragments, where the OptimizeOptions::merge(n) window (n>=2) selects T and U but leaves out S, which shares a destination with T (or any segment of the index is Unverifiable). plan_optimize_indices sends tagged tables to plan_unsplit_index (optimize.rs:782). That calls unsplit_index_needs_rewrite (optimize.rs:875-887), which returns true because select_segments_to_merge(...).len() >= 2. The task then runs merge_scalar_indices, or the Inverted branch. There tagged_merge_claim returns MergeClaim::Declined and the code returns Ok(None) (append.rs:1007-1008 and 2277-2278). On the base branch this selection was merged, and the next plan was empty. After this change the selection stays declined until a wider window is used, so every plan has a task that produces nothing. frag_reuse_reader_tests.rs:4493-4496 shows this is a contract the repo tests for: "A distributed driver gets nothing to run either".
Verification: In append.rs at lines 1005-1010 and the matching Inverted branch, Some(MergeClaim::Declined) returns Ok(None) when unindexed is empty. unsplit_index_needs_rewrite returns Ok(select_segments_to_merge(dataset, segments, options).len() >= 2) (optimize.rs:887) and never calls tagged_merge_claim. This is a regression from the base, where the same merge(2) selection merged.
215af05 to
0394c03
Compare
|
@claude review |
|
@claude review |
0394c03 to
7cdf8da
Compare
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.
78c8558 to
84b9f30
Compare
7cdf8da to
8bb6b52
Compare
|
@claude review |
84b9f30 to
d97a192
Compare
8bb6b52 to
1a8a4e4
Compare
|
@claude review |
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The ZoneMap/BloomFilter cleanup regression is fixed: carried zones retain the provenance needed to translate them. All 73 focused local cases passed, including both affected index types after cleanup and reopening.
| // The stable-row-id fold-in above must never meet a tagged history. | ||
| if live_claim.is_some() && dataset.manifest.uses_stable_row_ids() { | ||
| return Err(Error::internal( | ||
| "merge_scalar_indices: a tagged fragment reuse history on a stable-row-id table" | ||
| .to_string(), | ||
| )); | ||
| } |
There was a problem hiding this comment.
🟡 (optional) Users of stable-row-id tables with a tagged fragment-reuse history get an internal error from every scalar-index optimize_indices. On the base branch these merges succeeded. The guard at append.rs:1025 fires whenever live_claim.is_some() and the manifest uses stable row ids, whether or not the fold-in added any segment. The commit layer explicitly allows a tagged history beside stable row ids. Fix: raise the error only when the fold-in actually pushed a row-id-domain segment, or drop the guard. If kept, use a NotSupported error naming the index and table state rather than Error::internal.
Why this was flagged
rust/lance-table-runtime/src/frag_reuse/stable_row_ids.rs:57-59 accepts an index_version 1 (tagged) history on a stable-row-id table. On such a table, tagged_merge_claim returns Some(..) for every scalar optimize. append.rs:1025 then returns Error::internal("merge_scalar_indices: a tagged fragment reuse history on a stable-row-id table"). It does this even for a plain append-mode delta or a BTree merge where the fold-in at append.rs:988-999 added nothing. On the base branch the same call merged or indexed the new fragments. Now the index can never be optimized and new data stays unindexed. The commit check also requires every index on such a table to store row addresses (frag_reuse_with_stable_row_ids.rs:132-135), so the row-id-domain fold-in this guard protects cannot occur there. The compaction-side refusal at stable_row_ids.rs:90-95 covers only defer_index_remap recording, not transitions committed through the transaction API or by other writers.
Verification: Trigger: a stable-row-id table that carries a tagged (index_version 1) FRI history. tagged_merge_claim returns Some(..) whenever the FRI entry has index_version != 0 (frag_reuse.rs:603-609). The new guard at append.rs:1025 does not check whether the fold-in at append.rs:988-999 pushed any segment, so it fails every scalar optimize on that table. The base had no such guard.
…gged fragment-reuse history On a table with a tagged fragment-reuse history, `optimize_indices` merged scalar and inverted segments into a file holding live row addresses but committed the union of the sources' stored (historical) fragment bitmaps for it. The manifest then disagreed with the file, and a merge could take over only part of a destination that an unselected sibling still helped cover. The merged segment now commits exactly the live fragments its file is written for: the derived coverage of the selected segments plus the newly indexed fragments. A selection is merged only as a whole, and only when - every selected segment is registered in the snapshot's translation plan (one the reader derives nothing for contributes no coverage and is replaced, as before), - no unselected segment of the same index derives coverage of a fragment the selection covers, and - the selection covers none of the fragments being newly indexed. Otherwise the old segments are left untouched and only the unindexed fragments are indexed, as in append mode (or nothing is done when there are none). Tables without a tagged history are unaffected. Segments merged by earlier releases keep their provenance bitmaps and remain readable; this change does not rewrite them. Co-Authored-By: Claude <[email protected]>
|
@claude review |
1a8a4e4 to
4d3181f
Compare
Problem
After compaction moves rows into new fragments, an index can keep its old row addresses and translate them when read. This PR fixes how
optimize_indicesrecords coverage when merging scalar or inverted index segments on tables with a tagged fragment-reuse history.The merge already reads translated entries, so its output file contains current row addresses. But its manifest bitmap—the list of fragments the segment covers—still recorded the historical fragment IDs from the input segments.
That mismatch makes the merged index depend on old compaction history even though its entries have already been translated. Simply replacing the bitmap with current fragment IDs is not enough: several segments may each supply part of the same current fragment, so merging only some of them must not claim the whole fragment.
Example
Suppose segment S indexes fragment 0 and segment T indexes fragment 1. A rewrite redistributes their rows into fragments 10 and 11, so both S and T are needed to serve each destination. New data is then appended as fragment 12.
With this change:
merge(2)selects S and T{10, 11, 12}.T alone contains only part of the rows in fragments 10 and 11. S and T together contain all of them, so their merged segment can safely claim those fragments directly.
Change
Before merging, use the snapshot's query plan to check the selected segments' current coverage:
If these checks fail, or coverage cannot be verified, keep the existing segments and index only the unindexed fragments, as append mode does. If there are no unindexed fragments, do nothing. The check accepts or declines the whole selection; it does not expand or shrink the merge window.
An accepted merge records the selected segments' current coverage plus the newly indexed fragments. This makes its metadata agree with its file and lets cleanup remove old mapping history when no remaining index needs it.
Compatibility and limits
Tests
Regression tests cover accepted and declined merges for BTree and inverted indexes, shared destinations, independently covered destinations, superseded segments, and tables without tagged history. They check manifest bitmaps and compare indexed results with scans after reopening.
Additional checks verify that cleanup removes history after a complete merge but retains it after a declined merge, and that overlay updates remain visible across both paths and cleanup. The overlay cases use manifest fixtures because normal overlay commits on tagged tables are currently blocked.