Skip to content

fix(index): withdraw segment coverage when translation history is missing - #9947

Closed
brendanclement wants to merge 11 commits into
lance-format:mainfrom
brendanclement:brendan/withdraw-untranslated-segment-coverage
Closed

brendanclement wants to merge 11 commits into
lance-format:mainfrom
brendanclement:brendan/withdraw-untranslated-segment-coverage

Conversation

@brendanclement

@brendanclement brendanclement commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

A saved index segment can be reattached after cleanup has removed the history needed to translate its old row locations. It can then claim to cover rows it can no longer find, causing queries to miss matching rows.

In this PR we now check that the required translation history still exists before accepting that coverage. Otherwise, scan the affected data directly. If cleanup removes required history during the commit, reject the attempt so it can retry safely.

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.
…sing

A committed segment's coverage moves onto a deferred compaction's output
while its entries keep the rows' addresses from before the compaction, which
readers translate through the compaction's record in the fragment reuse
index. Saved from load_indices_by_name, dropped, and committed again with
commit_existing_index_segments once a cleanup had trimmed that record, the
segment still claimed the output, and queries through it found none of those
rows: the commit only checked fragments the segment's build snapshot held.

Committing segments now keeps coverage of a fragment compaction produced
after a segment was built only while the reuse index records every rewrite
from the build's fragments to it and the indexed data is unchanged along
them, as a merge already requires. Other such coverage is withdrawn and its
rows are scanned; this includes coverage an eager compaction remapped
inline, which the history cannot vouch for. If a cleanup trims a record the
coverage relied on after the commit read it, the commit is retryable, and
committing again leaves the coverage out.
@github-actions github-actions Bot added the bug Something isn't working label Oct 13, 2026
@brendanclement
brendanclement marked this pull request as ready for review October 13, 2026 16:35

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 13, 2026
A saved segment committed again after the fragment reuse index was dropped
kept covering a compaction's output. Its entries still hold the rows'
addresses from before the compaction, and nothing translated them any more,
so lookups through it missed those rows, whether it was committed as it was
or merged first. The withdrawal only ran while a v0 entry existed.

A missing entry now counts as an empty history: coverage of fragments that
compaction produced after a segment was built is withdrawn and their rows
are scanned. Fragments the build held need no history, and tagged histories
keep their replay path. A drop between a commit's read and its write was
already refused as retryable; the refusal now names it.
The missing-history check withdrew coverage of every fragment compaction
produced after a segment's build. A segment of stable row ids on a table that
has them needs no translation there: compaction leaves the ids valid. So an
ordinary BTree that an eager compaction carried onto its output lost that
coverage when committed again, and committing it over itself was refused for
orphaning the output.

Without a fragment reuse index such segments now keep that coverage. Zone maps
and the other indices of physical addresses keep the protection, as does every
index on a table without stable row ids. With a history present every segment
is still checked through it, data changes included.

Without stable row ids, an eager compaction's inline remap is still
indistinguishable from coverage whose record is gone: committing such a
segment over its index is refused, and once the index is dropped it commits
without the output. The docs and a test now state this.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 13, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 13, 2026
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
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.
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
…tion

Local integration only. Brings in lance-format#9947's follow-ups 4a61d90 and 0a10933,
published as lance-format#9947's head 0a10933, by way of the prerequisite base e896ec2.
No conflicts.
A saved segment's coverage was checked against the fragment reuse
history only in the create-index rebase, and only for records lost after
the commit's read version. A raw CreateIndex that already read a trimmed
history, or a detached commit, published coverage of compaction outputs
whose rows no longer translate. A cleaned-up build version made both that
check and the preparation in commit_existing_index_segments skip the
segment.

Every commit attempt, detached or not, now checks the coverage of new
segments against the manifest it replaces. A covered fragment needs the
segment's build version to hold it, the history to translate it there,
or a segment the commit replaces to have covered it. A build version
that has been cleaned up vouches for nothing, and preparation leaves such
a segment's coverage out. Refusals are retryable when the commit read an
earlier version that may still have vouched for the coverage, and invalid
input otherwise.
…erage

A raw CreateIndex could publish saved segment metadata whose coverage no
history translates by removing the current segments of its index: the
check counted the removed segments' coverage, and fragments none of them
covered, as vouched for, though neither says anything of the entries the
saved payload holds. It could also remove or replace the fragment reuse
index in the same commit, while the check translated through the history
the commit replaces.

That coverage now counts only for the segments optimize_indices builds,
which it merges from the segments its commit removes and from fragments
its read version left unindexed; it marks its commit so, and no other
caller can. Every other covered fragment needs the build version or the
history to vouch for it. A CreateIndex that publishes segments built at
an earlier version and also changes the fragment reuse index is refused.
@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 14, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 14, 2026
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 14, 2026
@wjones127
wjones127 self-requested a review October 14, 2026 17:23

@wjones127 wjones127 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.

Unfortunately, the regression for index remapping is too significant for us to merge this. I want to work with you to figure out an alternative design.

Also, I wonder if we should provide a mechanism to allow staged segments to "pin" the required fragment history. Definitely a separate PR, but would be a better fix, I think.

Comment thread rust/lance/src/index.rs

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.

thought: this module desperately needs a refactor.

Comment thread rust/lance/src/index.rs
/// build version has been cleaned up keeps none of its coverage, since nothing
/// then shows which fragments its build held. Tagged histories are replayed
/// instead ([`replay_staged_segments`]).
async fn withdraw_untranslated_coverage(

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.

suggestion: it would be nice to pull these methods out into a index/coverage.rs submodule.

Comment thread rust/lance/src/index.rs
@@ -868,6 +918,329 @@
Ok(())

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.

issue (blocking): Without stable row ids, if we remap during compaction this change makes those indexes drop the coverage. Example:

Take a table without stable row ids:

  1. val_idx is built at V1 over fragments {0,1,2,3}.
  2. An eager compaction turns {0,1} into fragment 4 and rewrites the index files. The segment now covers {2,3,4} and still says dataset_version = V1. The FRI has no record, and none is needed because the entries already point at fragment 4.
  3. Someone takes that segment’s metadata (load_indices_by_name) and commits it again with commit_existing_index_segments.

withdraw_untranslated_coverage then checks whether V1 contained fragment 4. It didn’t. Next it looks for an FRI record that translates V1’s fragments into 4, and there isn’t one. Under the PR’s rules that looks exactly like the bug case, where the history was trimmed, so fragment 4 is withdrawn.

This is a big regression, as it breaks remapping in compaction. We need to figure out some way to keep this working, while fixing this issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for flagging this. The compaction regression is addressed on current head 79f2d974cd50b3ce83892edffde3f245009ed9f9.

Successful eager remaps now advance dataset_version only after overlay-staleness reconciliation, so metadata saved from load_indices_by_name can be republished without being mistaken for missing translation history. Before advancing the watermark, a rewritten segment also withdraws coverage of retained fragments whose live overlays are newer than the segment, preserving the flat-scan fallback and indexed-value freshness.

test_republished_segment_over_an_eager_compaction_without_a_history covers stable-address and address-domain indexes across republish/drop/merge combinations, while test_eager_remap_withdraws_retained_overlay_stale_coverage covers an untouched overlay-bearing fragment alongside an eagerly compacted fragment and compares indexed lookups with scans.

Current-head CI is green and Gatekeeper reports approve with the pre-existing cleanup-race risk. Could you take another look?

Comment thread rust/lance/src/dataset.rs
/// Mark this commit as publishing the segments `optimize_indices` built
/// from the segments it removes and the fragments its read version left
/// unindexed, which vouch for their coverage.
pub(crate) fn with_optimized_index_segments(mut self) -> Self {

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.

question (non-blocking): This flag lets the caller exempt removed and unindexed coverage from the history check, and it travels in write config rather than in the transaction. Why not derive the exemption from the transaction itself, so a future caller can't set it by mistake and skip the check?

Comment thread rust/lance/src/index.rs
separately.",
segment.uuid, segment.name, segment.dataset_version, entry.uuid
)));
}

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.

issue (non-blocking): load_all_indices(base) now runs on every CreateIndex attempt that carries a segment older than base, which covers nearly all segment commits, and the retry loop runs it again on each attempt. Consider a quick benchmark of commit latency, or reusing the indices that the rebase already loaded.

Comment thread rust/lance/src/index.rs
},
};
}
for new in &group.new_frags {

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.

praise: Good catch: without this guard, reaching a group through a different covered source would put back a fragment that had already been ruled undatable. The comment explains why well.

…g-translation-history

# Conflicts:
#	rust/lance/src/dataset/tests/merge_coverage.rs
#	rust/lance/src/index.rs
#	rust/lance/src/index/api.rs
#	rust/lance/src/utils/test.rs
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 28, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 28, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 28, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 28, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 28, 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 with a non-blocking risk.

The missing-history and eager-remap overlay findings are fixed.

A cleanup prepared before segment attachment can still land afterward and remove required translation history, causing missed matches. This pre-existing race is unchanged here; #9821 remains open. Avoid concurrent history cleanup and segment attachment until that fix lands; no change for this race is requested in this PR.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 28, 2026
Xuanwo pushed a commit that referenced this pull request Oct 28, 2026
Record metadata-only suffix relabels with all moved physical row addresses, including deleted rows. Integrate strict trailing-suffix planning with recorded and unrecorded compaction races, and cover the resulting Rust and Python paths. Keep the accepted #9947 follow-up outside this PR scope.
wjones127 pushed a commit that referenced this pull request Oct 28, 2026
Record metadata-only suffix relabels with all moved physical row addresses, including deleted rows. Integrate strict trailing-suffix planning with recorded and unrecorded compaction races, and cover the resulting Rust and Python paths. Keep the accepted #9947 follow-up outside this PR scope.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants