Skip to content

feat(index): maintain tagged fragment reuse histories - #9161

Merged
LuQQiu merged 1 commit into
mainfrom
lu/fri-maintenance
Oct 5, 2026
Merged

LuQQiu merged 1 commit into
mainfrom
lu/fri-maintenance

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes index maintenance work after FRI-backed row movement: merge or rebuild indexes, retire unused mapping history, and reclaim unreferenced files.

Builds on #9139. Stable-partition remapping follows in #9187.

What changes and why

  • FRI-aware merge and rebuild. Maintenance uses translated coverage instead of intersecting old fragment IDs with live fragments. This avoids discarding valid index rows. Coverage withdrawn after column updates can be rebuilt by optimize_indices.
  • Validate distributed index builds. Replay transactions since each staged segment's build version before merging or committing it. Row movement remains translatable; column changes invalidate stale index coverage. Missing history requires rebuilding.
  • Safe history cleanup. Remove fully superseded segments, trim transitions no remaining index needs, and garbage-collect row maps only when retained snapshots no longer reference them. Prune/trim decisions are recomputed on commit retries.
  • Ordered-compaction remapping. Eligible indexes catch up through compaction-only chains; stable-partition chains wait for feat(index): remap indexes through fully covered fragment-reuse transitions #9187.
  • Windows stack safety. Heap-pin large vector-remap futures at this first affected PR, preventing ordinary compaction from overflowing the Python thread's stack.

Limits and validation

Unknown history prevents destructive maintenance. Staged NGram segments crossing stable partition require rebuilding. Replay cost grows with the commits crossed; replacing overlapping committed siblings can reduce coverage elsewhere to scan fallback.

Tests cover merge/rebuild correctness, staged-build races, incomplete history, concurrent cleanup, retained snapshots, and legacy upgrades. Windows and CI-profile Clippy are checked at this PR's own head.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Sep 13, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels 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

Adjudicated both rounds against the code; the pruning concerns were real and are fixed, the trim concerns were already structural.

Pruning validated nothing before removing: fixed in 5db67d4. Removals were derived through the lenient reader path, which only logs on unsupported records, so an old client could prune a segment whose coverage flows through a transition it cannot interpret, and commit that removal before trim's refusal fired. The strict ledger check now sits inside derive_superseded_segments, so every attempt refuses (NotSupported, message consistent with trim, remap, and GC) before any removal-only commit is built.

Pruning race on rebase: confirmed and fixed in 867ae45. The removal-only shape fell through every re-derivation branch in finish_create_index, and a concurrent replacement of a justifying sibling (for example this PR's own remap swap, which publishes narrowed coverage) escaped both has_append_drop_conflict (replacement-style is exempt) and has_replaced_identity_conflict (keys on our removed set, not our justification). A stale removal set could therefore land after concurrent coverage withdrawal. Prune transactions now carry an explicit transaction property; on rebase the resolver re-runs derive_superseded_segments against the rebased manifest and replaces the removal set wholesale, aborting via a no-op marker (treated as success) when nothing remains, mirroring the tagged-trim mechanism. The regression test drives exactly the claimed race (stale prune rebasing over a same-uuid narrowed replacement) and fails without the fix.

Trim from a stale view: already handled. The trim is re-derived against the manifest actually being committed onto during every rebase (finish_create_index): the stale outcome is discarded wholesale, and a rebase that leaves nothing to trim aborts via the TAGGED_TRIM_REBASED_TO_NOOP marker instead of committing an empty version. With 867ae45 the prune-then-trim split is now symmetric: both commits re-derive on every attempt and only consume committed state.

@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 19, 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 19, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 22, 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 23, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label 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 23, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 24, 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
LuQQiu added a commit that referenced this pull request Sep 24, 2026
…9107)

## What this adds

This PR connects scalar and vector index loading to the common version-1
FRI reader. It applies the coverage and translation plan produced for
each index segment while keeping version-0 FRI on its existing
synchronous path.

```text
stored index segment
        │
        ▼
snapshot FRI plan
        ├── Identity     → use the existing plugin load path
        ├── Translate    → load through asynchronous batch remapping
        └── No coverage  → omit the segment and scan
```

An unaffected segment receives no remapper, so existing and external
plugins continue using their normal loader. A segment that requires
translation is retained only when its consumer supports batch row-ID
remapping; otherwise its destination coverage falls back to scanning.

## Index consumers

The shared batch-remapping path is used by:

- B-tree, bitmap, zone map, Bloom filter, RTree, label-list, NGram, and
inverted/FTS scalar indices.
- Vector partition storage, including PQ-backed storage.

Consumers translate physical row IDs in batches, preserve result order
and deletion handling, and avoid building a partition-sized per-row
lookup table. Vector loading preserves its existing partition and
quantization layouts.

Version-0 FRI continues to use the original synchronous remapper and
plugin APIs. A separate version-1 identity state ensures an unaffected
segment never receives a synthetic legacy remapper merely because the
dataset contains version-1 history.

## Query planning and caching

The version-1 plan is built once per dataset snapshot and cached by
manifest identity. It records each segment’s derived coverage and the
fragments owned by newer selected segments. Warm segment opens reuse
this plan instead of recalculating whole-dataset coverage.

Direct destination segments take precedence over older translated
segments. When a logical index needs multiple source segments to cover a
destination, all required contributors are selected; omitting one forces
scan fallback for that destination. Fragment-restricted vector queries
also scan when their selected segments do not provide complete coverage.

Cached objects are keyed by what they depend on. Content decoded without
translation (identity segments, version-0 histories, no history, the IVF
state entry) lives in the plain per-index namespace and stays warm
across commits. Content that embeds translated addresses (pages,
postings, partitions loaded through a translating remapper) lives under
a namespace named by the segment's translation identity: a hash of its
live coverage, its sibling exclusions on its path's destinations, the
fingerprints of the transitions on its path, and whether the ledger
dropped unsupported records. Such an entry goes cold exactly when that
state changes (a transition on the path trimmed or replaced, a fragment
on the path dropped, a sibling taking direct ownership of a path
destination) and survives appends and rewrites of fragments the segment
never covered. The FRI entry's UUID is not part of the key: every
rewrite and trim mints a new one.

Staged segments. A segment built but not yet committed (the distributed
build flow: `execute_uncommitted` per fragment, then merge, then commit)
is unknown to the snapshot plan. `open_row_id_remapping_with_plan` /
`open_scalar_index_with_plan` open one segment through a caller-supplied
plan; the existing entry points are the `None` case. The cache namespace
still follows the resolved remapping. The planner that builds such plans
for a staged group, and the staged merge itself, land in #9161.

Two boundaries. A legacy-layout full-text (inverted) segment, whose
per-document lengths cannot be translated, is excluded from coverage on
a tagged table and its fragments are scanned; a full-text query must
then name its column, since a column-less query discovers columns from
the usable segments. Segment-only selection (`with_index_segments`
without a fragment list) answers from the selected segments only, by
contract, where the pre-FRI path fell back to a flat search; pass the
fragment list to get the coverage guard and the flat fallback.

## Validation

End-to-end tests cover all supported scalar and vector consumers,
multi-segment source coverage, two-source/two-destination rewrites,
deleted rows, partial and filtered queries, direct destination
precedence, reconverging lineage, unsupported plugins and index
versions, scan fallback, cache reuse, prewarm, append/delete/checkout,
and eager/deferred compaction.

A version-0 lifecycle suite covers scans, filtered queries, writes,
compaction, optimization, historical checkout, remapping, and cleanup
while asserting that version-0 datasets never enter the new asynchronous
path.

Validated with workspace Clippy and `cargo fmt --all`. The python and
java lockfiles carry the new `blake3` dependency (CI runs `--locked`);
the staged-group planner that an earlier revision of this PR carried
moved to #9161 with its consumers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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.

lance-gatekeeper[bot]

This comment was marked as outdated.

@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 rebased maintenance patch preserves the reviewed tagged-history behavior. The new heap-pinned IVF remap path reduces compaction caller-stack use without changing index data or coverage; focused compaction/remap and legacy lifecycle cases pass. The synchronized tagged write-path prerequisite still needs to land first, and its corrected ANN-withdrawal regression remains green.

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

@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 tagged write-path prerequisite #9139 has merged into this base, satisfying the prior sequencing condition. The maintenance patch is unchanged from the reviewed revision; focused tagged-merge, staged-index, and remap/trim tests pass on this head.

@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 rebase preserves tagged coverage through the Bitmap segment merger introduced by #9290 and keeps staged vector contract validation separate from query visibility. Focused staged-build, vector-contract, Bitmap-merge, and remap/trim regressions pass on this head; no blocking issue remains.

@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 rebase preserves tagged maintenance alongside the stable-row-ID deferred-compaction contract introduced by #9514. Focused lifecycle, concurrency, and tagged regressions pass, including retaining needed mappings and retiring them after index catch-up. No blocking issue remains.

Maintenance for tagged fragment reuse histories (FRI index_version 1) on
top of the commit path: trimming the entry to what retained versions and
index segments still derive through, pruning superseded segments,
collecting unreferenced row maps, and remapping under the legacy v0 rules
where a segment has caught up.

Merging segments on a tagged table keeps translated coverage: the merge
opens the sources through the translating loader, the merged segment
claims the union of its sources' stored provenance plus the newly indexed
fragments, and retired provenance stays on the lineage when a segment
commits. Staged segments (built uncommitted, merged later) are planned as
one group with the reader's own steps and replayed across every commit
since their build, so a recorded transition keeps the provenance while an
in-place column rewrite withdraws that transition's coverage; a bare
compaction of a covered fragment or a version that can no longer be read
refuses the merge with a rebuild error. Withdrawn coverage is rebuilt by
optimize_indices from the live fragments, and the snapshot plan records why
a segment derives no coverage so maintenance can act on it. After a v0
deferred-remap upgrade, the optimize merge translates the old file into
live addresses but keeps the min source stamp and the provenance union, so
the legacy version stays pinned until a remap advances the stamp.

Windows Python CI crashed with a stack overflow in the eager compact_files
tests once this PR sat on the commit-preparation layer below: at opt-level
0 every arm of the eleven-arm remap_index_file_v3 dispatch materializes its
builder future as a stack temporary. Each arm now moves its builder into a
heap-pinned future and IvfIndexBuilder::remap boxes merge_partitions
(remap_index future 13264 to 2560 bytes, eager compaction minimum stack
872 to 632 KiB on macOS at opt-level 0). Test futures that CI clippy
reports as large are boxed.

Claude-Session: https://claude.ai/code/session_01DgAshYD7wVzPVdjXRuWPPs

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 unchanged maintenance patch integrates with #9620: cleanup and remapping honor the new pre-rewrite watermark, while commit retries preserve the latest required mappings. Focused staged-build, cleanup-race, retry, and v0-to-tagged upgrade regressions pass on this head. No blocking issue remains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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