Skip to content

fix(index): let a remapping scalar merge advance its version stamp - #77

Merged
amunra merged 4 commits into
release-10.0.0from
zeljko/merge-stamp-current-version-r10
Sep 9, 2026
Merged

amunra merged 4 commits into
release-10.0.0from
zeljko/merge-stamp-current-version-r10

Conversation

@zehiko

@zehiko zehiko commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Related

  • Unblocks the Lance 10 bump in the dataplatform (rerun-io/reality#3558), whose fragment-reuse trim test fails against release-10.0.0.
  • The stamp this changes was introduced upstream by feat(index): support segmented ngram index lance-format/lance#7244 (segmented NGram). Upstream main still has it; no upstream issue tracks the trim consequence.
  • Supersedes the first version of this PR, which restored the manifest stamp unconditionally and broke overlay masking (caught in review; see Testing). Second revision after a second review round: per-segment overlay threshold, shared predicate, second-pass test.

What

IndexMetadata.dataset_version is a segment's watermark for two readers: is_index_remap_caught_up trims fragment-reuse versions at or below it, and overlay masking stops re-checking data overlays committed at or below it.

Since lance-format#7244, merge_scalar_indices stamps a merged segment with the oldest source segment's version. That keeps overlay masking correct, because a merge never incorporates overlays, but it also means a merge can never retire a fragment-reuse version: any source that predates the version pins it for the whole dataset, and with deferred index remap the reuse index only drains through a full rebuild.

For index types that translate their entries through the fragment-reuse index while merging (can_remap(): BTree, Bitmap, LabelList, NGram, and JSON when its target does), the merged segment is now stamped with the manifest version it was built from. Per source segment, every carried-over fragment with an overlay on an indexed field committed after that segment was built is removed from the merged coverage; freshly scanned fragments already reflect their overlays and are left alone. Uncovered fragments fall back to a scan and are re-indexed by the next optimize, the same treatment remap_column_index (optimize/remapping.rs) already applies after a remap; the overlay predicate now lives in dataset::overlay::fragment_has_newer_indexed_overlay and is shared by both call sites. Types that do not remap (ZoneMap, BloomFilter, RTree) keep the oldest source's stamp, unchanged from release-10.0.0.

Not covered: merge_existing_index_segments in index.rs keeps its own min-source stamp for non-RTree types (and stamps the manifest version for RTree, the one place that now contradicts the can_remap rule); the vector and inverted merge paths also keep the min stamp. Candidate follow-ups once upstream weighs in. The field match is id-equality, like the other prune sites; the reader gate is ancestry-aware, a pre-existing difference noted for a follow-up.

Provenance: fork-only change, written here; upstreamable as a fix to lance-format#7244. Not a port or backport.

Testing

  • test_ngram_optimize_preserves_overlay_staleness (upstream's overlay test for this merge path) now asserts that the merged stamp equals the manifest version the merge read, that the overlaid fragment left the coverage while the untouched fragment stayed, and that a second optimize_indices restores the coverage with a stamp past the overlay. Its query assertions are unchanged, repeated after the second pass, and pass. With the first version of this PR its contains(text, 'mango') assertion returned [6] instead of [1, 6].
  • New test_segment_merge_is_stamped_with_the_version_it_was_built_from: merges appended rows into a BTree segment that predates a deferred-remap compaction, asserts the stamp equals the manifest version the merge read, asserts the trim then drains the reuse index, and on a fresh open checks the plan answers from ScalarIndexQuery with no fragment falling back to a scan and the count matches an oracle computed with the index disabled. Fails on release-10.0.0 at the stamp assertion (left: 1, right: 6).
  • dataset::tests (full, includes the overlay module), dataset::optimize::tests, index::append, dataset::index::frag_reuse, index::frag_reuse: 440 passed, 0 failed, 1 ignored, at --test-threads=3; clippy clean on the touched files. At default parallelism a few tests fail at random on this branch and on the untouched base alike, always DataFusion's FairSpillPool refusing an ExternalSorterMerge reservation: session contexts are cached by config, so every test shares one 150 MiB pool (DEFAULT_LANCE_MEM_POOL_SIZE_PER_PARTITION, upstream code identical in v9 and v10) and three concurrent 40 MB sort reservations exhaust it. All pass single-threaded.
  • Against the dataplatform (rerun-io/reality#3558 with its Lance patch pointed at this branch): redap_lance_util lib tests go from 103 passed / 1 failed to 104 passed, the failing one being its fragment-reuse trim test.

Compatibility

Metadata-only: the value written into an existing IndexMetadata field changes and a merged segment's coverage bitmap may shrink. No file-format or manifest schema change. Segments already stamped with the older value stay valid and keep pinning their reuse versions until their next merge or rebuild. Rolling back is safe: a pruned coverage is strictly more conservative for readers.

Agent

🤖 This PR was opened by a coding agent (Claude Fable 5.1).

@zehiko zehiko added lance fork 10.0.0 Landed on the release-10.0.0 fork line upstreamable change Belongs upstream, but is not there yet labels Sep 8, 2026
@github-actions github-actions Bot added the bug Something isn't working label Sep 8, 2026
@zehiko
zehiko requested a balanced review from Copilot September 8, 2026 11:10

Copilot AI 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.

🟡 Changes recommended

Some scalar paths could discard required remapping, while inverted merges retain stale version stamps.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates scalar-index merge metadata to use the manifest version and adds BTree fragment-reuse regression coverage.

Changes:

  • Stamps generic merged scalar segments with the current manifest version.
  • Tests remap cleanup and query correctness after a BTree merge.
File summaries
File Review
rust/lance/src/index/append.rs Requires fixes for unsafe ZoneMap, BloomFilter, and RTree stamping, plus stale inverted-index merge stamps.
rust/lance/src/dataset/optimize.rs Adds BTree merge, cleanup, and query regression coverage.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread rust/lance/src/index/append.rs Resolved
Comment thread rust/lance/src/index/append.rs Resolved
@zehiko
zehiko marked this pull request as draft September 8, 2026 11:31
@zehiko
zehiko force-pushed the zeljko/merge-stamp-current-version-r10 branch from c5147ad to 0becb79 Compare September 8, 2026 11:41
@zehiko zehiko changed the title fix(index): stamp merged scalar segments with the version they were built from fix(index): let a remapping scalar merge advance its version stamp Sep 8, 2026
@zehiko
zehiko marked this pull request as ready for review September 8, 2026 11:41
`IndexMetadata.dataset_version` is a segment's watermark for two readers:
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it, and
overlay masking treats data overlays committed at or below it as incorporated.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source segment's version. That keeps overlay masking correct, because the
entries a merge carries over never incorporate overlays, but it also means a
merge can never retire a fragment-reuse version: any source that predates the
version pins it for the whole dataset, and with deferred index remap the reuse
index only drains through a rebuild or an explicit `remap_column_index`.

For index types that translate their entries through the fragment-reuse index
while merging (`can_remap`: BTree, Bitmap, LabelList, NGram, and JSON when its
target does), stamp the merged segment with the manifest version it was built
from. Per source segment, remove from the merged coverage every carried-over
fragment with an overlay on an indexed field committed after that segment was
built; freshly scanned fragments already reflect their overlays and are left
alone. Uncovered fragments fall back to a scan and are re-indexed by the next
optimize, the same treatment `remap_column_index` applies. The overlay test
moves into `dataset::overlay::fragment_has_newer_indexed_overlay`, shared by
both call sites. Types that do not remap keep the oldest source's stamp.

The existing NGram overlay test now asserts the merged stamp equals the
manifest version the merge read, that the overlaid fragment leaves the coverage
while the untouched one stays, and that a second optimize restores the
coverage past the overlay; its query assertions are unchanged. The new BTree
test merges appended rows into a segment that predates a deferred-remap
compaction, asserts the stamp, asserts the trim then drains the reuse index,
and checks the plan answers from the index for every fragment with the
correct count.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@zehiko
zehiko force-pushed the zeljko/merge-stamp-current-version-r10 branch from 0becb79 to 7f2af3f Compare September 8, 2026 12:08

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

Review of the approach, with one blocking question, one design concern, and a few cleanups. The context and pseudocode below are what the inline comments refer back to; the interaction between stamps, coverage and the merge is easy to lose track of, so it is spelled out once here.

Context: the problem

IndexMetadata.dataset_version is one field read by two consumers that want opposite things:

  • Overlay masking (read path) treats overlay.committed_version <= index.dataset_version as "already incorporated, trust the index". It wants the stamp low enough to be honest about values.
  • FRI cleanup (is_index_remap_caught_up) treats index.dataset_version < reuse.dataset_version as "not caught up, keep the reuse version". It wants the stamp high enough to reflect that addresses are current.

A merge copies index entries between segments without re-reading the column, so its entries are exactly as value-stale as their source. But it opens each source through open_scalar_index, which installs the FRI as a RowIdRemapper, so every copied entry comes out with current addresses. A merged segment is therefore as stale as its oldest source on values and fully current on addresses, with one u64 to say both.

Lance 10 (lance-format#7244) stamps min(source stamps). That is the only honest single value for overlays, and it is a lie for the FRI: a merge can only lower or hold the stamp, so a merged segment can never pass the < check, and the FRI never drains under a maintenance loop that relies on consolidation to advance the watermark.

Context: what this branch does

In pseudocode, with a tiny scenario:

# inputs
sources          = [A, B]                  # the old segments being merged
manifest_version = 9                       # the data version the merge is reading
coverage         = A.bitmap ∪ B.bitmap     # = {10, 20}

    segment A    stamp 1    covers fragment 10
    segment B    stamp 5    covers fragment 20
    fragment 10  has an overlay committed at version 3, on the indexed field
    fragment 20  has no overlays

# step 0 — the merge itself
created_index = merge(A's entries, B's entries, freshly-read unindexed fragments)

# step 1 — the stamp
new_segment.dataset_version = manifest_version        # 9, not min(A, B) = 1

# step 2 — the prune (the loop at append.rs:613-628)
for each source S in sources:                         # A, then B
    for each fragment F that S covers:                # A → {10},  B → {20}
        for each overlay O on F:
            if O.committed_version > S.dataset_version:   # S was built before O existed
                if O touches a field this index covers:
                    coverage.remove(F)                    # stop claiming F

new_segment.fragment_bitmap = coverage                # {20}

Walking it: A (stamp 1) covers fragment 10, which has an overlay at 3; 3 > 1, so fragment 10 is removed. B (stamp 5) covers fragment 20, no overlays; kept. Result: stamp 9, coverage {20}.

Why step 2 is needed: with a stamp of 9, the reader's gate reads 3 <= 9 as "already incorporated" and would trust A's pre-overlay entries for fragment 10. Dropping fragment 10 from coverage avoids making that claim; the reader scans fragment 10 instead.

What happens to fragment 10 afterwards: it is indistinguishable from freshly appended, never-indexed data. The scanner reads it directly. The next optimize_indices indexes it as a delta segment (current values, overlay applied). The optimize after that folds the delta into the base. So the fragment is out of the index for one maintenance cycle and takes two more passes to be consolidated again.

This is the same advance-and-prune shape the codebase already uses in remap_index and prune_overlay_stale_fields_from_indices, so it is idiomatic here. It trades row-level overlay masking for fragment-level fallback on the merge path, in exchange for the FRI actually draining. That is the right trade. On datasets that never write overlays (no public write API produces one; every constructor in the tree is in a mod tests block), step 2 is a no-op and the change reduces to restoring the pre-lance-format#7244 stamp.

Findings

Blocking question — inline at overlay.rs:78. The write-side predicate matches fields by exact id; the reader gate (overlay_exclusion_offsets) matches through schema ancestry in both directions. Because this PR advances the stamp, an overlay the reader would have masked but this predicate does not catch stops being masked. That is a regression relative to base for that class, which base handled by keeping the stamp low.

Design concern — inline at append.rs:624. Step 2 runs after step 0, so the merge reads, merges and writes fragment 10's entries and then makes them unreachable: wasted work on a step that is already a bottleneck for us, and an oversized index whose contents do not match its coverage. Separately, an optimize_indices call that returns a smaller index ({10, 20} → {20}) is a surprising contract. The inline comment proposes computing the prune set before the merge, excluding those fragments from the per-source copy, and re-reading them fresh in the same merge so coverage is preserved. The plumbing for both halves already exists in merge_scalar_indices.

Rebase. release-10.0.0 has moved to 1985a2a29 (#62, Bitmap segment merge). has_segment_merge_primitive is now BTree | Bitmap | NGram, so multi-segment Bitmap consolidation takes the merge path and inherits the min stamp too, where it previously rebuilt and got a fresh stamp. The fix covers it (Bitmap::can_remap() is true), but there is no Bitmap test, and the downstream regression test uses a Bitmap index.

Cleanups — inline. Orphaned doc comment at overlay.rs:64; the prune loop is sources × all manifest fragments rather than sources × covered fragments at append.rs:616.

For the upstream PR. This reverses the stamp assertion in test_ngram_optimize_preserves_overlay_staleness, which lance-format#7244 pinned deliberately. Keeping the query assertions intact is the right argument to lead with; expect the stamp reversal to be the crux of that discussion.


This review was drafted with the help of an LLM (Claude) and checked against release-10.0.0 @ 1985a2a29 and this PR's head.

.data_file
.fields
.iter()
.any(|field_id| indexed_fields.contains(field_id))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Predicate is narrower than the reader gate it claims to mirror.

This matches by exact field id. overlay_exclusion_offsets (just below) matches through field_ancestry_by_id in both directions: an overlay field that is a descendant of the indexed field, or an ancestor of it, counts.

On base that gap is harmless, because the merge keeps the min stamp and the reader masks regardless. This PR advances the stamp, so a fragment carrying an overlay the reader would mask but this predicate does not catch stays in coverage with a stamp past the overlay. The reader's gate then reads committed_version <= dataset_version as "incorporated" and serves the pre-overlay entries. That is a regression relative to base for that class.

The same exact-match form already exists in remap_index and prune_overlay_stale_fields_from_indices, so this is consistent with precedent rather than new, but it adds a third reachable instance and the first on a path that previously stayed safe.

Two ways to resolve:

  1. Can an index's fields ever hold a non-leaf id (list, struct, JSON targets)? If not, the reader's ancestry handling is dead code and the narrow form is fine everywhere; worth a comment saying so.
  2. If it can, this predicate should use the same ancestry logic as the reader, ideally factored so the two cannot drift, plus a nested-field test.

(Tombstoned fields are fine as written: TOMBSTONE_FIELD_ID is -2 and never matches a real id.)

/// only non-indexed fields contributes nothing. An overlay whose
/// `committed_version <= index_version` is already incorporated by the index and
/// is ignored.
/// Whether `fragment` carries an overlay on one of `indexed_fields` that was committed after

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new function landed between overlay_exclusion_offsets's doc comment (lines 53-63) and its signature. As written, overlay_exclusion_offsets now has no docs and this function has two stacked doc blocks, the first of which describes the other function. Rustdoc will attach both to fragment_has_newer_indexed_overlay.

Comment thread rust/lance/src/index/append.rs Outdated
else {
continue;
};
for fragment in dataset.manifest.fragments.iter() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sources × every fragment in the manifest, not sources × covered fragments. On a dataset with ~100k fragments and several segments that is millions of bitmap contains calls per merge, for a condition that is false on any dataset without overlays.

Either iterate carried_over directly and look fragments up, or test fragment.overlays.is_empty() before the contains so the common case short-circuits on the cheaper check.

Comment thread rust/lance/src/index/append.rs Outdated
segment.dataset_version,
)
{
frag_bitmap.remove(fragment.id as u32);

@amunra amunra Sep 9, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two related issues with the ordering here. The pseudocode and the A / B / fragment-10 scenario this refers to are in the review summary; step numbers below are from there.

Issue A: the merge does work that this loop immediately discards

Step 0 (the merge) runs before step 2 (this loop). By the time frag_bitmap.remove(fragment.id) fires for fragment 10, the merge has already:

  1. opened source A and read every one of its entries for fragment 10 (through the FRI remapper),
  2. merged them with B's entries and the fresh data, and
  3. written them into the new index file.

The bitmap edit then makes those entries unreachable. They are dead weight in the file until the next merge's per-source filter (build_per_segment_filters, which reads the coverage bitmap) drops them. So the cost of reading, merging and writing fragment 10's entries is paid in full and the result is thrown away, and the output is an oversized index whose contents do not match its coverage.

This matters to us concretely: index optimization is a significant bottleneck in our maintenance loop today, and this ordering adds merge work proportional to the pruned fragments' entries on every consolidation where an overlay is present.

Everything step 2 needs is metadata (source bitmaps, source stamps, fragment overlay lists), none of it requires the merged file, so step 2 can run before step 0.

Issue B: an optimize step shrinks the index's coverage

Before this merge the index covered {10, 20}. After optimize_indices returns, it covers {20}. An optimization step has reduced what the index answers for, and it takes two more optimize passes to get back to where it started.

That is a surprising contract for optimize_indices. Users expect it to catch the index up to the data (coverage goes up or stays the same), not to hand back a smaller index. remap_index and prune_overlay_stale_fields_from_indices do shrink coverage, but they run inside compaction/remap, not inside the step whose stated purpose is to make the index better.

Proposal: precompute the prune, exclude those fragments from the copy, re-read them in the same merge

# before the merge
stale = {}
for each source S in sources:
    for each fragment F that S covers:
        if any overlay O on F has O.committed_version > S.dataset_version
           and O touches a field this index covers:
            stale.add(F)                              # → {10}

# feed the merge two adjusted inputs
per_source_coverage[S] = S.bitmap − stale             # A → {},  B → {20}
                                                       # (build_per_segment_filters uses these,
                                                       #  so A's fragment-10 entries are never read)
unindexed = unindexed ∪ stale                          # fragment 10 is re-read from the data,
                                                       # overlays applied, via load_unindexed_training_data

# the merge, once
created_index = merge(filtered source entries, freshly-read unindexed incl. fragment 10)

new_segment.dataset_version = manifest_version         # 9 — honest for every fragment now
new_segment.fragment_bitmap = A.bitmap ∪ B.bitmap ∪ unindexed   # {10, 20}: coverage preserved

Properties:

  • No wasted copy. Fragment 10's stale entries are never read from A; the per-source filter excludes them.
  • No bloat. The output file contains exactly the entries its coverage admits to.
  • Coverage preserved. The index still covers {10, 20} after optimize. Fragment 10's entries are fresh (current values, overlay applied), so the manifest-version stamp is honest for it too.
  • Same total work, done once. Re-reading fragment 10 is exactly what the next optimize pass would have done anyway; this pulls it into the current pass and skips the intermediate bloated file and the two follow-up passes.
  • A fully-stale source can be skipped outright. If every fragment A covers is in stale, A drops out of selected_old_indices and is never opened.

The plumbing exists already: merge_scalar_indices takes unindexed: &[Fragment] and reads it fresh through load_unindexed_training_data → dataset.scan(), which applies overlays. build_per_segment_filters builds one filter per source from that source's effective coverage, so subtracting stale from those bitmaps before the filters are built is enough to exclude the copies. Both would need to happen inside merge_scalar_indices (or the inputs adjusted before the call).

One trap: frag_bitmap also feeds the rebuild branch's scan set (rebuild_scalar_segment(…, frag_bitmap.iter().collect())). In that branch every fragment is re-read from the data, so overlays are incorporated and pruning would wrongly drop a fragment the rebuild indexes correctly. The precompute must stay gated on can_merge_segments, exactly as this post-hoc loop already is.

Scope

On a dataset with no overlays, stale is always empty and none of this changes anything. The cost in Issue A and the surprise in Issue B only appear when overlays exist. But those are also the only conditions under which the current loop does anything at all, so if the loop is worth having, it is worth having in the cheaper, coverage-preserving form.

amunra and others added 3 commits September 9, 2026 15:41
Brings in #62 (Bitmap segment merge), which routes multi-segment Bitmap
consolidation through the merge path this fix covers.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
fragment_has_newer_indexed_overlay was inserted between the doc comment of
overlay_exclusion_offsets and its signature, so rustdoc attached both blocks
to the new function and left overlay_exclusion_offsets undocumented. Move the
new function above the doc block.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The prune loop iterated every fragment in the manifest once per source
segment, for a condition that is false on any fragment without overlays.
Collect the overlaid fragments once and iterate those, so the common
no-overlay case does no per-segment work.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@amunra amunra added permanent fork change No upstream path; Rerun-specific by construction and removed upstreamable change Belongs upstream, but is not there yet labels Sep 9, 2026
@amunra

amunra commented Sep 9, 2026

Copy link
Copy Markdown

Status: accepted as a fork change; not upstreamable in this form

Pushed three commits on top of 7f2af3f25:

We are taking this as-is under permanent fork change because it unblocks the Lance 10 bump: on our datasets nothing writes overlays, so the prune loop is a no-op and the change reduces to restoring the pre-lance-format#7244 stamp on merges, which is what our compact → consolidate → trim maintenance loop depends on to drain the fragment-reuse index.

What blocks proposing this upstream

Two findings from the review are correctness/design issues that only manifest when overlays exist, which is exactly the population upstream cares about. They are deferred to a follow-up PR against this branch, after which the label should flip to upstreamable change.

1. Write-side field predicate is narrower than the reader's — inline. fragment_has_newer_indexed_overlay matches overlay fields to indexed fields by exact id. overlay_exclusion_offsets matches through schema.field_ancestry_by_id in both directions. Because this PR advances the stamp, an overlay the reader would mask but the predicate does not catch (concretely: a LabelList index on a List<T> column with an overlay on the item leaf) stays in coverage with a stamp past the overlay, and the reader serves the pre-overlay entries. Base did not have this failure; the min stamp kept masking regardless. Fix: extract the reader's matching closure into a shared helper, give fragment_has_newer_indexed_overlay a schema parameter, and use the helper at both call sites (append.rs, remapping.rs). ~30 lines plus a nested-field test.

2. The prune runs after the merge, and an optimize step shrinks coverage — inline. The merge reads, merges and writes the pruned fragments' entries and only then makes them unreachable, so the output is oversized and its contents disagree with its coverage; and optimize_indices returns an index covering fewer fragments than it started with, needing two more passes to recover. Fix: compute the stale set from metadata before the merge, subtract it from the per-source coverage fed to build_per_segment_filters so those entries are never copied, and add those fragments to unindexed so they are re-read fresh in the same merge. Coverage is then preserved and the manifest-version stamp is honest for every fragment. Must stay gated on can_merge_segments, since the rebuild branch re-reads everything and needs no prune.

3. Discussion point, not a code change. This reverses the stamp assertion in test_ngram_optimize_preserves_overlay_staleness, which lance-format#7244 pinned deliberately. The query assertions are intact and repeated after the recovery pass; that is the argument to lead with upstream.

Out of scope for both this PR and the follow-up, unchanged on min: Inverted merges (append.rs, separate arm), vector merges, and merge_existing_index_segments.


Drafted with the help of an LLM (Claude).

@amunra
amunra merged commit efbed31 into release-10.0.0 Sep 9, 2026
71 of 75 checks passed
@amunra
amunra deleted the zeljko/merge-stamp-current-version-r10 branch September 10, 2026 07:11
rerun-sync Bot pushed a commit to rerun-io/rerun that referenced this pull request Sep 10, 2026
Bump Lance version to 10.0.

Two API adaptations:
- `Operation::Update` renamed `merged_generations` to
`compacted_sstables`.
- `data_storage_format.version` is now a typed `ConcreteFileVersion`
instead of a `String`.

Separate Lance fixes had to be made as part of rerun-io/lance#77

Source-Ref: 795ed996496f3f023780c051c89cefe35127633a
amunra added a commit that referenced this pull request Oct 12, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

Tests, for BTree, Bitmap, NGram and LabelList, with and without stable row
ids: full coverage and the manifest stamp after one optimize; the merged
file holds the overlaid values, including a NULL override, and none of the
replaced ones; a deletion hole in the overlaid fragment; a fragment whose
overlay predates its source, or touches an unindexed field, is carried over
without reading its data files; every source stale with nothing appended;
a stale fragment under a segment the merge did not select is left alone;
the scanner matches an index-disabled oracle and plans no scan; a second
optimize changes nothing. The ZoneMap control keeps the oldest source's
stamp. A BTree merge over a segment that predates a deferred-remap
compaction asserts the trim then drains the reuse index and the plan
answers from the index. The Bitmap merge tests told merge from rebuild by
the stamp; they now check no indexed data file was read. The tagged-upgrade
tests that pinned the legacy version through a merge now assert it is
released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 12, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

Tests, for BTree, Bitmap, NGram and LabelList, with and without stable row
ids: full coverage and the manifest stamp after one optimize; the merged
file holds the overlaid values, including a NULL override, and none of the
replaced ones; a deletion hole in the overlaid fragment; a fragment whose
overlay predates its source, or touches an unindexed field, is carried over
without reading its data files; every source stale with nothing appended;
a stale fragment under a segment the merge did not select is left alone;
the scanner matches an index-disabled oracle and plans no scan; a second
optimize changes nothing. The ZoneMap control keeps the oldest source's
stamp. A BTree merge over a segment that predates a deferred-remap
compaction asserts the trim then drains the reuse index and the plan
answers from the index. The Bitmap merge tests told merge from rebuild by
the stamp; they now check no indexed data file was read. The tagged-upgrade
tests that pinned the legacy version through a merge now assert it is
released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

Tests, for BTree, Bitmap, NGram and LabelList, with and without stable row
ids: full coverage and the manifest stamp after one optimize; the merged
file holds the overlaid values, including a NULL override, and none of the
replaced ones; a merge over a large fragment with one overlaid row reads a
fraction of its data file; a stale fragment under a segment the merge did
not select is left alone; the scanner matches an index-disabled oracle and
plans no scan; a second optimize changes nothing. The ZoneMap control
keeps the oldest source's stamp. A BTree merge over a segment that
predates a deferred-remap compaction asserts the trim then drains the
reuse index and the plan answers from the index. The Bitmap merge tests
told merge from rebuild by the stamp; they now check no indexed data file
was read. The tagged-upgrade tests that pinned the legacy version through
a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

Tests, for BTree, Bitmap, NGram and LabelList, with and without stable row
ids: full coverage and the manifest stamp after one optimize; the merged
file holds the overlaid values, including a NULL override, and none of the
replaced ones; a merge over a large fragment with one overlaid row reads a
fraction of its data file; a stale fragment under a segment the merge did
not select is left alone; the scanner matches an index-disabled oracle and
plans no scan; a second optimize changes nothing. The ZoneMap control
keeps the oldest source's stamp. A BTree merge over a segment that
predates a deferred-remap compaction asserts the trim then drains the
reuse index and the plan answers from the index. The Bitmap merge tests
told merge from rebuild by the stamp; they now check no indexed data file
was read. The tagged-upgrade tests that pinned the legacy version through
a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 13, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 15, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
amunra added a commit that referenced this pull request Oct 22, 2026
`IndexMetadata.dataset_version` is a segment's watermark for two readers.
`cleanup_frag_reuse_index` retires fragment-reuse versions at or below it,
and overlay masking trusts the index for data overlays committed at or
below it and re-reads the rows of newer ones.

Since lance-format#7244 `merge_scalar_indices` stamps a merged segment with the oldest
source's version. That keeps masking correct, because the entries a merge
carries over never incorporate an overlay, but it also means a merge can
never retire a reuse version: any source that predates it pins it for the
whole dataset, and with deferred index remap the reuse index only drains
through a rebuild or an explicit `remap_column_index`.

For the types that translate their entries through the reuse index while
merging (`can_remap`: BTree, Bitmap, LabelList, NGram, JSON when its target
does), stamp the merged segment with the manifest version the merge read
and make that stamp true: per source segment, find the rows whose indexed
field an overlay replaced after the source was built, using the same
per-row, field-aware, version-gated check the scanner masks by; read those
rows, with their overlays resolved, in the one sorted scan that already
indexes the newly appended fragments; and drop their carried-over entries
through each source's old-data filter, which becomes an allow-list of the
kept fragments' rows minus the stale ones. The merged segment covers every
live fragment with current values, nothing is read twice, and the sort is
over the appended and overlaid rows only. Types that do not remap keep the
oldest source's stamp and carry everything over. A seed is written with
its data file, before any overlay, so the seed path is skipped when a
merge must read overlaid rows.

The tests whose expectations this flips move with it: the NGram overlay
test now asserts the rescan, with and without stable row ids; the ZoneMap
control keeps the oldest source's stamp while BTree and Bitmap take the
manifest's; the tagged-upgrade tests that pinned the legacy version
through a merge now assert it is released.

Ported in part from #77.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
westonpace pushed a commit to lance-format/lance that referenced this pull request Oct 22, 2026
…9941)

### Overview

This change improves index segment merging and resolves (for a subset of
index types) the tension between:
* *Clearing FRI entries* - Which require indices rebuilt against the
latest data.
* *Overlay Lookups* - Which invalidate index segment data.

### The Problem

Each index segment tracks an `IndexMetadata.dataset_version`, also known
as "the stamp".

An FRI entry can only be removed from a dataset's manifest once every
index segment's stamp is newer than the version it records.

Overlays, however, get applied based on the dataset manifest version,
and to ensure correctness #7244 changed the merge
logic so that the stamped version is the _minimum_ of the various
segments being merged. This is because the earlier logic of merging and
stamping latest would effectively discard the overlays, since a merge
copies the source segments' entries rather than re-reading them.

This introduced the "FRIs don't clear" bug!

### This PR's solution

The solution is, during index merge, to squash down the overlays by
re-reading the overlaid rows from the fragments and stamp the merged
segment with the _manifest version_ the merge read.

This is only possible for index types that remap their entries through
the FRI when merging (`can_remap`). The other index types carry their
entries over untranslated, so their merges are still stamped with the
_minimum_ version of the segments being merged and still retain the
"FRIs don't clear" bug.

| index type | `can_remap` | stamp after a merge | FRI | rows overlaid
after a source was built |
|---|---|---|---|---|
| BTree, Bitmap, LabelList, NGram | yes | manifest version | drains
below the stamp on the next trim | re-read; merged file holds current
values |
| JSON | that of its target index | as the target | as the target | as
the target |
| ZoneMap, BloomFilter, RTree | no | oldest source, as before | stays
pinned until a rebuild or `remap_column_index` | carried over as built;
masked at read time |

### Testing

Tests pin four properties of a merge over fragments with overlays, for
BTree, Bitmap, NGram and LabelList, with and without stable row ids:

* **The merged segment is honest.** It is stamped with the manifest
version and covers every fragment, and its file holds the overlaid
values (NULL overrides included) and none of the replaced ones. Queries
match an index-disabled oracle and the planner answers from the index
alone, so no masking is left to do.
* **It is a merge, not a rebuild.** A merge reads none of the base data
files of the fragments its sources already cover; a merge over a large
fragment with one overlaid row reads a fraction of that fragment's file.
Existing merge tests that told merge from rebuild by the stamp, which no
longer distinguishes them, now use this read-based check.
* **It stays in scope.** A stale fragment under a segment not selected
for the merge is left alone, and a second optimize is a no-op.
* **The FRI drains.** A merge over a segment that predates a
deferred-remap compaction lets the next trim drain the reuse index, and
the tagged-upgrade tests that pinned the legacy version through a merge
now assert it is released.

ZoneMap serves as the control: its merge keeps the oldest source's
stamp.

### Related

* #7244, which introduced the minimum stamp.
* rerun-io#77, which addressed the same problem by discarding
fragments with overlays from index merges. Inspiration for this PR; the
approach here differs.

### Compatibility

Metadata-only: a merged segment's stamp changes and its file holds the
overlaid values. No format change. Existing segments stay valid. Rolling
back is safe.

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

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lance fork 10.0.0 Landed on the release-10.0.0 fork line permanent fork change No upstream path; Rerun-specific by construction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants