Skip to content

fix: do not lose index coverage on a partial index commit over a fragment reuse history - #11292

Merged
LuQQiu merged 1 commit into
mainfrom
lu/keep-historical-index-segments-on-commit
Nov 30, 2026
Merged

LuQQiu merged 1 commit into
mainfrom
lu/keep-historical-index-segments-on-commit

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A partial index commit can remove old segments that still serve current data through fragment reuse history (FRI). The commit succeeds, but fragments outside the new build lose their index coverage.

With FRI, a segment's stored fragment bitmap records where its row addresses came from. It does not describe all the current fragments that the segment can serve after rewrites. commit_existing_index_segments currently uses that bitmap's overlap with live fragments to decide which old segments to remove.

Case 1: an unrelated append removes useful historical segments

P, Q, and R are segments of the same logical index:

Existing segments:  P stores {0}, Q stores {1}
Rewrite:            {0, 1} -> {10, 11}
Append and index:   R stores {12}

Before the commit:  P + Q serve {10, 11} through FRI
Old result:         R alone; {10, 11} lose index coverage
New result:         P + Q + R; existing coverage is preserved

P and Q have no stored fragment that is still live, but their index data remains useful. Committing R must not remove them merely because 0 and 1 have been retired.

Case 2: replacing direct coverage also removes translated coverage

Existing segments:  A stores {1, 3}, B stores {2, 4}
Rewrite:            {1, 2} -> {10, 11}
Incoming segment:   C stores {3, 10}

The old commit removes A because C covers A's remaining live fragment, 3. However, fragment 11 still needs both A and B through FRI. Removing A loses coverage that C did not replace.

The new commit rejects this request without publishing a manifest. The caller can instead build over {10} and keep A, or build over {3, 10, 11} so that removing A loses no coverage.

Change

For a partial commit on a table with tagged FRI, evaluate the set of segments the commit would publish, using the same coverage and segment-membership rules as the reader:

  1. Include incoming segments and the old segments that would remain. Historical segments can remain useful on their own or together with incoming segments.
  2. Compare the logical index's current coverage with the coverage of that proposed set.
  3. Reject the commit if any currently covered live fragment would lose coverage. The error identifies the affected segments and fragments so the caller can adjust the build scope.

Segments are retained or removed whole. This does not shrink stored bitmaps over unchanged index files: the old row addresses remain in those files, and hiding their provenance can cause duplicate results after a later rewrite. Requests that would retain a live segment alongside incoming segments sharing its rewritten source addresses are also rejected.

A segment whose coverage cannot be established is not treated as useless. Historical segments are kept conservatively, and a removal requires proof that the incoming segments safely replace it. Every retained segment still has to pass declaration and compatibility checks; an unreadable retained segment can therefore prevent a partial commit.

Full replacements over all live fragments, existing index-type-change rules, definition-only segments, and tables without tagged FRI keep their existing selection behavior. There is no new persisted state, file format, or public API.

Concurrent commits

A decision that depends on derived coverage or reader classification must commit against the snapshot that justified it. If another writer commits first:

  1. Check the losing transaction against every intervening version using the ordinary commit conflict rules.
  2. If those changes are compatible, repeat the entire decision on the checked snapshot, starting from the caller's original segments.
  3. If the same index was dropped or rebuilt, return the ordinary conflict. Retrying must not recreate a concurrently dropped index.

Attempts share the existing default retry budget, with no added waits. Only a positively identified version race triggers another decision; write failures and unknown commit outcomes are returned rather than retried by this loop. On error, the caller's Dataset object is restored to its entry snapshot. Commits that do not need this snapshot constraint continue to use ordinary rebasing.

Compatibility and failure-handling details
  • When coverage is unproven, incoming segments that participate in reader coverage must collectively supply all relevant stored fragments of each removed segment. A narrow exception allows replacement of a segment excluded because its type has no batch remapper by incoming segments with that same exclusion, or by reader coverage members. This does not allow a directly serving segment to be replaced by segments the reader excludes, and it does not apply to an uninterpretable history.
  • A stored fragment that is neither live nor mentioned anywhere in a fully understood history is ignored in this replacement check. This preserves ordinary rebuilds after outright deletion. Retired sources still present in the history remain relevant; if the history is not fully understood, the whole bitmap is retained for the check.
  • When failed reads are the only reason a required coverage proof is unavailable, return the original read error. Structural uncertainty produces an invalid-input error explaining the reasons. A retained format that cannot be opened for compatibility checking produces a not-supported error; the check is not skipped.
  • Partial commits now open the tagged history, and fail if it cannot be read. A full replacement avoids retaining incompatible old segments, subject to the normal validation rules.
  • Segment conversion now precedes column lookup, so when both inputs are invalid, error precedence changes.

Validation

Regression tests cover both examples above, successful replacement once coverage is complete, combinations of old and incoming segments, duplicate-source rejection, deleted fragments, unreadable metadata and vector files, unsupported history, and types without batch remapping. They check unchanged manifests on refusal and indexed results without duplicate rows after successful commits.

Concurrency tests cover compatible appends and rewrites, same-index drop and rebuild conflicts, unrelated index drops, and failed conditional manifest writes. Read-failure tests verify that the identical request succeeds after recovery.

On head 1bbf62bfa (rebased onto main at dda3823cd; the commit-window check now lives in lance-table-runtime, where main moved the commit loop):

  • cargo test -p lance --lib: 11,955 passed, 0 failed, 9 ignored. This includes two new regressions: one commits a segment for only part of a rewrite's destinations and checks that the historical segment stays unchanged for the rest until those are covered too; the other commits a segment for one rewrite's destinations while an unrelated historical segment serves another rewrite's destinations, and checks after reopening that the unrelated segment is unchanged and still answers indexed lookups.
  • cargo test -p lance-table-runtime: all passed.
  • cargo clippy -p lance-table-runtime -p lance --tests -- -D warnings: passed, with -A unreachable_code added for the pre-existing aarch64-only warnings in lance-encoding.

Coverage limits: incoming segments with uninterpretable details and retired provenance, exhaustion of the full re-decision budget, and retained vector formats this build cannot open are covered at the decision/classification level, not by end-to-end tests.

@LuQQiu

LuQQiu commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions github-actions Bot added the bug Something isn't working label Nov 20, 2026
Comment thread rust/lance/src/index/lifecycle.rs Resolved
Comment thread rust/lance/src/index/lifecycle.rs Resolved
@LuQQiu LuQQiu changed the title fix: keep index segments that still serve translated coverage on a partial index commit fix: do not lose index coverage on a partial index commit over a fragment reuse history Nov 20, 2026
@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch from 424ca3b to 3576630 Compare November 20, 2026 07:47
@LuQQiu

LuQQiu commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Findings marked 🟡 are optional suggestions and need no follow-up push.

Still open from earlier reviews (1):

  • 🔴 rust/lance/src/index/lifecycle.rs — Partial vector-index commits now fail when a historical segment is Unsupported, Unverifiable or Corrupt; the base branc…

If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.

Comment thread rust/lance/src/index/lifecycle.rs Resolved
Comment thread rust/lance/src/index/lifecycle.rs Resolved
Comment thread rust/lance/src/index/lifecycle.rs Resolved
Comment thread rust/lance/src/index/frag_reuse.rs Resolved
Comment thread rust/lance/src/index/frag_reuse.rs Resolved
@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch from 3576630 to f2cfaaa Compare November 20, 2026 09:12
@LuQQiu

LuQQiu commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Findings marked 🟡 are optional suggestions and need no follow-up push.

Still open from earlier reviews (5):

  • 🔴 rust/lance/src/index/lifecycle.rs — Partial vector-index commits now fail when a historical segment is Unsupported, Unverifiable or Corrupt; the base branc…
  • 🔴 rust/lance/src/index/lifecycle.rs:1482 — On tables with steady ingestion, a coverage-dependent partial index commit can fail repeatedly, even when the concurren…
  • Also unresolved: 2 minor or pre-existing, 1 blocking on lines changed since (possibly already fixed).

If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.

@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch 2 times, most recently from fb33834 to a8f0cf3 Compare November 20, 2026 10:54
@LuQQiu

LuQQiu commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Still open from earlier reviews (2):

  • 🔴 rust/lance/src/index/lifecycle.rs — Partial vector-index commits now fail when a historical segment is Unsupported, Unverifiable or Corrupt; the base branc…
  • Also unresolved: 1 blocking on lines changed since (possibly already fixed).

If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.

Comment thread rust/lance/src/index/lifecycle.rs Resolved
@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch from a8f0cf3 to deb5e3a Compare November 20, 2026 11:36
@LuQQiu

LuQQiu commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

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

Code review found no issues

No high-confidence issues detected in this change.

@LuQQiu
LuQQiu marked this pull request as ready for review November 20, 2026 20:03

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

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 20, 2026
@LuQQiu

LuQQiu commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch from deb5e3a to 8f00999 Compare November 20, 2026 22:58
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 20, 2026

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

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 20, 2026
Xuanwo pushed a commit that referenced this pull request Nov 23, 2026
…e settled downstream (#11290)

## What this fixes

After fragments are rewritten, existing index segments may still point
to the old fragment IDs. Fragment reuse history (FRI) translates those
old row addresses to the current fragments, allowing the index to keep
working without rebuilding it immediately.

Once an index directly covers the current fragments, those translation
records may no longer be needed. Today, cleanup can retain them forever
if the data was rewritten more than once.

For example, all three segments below belong to the **same logical
index**:

```text
Index segments:    A stores {1, 3}; B stores {2, 4}
Rewrite history:   {1, 2} → {10} → {30}
New index segment: C stores {30}
Current fragments: {3, 4, 30}
```

A can serve 3, B can serve 4, and C can serve 30 directly. Queries no
longer need either translation. However, the old cleanup waits for
direct index coverage of fragment 10, even though 10 no longer exists,
and keeps both records.

With this change, cleanup removes both translation records. **The index
segments A, B and C are kept.**

## How the new check works

Start with the fragments that exist **now**, separately for each logical
index:

1. If an index segment directly covers a current fragment, no
translation is needed to reach it.
2. Otherwise, follow its rewrite history backwards to find old fragments
stored in the index's segments. Keep the translation records needed
along those paths.
3. Also keep downstream records required by any retained record, so
removing history cannot break a translation chain.

Coverage from one logical index cannot stand in for another's. A segment
this build cannot read does not count as direct coverage, but its stored
fragment IDs still prevent required history from being discarded.
Partially indexed rewrite inputs are retained so that a later segment
can complete their coverage. Existing rules for legacy history remain in
place, and cleanup refuses to trim history containing transitions this
build does not understand.

A related change: if a destination fragment was deleted entirely, with
no remaining live descendant needing translation, it no longer keeps its
history alive. If another destination still needs that translation, the
record stays.

## When this runs and what it costs

**This is a cleanup operation, not an extra check on every index-segment
commit.** In the current Sophon integration, GC cleanup and the remap
job's cleanup phase call `cleanup_frag_reuse_index`. Ordinary writes and
ordinary index-segment commits do not automatically run this
calculation.

Lance also exposes an explicit `TrimFragReuse` transaction action; a
caller must choose to include it. It is not automatically added to
ordinary transactions.

The walk remembers each record's result for the duration of this
calculation, so a shared transition is evaluated at most once per
logical index. This removes the previous repeated scanning of wide
transitions. Building and traversing the history still costs work, and a
cleanup rebased over a concurrent commit may need to calculate again.
This PR does not promise a fixed maintenance latency.

## Compatibility

**Rust API change:**
`lance_table::system_index::frag_reuse::retention::compute_tagged_retention`
now requires `live_fragments`. Callers must pass the current fragment
bitmap from the **same manifest** as `indices`.

## Validation

Tests cover multi-step rewrites, independent logical indices, partial
coverage, unreadable segment types, legacy history, deep and wide
histories, and concurrent commits. Resolution-count tests verify that
shared transitions are evaluated once per logical index; 400 generated
histories are compared with a separate reference calculation, which
shares the existing legacy predicate.

Dataset tests perform real rewrites and deletes, run cleanup twice,
reopen the dataset in a fresh session, and compare indexed queries with
scans. They verify both sides: obsolete history is removed, while
history needed by a surviving fragment remains.

Executed on head `2db639ed0`:

- `lance-table` library tests: **1,676 passed**.
- Focused Lance tests (`tagged_trim`, `retention`, `frag_reuse`,
`deleted_destination`): **722 passed, 2 ignored**.
- Formatting and package-scoped clippy: **passed**.

These results validate the Lance change. The combined Sophon run with
the final #11292 revision is separate and is not claimed here.

Co-authored-by: Claude <[email protected]>
@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch from 8f00999 to ec96a5f Compare November 24, 2026 09:34
@LuQQiu
LuQQiu changed the base branch from main to lu/optimize-merge-live-coverage November 24, 2026 09:34
@LuQQiu

LuQQiu commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 2026

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

Code review found no issues

No high-confidence issues detected in this change.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 2026
@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch from ec96a5f to 2392764 Compare November 24, 2026 10:08
@LuQQiu

LuQQiu commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 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.

The partial-commit check preserves historical coverage and stored provenance, including partially replaced destination sets and unrelated historical segments. Segments over fragments deleted outright are removed, and concurrent drops or rebuilds of the same index remain conflicts. No blocking issues found.

For landing on main, preserve the stack order: #11399 → #11426 → this PR.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 2026

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

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

…ment reuse history

Committing segments for part of an index decided which same-name
segments to remove from their stored fragments alone. On a table with a
tagged fragment reuse history a stored bitmap is provenance: after
rewrites retire the fragments it names, the reader still translates the
segment to the live fragments those rewrites produced. Two things went
wrong. A segment with no live stored fragment was always removed, so a
commit over unrelated fragments dropped coverage it did not replace.
And a segment that was partly live could be replaced by a commit over
its live fragment while another live fragment still depended on its
retired one, which silently lost that fragment's coverage.

A partial commit on a tagged history is now decided against the
composition it would publish, using the reader's own membership rule.
Segments are kept or removed whole; a stored bitmap is never narrowed.
A segment with no live stored fragment stays while the published
composition still derives coverage for it. A commit that would leave a
live fragment without the index coverage it has now is refused, and
nothing is committed. When a segment's coverage cannot be established,
nothing is removed on the strength of it: such segments stay, and a
removal the incoming segments do not wholly supply again is refused, or
fails with the read error when failed reads are all that prevented the
check. Incoming segments
supply a removed segment again when they take part in coverage and
store all of its fragments; a segment of an index type without a batch
remapper, which the reader already leaves out, can also be replaced by
segments of that type storing all of its fragments. A live segment
sharing an already rewritten source fragment with the incoming segments
is refused instead of serving those rows twice.

Fragments a removed segment stores that are neither live nor named by
the history (deleted outright) are ignored when judging whether it is
supplied again, unless the history cannot be fully interpreted.

A decision that rests on derived coverage must land on the version it
was made on. If another commit lands first, the whole decision is made
again on the latest version from the caller's original segments, up to
the commit retry budget and without waiting between attempts. Before
deciding again, the losing transaction is checked against the
intervening versions by the ordinary conflict rules, so a concurrent
drop or rebuild of the same index stays a conflict; a failed manifest
write or an unknown outcome is returned as is. On error the
dataset is left at the version it was called with. A retained segment
that cannot be opened for the compatibility check refuses the commit
with the original error's classification. Commits that cover
every live fragment, index type changes, definition-only segments and
tables without a tagged history behave as before.

Co-Authored-By: Claude <[email protected]>
@LuQQiu
LuQQiu force-pushed the lu/keep-historical-index-segments-on-commit branch from 2392764 to 1bbf62b Compare November 30, 2026 22:42
@LuQQiu
LuQQiu changed the base branch from lu/optimize-merge-live-coverage to main November 30, 2026 22:42
@LuQQiu

LuQQiu commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 30, 2026

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

Code review found no issues

No high-confidence issues detected in this change.

@LuQQiu
LuQQiu merged commit 12458e8 into main Nov 30, 2026
58 of 65 checks passed
@LuQQiu
LuQQiu deleted the lu/keep-historical-index-segments-on-commit branch November 30, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants