Repository navigation
fix(index): trace segment coverage across recorded compactions - #9946
Conversation
merge_existing_index_segments keeps a segment's coverage of a fragment that compaction produced after the segment was built only if it can trace the fragment back to the segment's build snapshot through the fragment reuse index. It looked back one group, so a fragment made by compacting an earlier compaction's output had a source the snapshot never held: the fragment was taken as changed and left out of the merged coverage, and committing the merge over the segment it replaces was then refused for orphaning it. Each source is now followed back through every group recorded since the build, down to fragments the snapshot holds: - A group that rewrites fragments into several outputs gives them the same sources, so repeated compactions reach a fragment along exponentially many paths while the history grows linearly. Each fragment is followed once, and each source is returned once. - A source that neither the snapshot holds nor a recorded group produced is a missing link: the fragment is left out, whatever other branches trace back. - Following another covered fragment's sources forward through the group that produced such a fragment no longer marks it fresh again. Those sources vouch for none of the group's other inputs, whose rows the segment cannot translate. The freshness checks along the chain are unchanged, so indexed data that changed along it still leaves the fragment out.
…dbc9b11 (prerequisite, local integration only)
Local integration only. Brings in main 7e8d796, lance-format#9946 dbc9b11 through lance-format#9947 c2af5d7, and lance-format#9611 fbec90f, already merged here, by way of the prerequisite base 379e44a. No conflicts.
westonpace
left a comment
There was a problem hiding this comment.
Two coverage questions are inline. Neither is reproduced yet; both are cases where the merged index might claim rows it has no entries for.
Generated by Claude Code
| // out, though another covered fragment's sources lead to the | ||
| // group that produced it: those vouch for none of the group's | ||
| // other inputs. | ||
| if following.get(&new) != Some(&None) { |
There was a problem hiding this comment.
This guard only protects outputs that are already covered and recorded as None. It doesn't mark the group itself stale. A few lines up, an input that isn't in following is skipped by let (Some(recorded), Some(before_commit)) = (following.remove(&old), ...) else { continue; }. So a group with one traceable input and one untraceable input can still give a fresh committed value to any of its outputs that isn't already marked None.
In test_merge_covers_shared_sources_only_through_kept_links, this works because 8 and 9 are both covered and both None. But it depends on every output behind an untraced input being covered itself. If an output isn't covered (for example, coverage was lost on one output but kept on its sibling), it would be marked fresh on the strength of 6 alone, while half its rows come from 5.
Could we make the group stale whenever one of its inputs is neither followed nor produced after the build, instead of protecting outputs one at a time? That would also drop the reliance on Some(&None) as a marker, since None in following currently means both "can't be dated" and "output of an untraceable chain".
Generated by Claude Code
| &frag_reuse_index.details.versions, | ||
| version, | ||
| fragment, | ||
| |id| built_at.fragment(id).is_some(), |
There was a problem hiding this comment.
The trace stops at any fragment that exists in the build snapshot, not at fragments this segment actually indexed. For a partial or distributed segment, that means a source the segment never covered can come back as Some(version).
Example: a segment built at v covers only fragment 0, while fragment 1 also exists at v. Then (0,1) -> 4 and (4,x) -> 6 run. Tracing 6 returns {0, 1}, and fragment 1 is recorded at v. Fragment 1's data hasn't changed, so indexed_data_differs passes, and 6 ends up covered even though the segment has no entries for fragment 1's rows. Index-only lookups would then miss those rows.
The single-hop code already had this problem, but following the chain spreads it across every link. Would checking membership in the segment's own fragment_bitmap at build time (or the bitmap as of v) be the right stopping condition here, in addition to the snapshot check?
Generated by Claude Code
westonpace
left a comment
There was a problem hiding this comment.
I added some comments from Claude but the ID of walking the graph of FRIs makes sense to me.
I don't think either of the review comments are mandatory so only address them if they make sense and let me know when you're ready to merge.
Segments merged after compactions that each rewrite several fragments can index only some inputs of a recorded group: a subset of per-fragment segments, a segment staged over part of a chain's sources, or a saved segment whose coverage lost one output of a group while a sibling is dated by a chain a cleanup broke. In each case the merge claims none of the group's outputs, and lookups match a scan. Tracing finds every such group, and checking freshness can pass its outputs, but neither adds coverage. The history moves coverage across a group only when the segments cover every input, and these tests pin that rule: without it the merges claim outputs holding rows the segments never indexed, and lookups miss them.
I investigated both of these and added some regression tests. |
After rows have moved through multiple compactions, merging existing index segments can incorrectly lose track of which rows they cover. This can cause the merged index to be rejected, even when the history needed to locate those rows still exists.
In this PR, we now follow the complete recorded chain of moves when checking index coverage. Check each fragment only once, and leave coverage out if a required link is missing.