Skip to content

feat(index): commit stable-partition rewrites on the tagged fragment reuse history - #9139

Merged
LuQQiu merged 1 commit into
mainfrom
lu/fri-commit-path
Sep 26, 2026
Merged

LuQQiu merged 1 commit into
mainfrom
lu/fri-commit-path

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the write/commit path for FRI-backed stable-partition rewrites. Rewritten data and its row-address mapping become visible together, allowing existing indexes to keep serving rows after reclustering without rebuilding those indexes in the same job.

Query-time address translation is provided by #9107. This PR makes the corresponding writes safe; index maintenance and history cleanup follow in #9161.

Why this is needed

An index stores row addresses, not just values. If reclustering moves a row from F1:20 to F3:10, the index still points to F1:20. FRI records how to reach the new address.

The commit path must preserve three things:

  1. New fragments must never become visible without their mapping.
  2. Concurrent rewrite jobs must not overwrite each other's mapping history.
  3. If an indexed value changes, translating its address must not make the stale index entry appear valid.

What this PR implements

1. Publish the rewrite and mapping atomically

The caller writes destination fragments and the row-map file, then submits a Rewrite carrying the complete FRI entry it built from its read snapshot.

Before committing, Lance validates that the mapping records match the rewrite's sources and destinations, including row counts and deletion state. Both the fragment replacement and the FRI entry are published in the same manifest commit.

A job can also fold newly observed source deletions into destination deletion vectors. The commit path validates that accounting; it does not silently accept a mapping computed against stale deletion state.

2. Merge concurrent additions instead of replacing history blindly

Two jobs can start from the same history and rewrite different fragments. Installing either job's complete snapshot unchanged would lose the other job's additions.

On every commit attempt, Lance extracts only the records the caller added relative to its read version, then merges those additions into the latest history. This allows disjoint rewrites to commit and avoids resurrecting history removed by cleanup. Conflicting rewrites are rejected.

Distributed compaction uses the task's original read snapshot even when submitted through a newer dataset handle. Rewrite submissions are add-only: removing history remains cleanup's responsibility.

3. Keep column updates safe without forbidding them

Moving a row preserves its indexed value; rewriting an indexed column does not. For example, an index entry for price = 10 becomes stale if that row's price changes to 20, even when FRI can still find the row.

The commit withdraws affected index coverage, so queries scan those rows until maintenance rebuilds it. For a translating segment, this can withdraw an entire transition's contribution, not just the edited fragment.

Index preparation runs again against the latest state on retries. The final manifest uses the prepared list; MemWAL bookkeeping retains the original list as its comparison baseline.

Compatibility and boundaries

  • Existing Operation::Rewrite and ManifestBuildConfig fields remain unchanged.
  • The first new-format commit preserves legacy history and sets a reader/writer feature flag. Older builds cannot access the upgraded table; tables using the legacy path retain that behavior.
  • Stable-partition submission is Rust-only in this stack. Compaction on upgraded tables requires defer_index_remap = true.
  • Stable-row-ID tables and overlaid rewrite sources are not supported.
  • Custom low-level commit paths must supply decoded external history through prepare_indices when needed for coverage withdrawal.

Validation

Tests cover concurrent rewrites, retry idempotence, cleanup races, distributed compaction, deletion folding, and column updates racing index creation. Coverage-withdrawal queries are compared with index-disabled scans, including nested fields and partial withdrawal.

@github-actions github-actions Bot added the enhancement New feature or request label Sep 11, 2026
@LuQQiu
LuQQiu added this pull request to stack #9137 September 11, 2026 01:18
@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI labels Sep 11, 2026
@LuQQiu
LuQQiu marked this pull request as ready for review September 13, 2026 18:08
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 13, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 13, 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 Sep 13, 2026
@LuQQiu

LuQQiu commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

On the remaining item: that ordering is structural to this stack, not an open question. #9136 is the first PR of the stack and is currently under the format vote; nothing above it merges before it lands on main, and this branch will be synchronized onto the landed spec before acceptance. The tagged contract and the 1024 capability flag implemented here are exactly what #9136's current revision defines, and the spec PR stays frozen while the vote runs so the voted text and this implementation cannot drift.

Confirming the resolved items for the record: ambiguous-commit ownership now compares durable transaction forms only (6e76f58, with unit plus two end-to-end ambiguity tests; the defect predated this PR, since the in-memory field has participated in equality since #3847), folded destination deletion counts are bound to their validated bitmaps (same commit), and system metadata (FRI and MemWAL) bypasses tagged coverage filtering (433d8c4).

@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 13, 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 Sep 13, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 18, 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 Sep 18, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 18, 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 Sep 23, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 23, 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 Sep 23, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Sep 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Sep 23, 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 Sep 24, 2026
Base automatically changed from lu/fri-index-consumers to main September 24, 2026 17:22
lance-gatekeeper[bot]

This comment was marked as outdated.

lance-gatekeeper[bot]

This comment was marked as outdated.

lance-gatekeeper[bot]

This comment was marked as outdated.

lance-gatekeeper[bot]

This comment was marked as outdated.

lance-gatekeeper[bot]

This comment was marked as outdated.

lance-gatekeeper[bot]

This comment was marked as outdated.

…reuse history

The write path of tagged fragment reuse histories (FRI index_version 1). A
fragment rewrite commits its transitions atomically through the entry
`Operation::Rewrite::frag_reuse_index` has always carried: the complete
entry the caller wants installed, built from the snapshot at the
transaction's read version (`frag_reuse_entry_appending`). The commit path
diffs it against the entry at that version, refuses an entry that drops or
changes recorded history (add-only; trim retires records), and at every
attempt merges the additions onto the entry current at commit, revalidates
and CASes, so concurrent disjoint rewrites merge and a distributed
compaction planned at V commits from a later driver handle. The first
tagged commit lifts a v0 entry byte-verbatim and sets the sticky
FLAG_FRAGMENT_REUSE_INDEX fence; version-0 tables keep their behavior
byte-identically.

Each commit attempt prepares before it builds: `Transaction::prepare_indices`
reads the index list current at the attempt, keeps it as the original list,
runs the tagged-table gate and derives a prepared list on which an in-place
column rewrite has withdrawn (along the history) or pruned (by fragment id)
the coverage it invalidates; `Transaction::build_manifest_prepared` applies
the operation and publishes only the final list, comparing MemWAL coverage
against the original one. `ManifestBuildConfig` keeps main's fields; what
the commit path settled about the entry travels as `FragReuseUpdate`. One
withdrawal implementation serves the preparation and the conflict
resolver's CreateIndex rebase; a remainder the reader would load as it is
after retired sources were withdrawn goes with them and is rebuilt. Normal
mutations (deletes, row-rewriting updates, config and schema changes,
overwrite, restore) are admitted on a tagged table; overlaid sources,
stable-row-id tables and unknown mappings are refused. Deletions that land
after a rewrite's scan can be folded into destination deletion vectors with
exact accounting.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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 prepared fragment-reuse update is now explicitly non-exhaustive, and the comments describe its per-attempt assembly accurately. The tagged rewrite, index-coverage, and distributed-compaction paths are otherwise unchanged from the previously verified revision; the affected Rust crates compile on this head. No blocker remains.

@LuQQiu

LuQQiu commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

The linux-build and linux-arm failures here are the four rest::tls tests in lance-namespace-impls (test_incomplete_initial_load_is_retried, test_malformed_ca_certificate_is_dropped_on_its_own, test_rotation_is_picked_up_once_the_interval_elapses::case_1_interval_elapsed, test_unusable_rotated_material_keeps_client), added by #8456; this stack does not touch that crate, and main fails the same four tests in the same two jobs on its own tip: https://github.com/lance-format/lance/actions/runs/36194697954 (2f5d4fb) and https://github.com/lance-format/lance/actions/runs/36170893444 (0aa3d53).

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 K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants