Skip to content

feat: record row-address moves for deferred compactions on stable-row-ID tables - #9611

Merged
westonpace merged 12 commits into
lance-format:mainfrom
brendanclement:brendan/fri-srid-recording
Oct 14, 2026
Merged

westonpace merged 12 commits into
lance-format:mainfrom
brendanclement:brendan/fri-srid-recording

Conversation

@brendanclement

@brendanclement brendanclement commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Records row-address mappings during deferred compaction on stable-row-ID tables. Supports tables with no indexes or only compatible address-based indexes, currently ZoneMap and BloomFilter.

Every rewritten group is recorded in the Fragment Reuse Index (FRI), including groups with no index coverage. This lets feature-engineering jobs translate addresses from before compaction to the rows’ new locations. Stable row IDs are preserved.

Requires defer_index_remap and remains debug-only. Depends on #9620.

Next steps

  • Keep recording on subsequent compactions once enabled.
  • Retain mappings for running jobs, even when indexes no longer need them.
  • Complete the remaining concurrency protections and enable release support.

@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI enhancement New feature or request labels Sep 29, 2026
@brendanclement
brendanclement force-pushed the brendan/fri-srid-recording branch 2 times, most recently from d520326 to b9771c7 Compare September 29, 2026 19:24
@brendanclement
brendanclement marked this pull request as ready for review September 29, 2026 20:10

@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 Sep 29, 2026
@brendanclement
brendanclement marked this pull request as draft September 30, 2026 04:55
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 30, 2026
@brendanclement
brendanclement force-pushed the brendan/fri-srid-recording branch 2 times, most recently from 32b436a to 1d6e7b2 Compare September 30, 2026 14:16
… base_id on Keep

A fragment reuse version's dataset_version is its watermark: an index
built at or before it still holds the row addresses the rewrite moved.
The value was the committing handle's version, so an index built after
that but before the rewrite published counted as caught up, and cleanup
trimmed a mapping it still needed. Queries through that index then lost
rows.

Define the watermark as the version immediately before the rewrite
publishes, which matches the proto's own definition. finish_rewrite
restamps the rewrite's own version with it on every commit attempt of a
v0 entry, so retries restamp too; older versions keep their stamps.
Tagged histories carry no per-version watermark. Detached commits
bypass the stamp, and versions written earlier keep their old values.

Compare against the watermark inclusively everywhere staleness is
decided: is_index_remap_caught_up (cleanup), remap_index, and
fragment_reuse_affects_segment (segment merge and the NGram rebuild
checks). An index built at exactly the watermark is still stale.

RemapResult::Keep reuses the entry's files, so it now keeps the source
base_id; a shallow clone's index otherwise points at files it does not
have.
A deferred compaction's Rewrite and the reuse index cleanup each replace
the v0 fragment reuse entry wholesale. The transaction file does not
carry that entry, so a rebase that reads a concurrent Rewrite back from
its file, as a separate session always does, could not see its
mappings, and the second replacement silently discarded them.

Each replacement now records the entry of the dataset it is committed
through: the entry the compaction extended or the cleanup trimmed. The
commit loop never moves that handle between attempts, so on every
attempt the rebase compares the same base with the latest manifest's
entry:

- unchanged: publish as before, stamped as the previous commit defines;
- a compaction over a trim of its base: publish the current versions
  plus its own, which keeps every mapping the current history has;
- anything else, including creation and removal: RetryableCommitConflict.
  Commit the results again through a dataset at the latest version.

A replacement that is not its base plus one version of its own, such as
one built from an older snapshot than the dataset it is committed
through, is refused as InvalidInput.

This replaces the Rewrite-vs-Rewrite rule that depended on the
transaction cache, and both history merges (the cleanup's appended
versions and the compaction's retain), which could drop or resurrect
versions. A distributed commit through a handle newer than the tasks'
read version no longer loses a mapping recorded in between. Tagged
histories keep their validated assembly and conversion, and eager
compaction is unchanged.

A cleanup racing an ordinary index creation is a different race and is
not addressed here.
@brendanclement
brendanclement force-pushed the brendan/fri-srid-recording branch from 1d6e7b2 to 7a82dba Compare September 30, 2026 14:58
commit_compaction reserves fragment ids in a commit of its own without
moving the handle, then stamped the new v0 reuse version and its entry with
the handle's version. The Rewrite therefore always published one version
past its stamp, so finish_rewrite restamped and rebuilt the entry on every
commit: for an external history a second full details.binpb write, leaving
the first one unreferenced.

Stamp both with the version the reservation committed at, and give the
entry the fragment bitmap a rebuild or a cleanup publishes, every version's
new fragments, so an uncontended commit keeps the entry as built and
publishes the same entry a restamp would. The restamp on each attempt still
handles a commit that lands after the reservation.
Every commit attempt of a deferred compaction loads its own new entry and
the entry it was built from to check the history, and each load of an
external entry read and decoded the whole details file. Both files had just
been read or written by the same process.

Cache the decoded details of an external entry in the session index cache,
keyed by the file's store, resolved path, offset and size (a shallow clone's
entry resolves to the source dataset's file), and populate it when the file
is written, in the stamp order the encoding uses. A miss reads the file as
before, and the history check runs on the loaded details either way.
…-ID tables

Builds on lance-format#9120 (the eligibility check and the
debug-only gate) and depends on the two commits below it:
- fix: exact FRI watermark for retention, remap and segment merge, so
  that an index built before a recorded rewrite publishes keeps the
  mapping it needs once its coverage follows the rewrite;
- fix: refuse a fragment reuse replacement built from a changed history,
  so that two recording compactions from separate sessions cannot
  discard each other's moves.

A deferred compaction (defer_index_remap) on a stable-row-ID table now
records its row-address moves in the fragment reuse index, including on
tables with no indices and for groups no index covers. Release builds
still refuse the option there.

- The planner accepts the option only if every index passes the
  eligibility check, and names each offending index otherwise. It also
  refuses a table whose manifest still requires a tagged fragment reuse
  history, which stable row IDs exclude.
- Recording tasks take the moved rows' old addresses from fragment
  metadata and deletion vectors. They refuse task fragments out of id
  order and a live-row count that disagrees with the rewrite. Row
  lineage is placed for every stable-row-ID task, recording or not.
- The commit records when the option is set or when every task
  recorded, so a commit without options keeps the moves and normalizes
  the source fragments the same way. Mixed tasks,
  or the option with tasks that recorded nothing, are refused before
  any fragment id is reserved, and eligibility is checked again against
  the commit handle.
- When a stable-row-ID rewrite carries a fragment reuse index, address
  indices keep their coverage and readers translate through it. Without
  one they drop the rewritten fragments as before.

Tables without stable row IDs, and stable-row-ID compactions without
the option, behave as before.
@brendanclement
brendanclement force-pushed the brendan/fri-srid-recording branch from 7a82dba to f11062a Compare October 1, 2026 19:12
@brendanclement
brendanclement marked this pull request as ready for review October 1, 2026 19:47

@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 K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. and removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 1, 2026
Merge main after lance-format#9514. Preserve its index coverage and conflict checks alongside metadata-based address recording, index-free mappings, and distributed commit handling. Update the race regression for the earlier conflict and adapt the new resolver test to the FRI base field.
@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 5, 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 5, 2026
@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 7, 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 main-branch integration preserves the merged mapping-preservation fix (#9620). Focused regressions pass, including deferred compaction with stable row IDs and managed blobs.

External consumers still cannot treat the FRI as a complete, durable translation history: cleanup can trim mappings, and compactions without defer_index_remap leave moves unrecorded. This remains debug-only; jobs relying on physical addresses must control those maintenance operations.

@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 7, 2026

@westonpace westonpace left a comment

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.

Just some minor comment nits.

Comment thread python/src/lib.rs Resolved
Comment thread rust/lance/src/dataset/optimize.rs Resolved
Drop the test-only `_frag_reuse_with_stable_row_ids_enabled` binding. The
optimize tests now get the gate from a module fixture that compacts a small
in-memory stable-row-ID table with defer_index_remap: the release refusal
means this build does not record, and a rewrite that writes the fragment
reuse index means it does. Any other outcome fails the tests.

Also state the recording-intent invariant on records_stable_row_id_moves
without referring to Python.
@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 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.
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
… only)

Two textual conflicts. rust/lance-table/src/format/manifest.rs: the
clone flag mask takes main's split STICKY_READER_FLAGS /
STICKY_WRITER_FLAGS with lance-format#9768's FLAG_STABLE_ROW_IDS, the form lance-format#9768
landed in on main. rust/lance/src/dataset/optimize.rs:
records_stable_row_id_moves keeps lance-format#9611's reworded doc comment with this
branch's added sentence.

lance-format#9611 replaced the _frag_reuse_with_stable_row_ids_enabled binding with
the srid_recording_enabled fixture, which finds the gate by compacting.
This branch's three recording tests take the fixture, and the CI job
that runs them with recording on proves it the same way before running
them, since they also pass on the refusal.
brendanclement added a commit to brendanclement/lance that referenced this pull request Oct 13, 2026
…compaction

Main now lets an index built before a deferred compaction commit past it
from any session while the latest reuse index records the compaction,
and lance-format#9611 already expects this. The race test of a cleanup and a late
index on a stable-row-id table no longer expects the index from another
session to retry.
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.
@westonpace
westonpace merged commit 0880bfd into lance-format:main Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-java Java bindings + JNI A-python Python bindings enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants