Skip to content

fix(commit): let a deferred rewrite exempt a reindex across processes on untagged FRI tables - #9808

Merged
jackye1995 merged 19 commits into
lance-format:mainfrom
xuanyu-z:fix/v0-fri-cross-process-rewrite-conflict
Oct 9, 2026
Merged

jackye1995 merged 19 commits into
lance-format:mainfrom
xuanyu-z:fix/v0-fri-cross-process-rewrite-conflict

Conversation

@xuanyu-z

@xuanyu-z xuanyu-z commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

With defer_index_remap, a compaction does not remap indexes, so an index built concurrently should commit past it. On a table whose fragment reuse index (FRI) is untagged (index_version 0), that only works from the process that ran the compaction. The exemption reads Rewrite.frag_reuse_index, which is never serialized to the transaction file, so a build in any other process fails with preempted by concurrent transaction Rewrite.

Fix. The CreateIndex rebase also loads the latest manifest's untagged FRI. A rewrite counts as deferred if it carries the in-memory update (as before) or if the FRI records all of its groups, matched by source fragment ids, which are never reused.

Letting a build past a compaction means its coverage of the compacted fragments must stay valid. Two changes can invalidate it, and both now withdraw coverage instead of committing stale entries:

  • In-place column update. An update to a compaction's output prunes the fragments that output was compacted from. They come from the FRI, so nothing has to persist between commit attempts. The update's fields include their descendants, so rewriting a packed struct reaches an index on one of its children.
  • Folded overlay. A compaction that folds in an overlay newer than the index, on an indexed field, withdraws that group. The rule is shared with query-time masking (overlay_affects_index). It now also applies to a rewrite from the same process. An index with no fragment bitmap retries instead.

The index's source fragments must also stay unchanged from the build until the compaction reads them. A version cleaned up from the commit window could hide a change to them, or to the compaction's output. So if the index covers a recorded compaction's sources, any missing version refuses the commit with a retryable conflict. Other indexes and tables keep their current behavior.

If the FRI record is trimmed between two commit attempts, the index commits with coverage nothing translates. Those rows are scanned, as an in-process build did before.

Tests are in optimize/tests/concurrent_reindex.rs. Each scenario commits a build from another process (and from the same process where it differs), then compares index lookups against a scan:

  • past one or chained deferred compactions, and a partly covered group;
  • eager compaction and a trimmed record (retry, as before);
  • in-place update, a packed struct's child, and folded overlay;
  • retries after a racing update, overlay fold, cleanup, or trim;
  • cleaned-up versions.

Seeded workloads of appends, deletes, updates, overlays, compactions, added columns and the remap job also run before and during the commit. Each change was checked against the test that should catch it.

@LuQQiu: the untagged path stays separate from the tagged per-group loop, following the existing split.

xuanyu-z and others added 2 commits October 8, 2026 14:01
A CreateIndex checks a concurrent deferred-remap Rewrite through the
rewrite's in-memory `frag_reuse_index`, but that field is never
serialized: a rewrite committed by another process is read back from its
transaction file with `frag_reuse_index: None`. On a v0 table the eager
rule then applies and any overlap retries, so a reindex running in a
different process from compaction (a distributed indexer, for example)
loses to every concurrent compaction even with defer_index_remap set.

Use the latest manifest's v0 entry as the durable evidence instead, the
v0 counterpart of the tagged lineage: a deferred rewrite records every
group's source fragments, and fragment ids are never reused, so a rewrite
whose groups are all still recorded deferred its remap. Reading the
latest entry also closes a hole the in-memory check had: a cleanup can
trim the record while an index is being built (it only waits for
committed indexes), and an index committed after that kept pointing at
the retired fragments with nothing left to translate them. A trimmed
record now retries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two more cross-process cases for the v0 deferred-rewrite evidence: a
reindex that several deferred compactions committed under, and one whose
rewrite group mixes a fragment it covers with one appended after it read
the table (the commit leaves that group's output out of its coverage, so
the rows are scanned rather than lost). Also move the lineage loader's
doc comment back onto it and mention the v0 evidence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

@github-actions github-actions Bot added the bug Something isn't working label Oct 8, 2026
Rename `current_v0_reuse_sources` to `untagged_deferred_groups` (and its
loader and check to match) and rewrite their docs in plain sentences.
The concurrent compaction/reindex tests, old and new, now share one
fixture and small helpers instead of repeating the dataset setup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xuanyu-z xuanyu-z changed the title fix(commit): let a v0 deferred rewrite exempt a reindex across processes fix(commit): let a deferred rewrite exempt a reindex across processes on untagged FRI tables Oct 8, 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 8, 2026
…d data

An index allowed past a deferred rewrite keeps claiming the source
fragments and relies on the reuse index to translate them. Two later
changes made that claim stale without anything noticing: an in-place
column update on the rewrite's output (the update pruned the output id,
which the index does not hold), and a later deferred rewrite folding in an
overlay newer than the index (nothing is left to mask the old values).

Track which source ids each deferred rewrite's output holds, prune those
on an in-place update, and withdraw a group that folded in a newer overlay
on an indexed field. The rows are scanned instead. This also fixes the
same-process path, which already admitted both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 8, 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 8, 2026
Share `overlay_affects_index` with the query-time rule so a folded overlay
on a parent or child of an indexed field counts, judged against each
index's own build version. Cut the PR's comments down.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 8, 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 8, 2026
xuanyu-z added a commit to xuanyu-z/lance that referenced this pull request Oct 8, 2026
Use `overlay_affects_index` and `field_affects_index` so an overlay on a
parent or child of an indexed field counts, as at query time. The
staleness.rs change is identical to the one in lance-format#9808.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 8, 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 8, 2026
…attempt

A retry only saw versions committed since the previous attempt, so a
change racing the first attempt (an in-place update or a folded overlay
on a rewrite it had let through) was checked without that rewrite and
the index committed stale coverage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 8, 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 8, 2026
Letting an index past deferred compactions on an untagged table needs
every version since its read version: a version cleanup removed hides the
compaction, and an update to its output then goes unwithdrawn. Refuse
with a retryable conflict when the window is incomplete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 8, 2026
@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 8, 2026
Replaying an index commit from its read version on every attempt dropped
pruning an earlier attempt had applied for an update whose version was
then cleaned up. Keep the upstream incremental retry and carry where
deferred compactions moved the index's rows from attempt to attempt
instead; require a complete window per attempt only when the index
relies on that history. The workload tests now also run changes during
the first commit attempt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
…index

Rework the untagged path after review:

- Find the fragments a compaction output was rewritten from in the latest
  reuse index on each attempt, instead of carrying a map across commit
  attempts; nothing has to survive a lost race.
- Keep the in-memory reuse update as evidence too, so a same-process build
  after a trim commits as it did before.
- Refuse a version gap only when an index's bitmap covers a recorded
  group's sources; the MemWAL index and tables without a reuse index are
  never refused.
- Prune updated fragments by id rather than building placeholder fragments.
- Move the tests to optimize/tests/concurrent_reindex.rs with one table
  fixture, one commit hook, and one lookup-versus-scan check, restore the
  existing compaction/reindex tests, and widen the seeded workloads to
  overlays, folding compactions and added columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
…-less indexes

- Refuse a commit over cleaned-up versions only when one is at or after the
  commit of a recorded compaction of fragments the index covers; an earlier
  gap touched fragments under their own ids, as without the reuse index.
- Expand an in-place update's fields to their descendants, so rewriting a
  packed struct withdraws an index on one of its children.
- Retry when a folded overlay must be withdrawn from an index with no
  fragment bitmap.
- Share each group's sources between its outputs.
- Tests: an unrelated gap before the compaction, a packed child, coverage
  assertions that catch withdrawing too much, and overlays placed on the
  fragment holding the row the assertions follow rather than on whichever
  fragment the manifest lists first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 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 9, 2026
…ted sources

Letting an index past a deferred compaction relies on its source fragments
staying unchanged from the build until the compaction read them, as well as
on the output after. Restricting the gap check to versions at or after the
compaction let a cleaned-up in-place update before it go unseen, and the
compaction carried the new values onto an output the index then claimed.
Refuse any cleaned-up version in the window again whenever the index covers
a recorded compaction's sources.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

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

Pinned staged-segment builds preserve correct indexed results across deferred compaction and a later in-place update. Missing required history remains a retryable conflict.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 9, 2026
@jackye1995
jackye1995 merged commit 468e561 into lance-format:main Oct 9, 2026
jackye1995 pushed a commit to xuanyu-z/lance that referenced this pull request Oct 9, 2026
Use `overlay_affects_index` and `field_affects_index` so an overlay on a
parent or child of an indexed field counts, as at query time. The
staleness.rs change is identical to the one in lance-format#9808.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 12, 2026
Since lance-format#9808, an index build that rebases past a deferred compaction finds
the compaction recorded in the latest manifest's fragment reuse index, so
it does not retry when it sees the rewrite decoded from storage. On a
stable-row-ID table a zone map now commits on its first attempt and a
bitmap is refused there by the publication check.

Also check that a committed race keeps every row's stable row ID and maps
its old address to the new one, and that a refused one leaves the table
as the first commit published it.
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants