Skip to content

feat(frag-reuse): add LANCE_FRAG_REUSE_REMAP_MODE=assert(<mode>) - #47

Merged
amunra merged 1 commit into
release-8.0.0from
adam/assert_compact_fri
Aug 24, 2026
Merged

amunra merged 1 commit into
release-8.0.0from
adam/assert_compact_fri

Conversation

@amunra

@amunra amunra commented Aug 24, 2026 •

Copy link
Copy Markdown

Why

A deployment that has committed to the compact reuse-remap form still has no way to tell whether some code path quietly falls back to the direct one. It finds out as the memory blowup the compact form exists to avoid, long after the call that chose it.

What

LANCE_FRAG_REUSE_REMAP_MODE gains an assert(<mode>) spelling:

export LANCE_FRAG_REUSE_REMAP_MODE="assert(compact)"

This selects the compact form as the process default and turns every other form into a panic, so the offending call site shows up as a backtrace:

thread '...' panicked at rust/lance/src/dataset.rs:431:5:
LANCE_FRAG_REUSE_REMAP_MODE=assert(compact) but this code path uses direct
   2: lance::dataset::assert_frag_reuse_remap_mode
   3: lance::dataset::optimize::commit_compaction::{{closure}}
   4: lance::dataset::optimize::compact_files::{{closure}}

It is a plain assert!, not debug_assert!, because the deployments that need it run release builds.

Three assert sites cover the ways a form gets chosen:

Site Catches
Dataset::checkout_manifest every dataset open — the backtrace names whichever path built the mode
open_frag_reuse_index_with_mode callers that pass a mode not coming from a Dataset
commit_compaction CompactionOptions::index_remap_mode, gated on needs_remapping

The compaction assert is gated on needs_remapping on purpose: a stable-row-id or deferred compaction never consults index_remap_mode, so asserting there would report configuration that costs nothing and would drown the real hits.

Arming it emits one warn! on the read that fixes the setting for the process, so an operator can tell a later panic apart from an unrelated crash:

WARN lance::dataset: LANCE_FRAG_REUSE_REMAP_MODE=assert(compact): this process will PANIC if any code path uses another fragment reuse remap form.

Everything else is unchanged: the plain direct/compact spellings behave exactly as before, and an unparseable assert(...) falls back to the existing warn-and-use-direct path rather than failing an open. With the env var unset there is no behavioural change at all.

Also adds IndexRemapMode::as_str(), the inverse of the existing TryFrom<&str>, so both messages name a form in the same lowercase spelling the env var uses.

It already found something

Running cargo test -p lance --lib optimize::tests under assert(compact) gives 64 passed / 39 failed. Seven of the 39 are cases that deliberately exercise the direct form (test_catch_up_rewrites_the_index_under_either_form::case_1_direct, the case_2 arms of the btree/ivf_pq/inverted remap families, test_frag_reuse_remap_mode_end_to_end::case_1_direct, both arms of test_shared_session_serves_both_forms) — those are the assert working as designed, not findings.

The other 32 are the forgotten path. They call compact_files with CompactionOptions { ..Default::default() } on non-stable-row-id datasets, never mention a remap form, and — because CompactionOptions::default().index_remap_mode is Direct and is not wired to LANCE_FRAG_REUSE_REMAP_MODE — build the per-row HashMap<u64, Option<u64>> remap anyway. That is the writer-side instance of exactly the growth the compact form exists to avoid. Examples:

test_compact_data_files::data_storage_version_2_LanceFileVersion__Stable
test_compact_deletions::data_storage_version_1_LanceFileVersion__Legacy
test_compact_distributed::...::use_stable_row_id_1_false
test_distributed_compact_concurrent_delete_no_resurrection
test_max_source_fragments
binary_copy::test_binary_copy_remaps_unstable_row_ids
... plus the 13 test_compact_blob_v2_* cases

Wiring CompactionOptions to the env var is a behaviour change beyond the scope of this PR, so it is left for a follow-up.

Testing

  • parse_frag_reuse_remap_mode gains 6 cases for the new grammar (assert(compact), assert(direct), ASSERT(COMPACT), padded, unparseable inner mode, unterminated) alongside the 7 existing ones — 13 pass.
  • With the env var unset: 46 frag_reuse and 103 optimize::tests pass, i.e. no change to existing behaviour.
  • With assert(compact) set: test_both_modes_agree_on_a_real_payload::case_1_compact passes and case_2_direct panics, confirming the assert fires only on the other form; test_catch_up_rewrites_the_index_under_either_form::case_2_compact passes, confirming the needs_remapping gate keeps inert configuration quiet.
  • The one-time warn! was verified with a throwaway capturing subscriber (emitted exactly once across two ReadParams::default() calls); that scratch test was deleted.
  • cargo fmt --all and cargo clippy -p lance --tests -- -D warnings are clean.

🤖 Generated with Claude Code

A deployment that has committed to the compact reuse-remap form still has no
way to tell whether some code path quietly falls back to the direct one -- it
finds out as the memory blowup the compact form exists to avoid, long after the
call that chose it.

`LANCE_FRAG_REUSE_REMAP_MODE=assert(compact)` selects the compact form as the
process default and turns every other form into a panic, so the offending call
site shows up as a backtrace instead. The assert is a plain `assert!`, not
`debug_assert!`, because the deployments that need it run release builds.

Three sites cover the ways a form is chosen: `Dataset::checkout_manifest` (every
dataset open, whichever path built the mode), `open_frag_reuse_index_with_mode`
(callers that pass a mode not coming from a `Dataset`), and `commit_compaction`
(`CompactionOptions::index_remap_mode`). The compaction one is gated on
`needs_remapping`, since a stable-row-id or deferred compaction never consults
the mode and asserting there would report configuration that costs nothing.

Arming it warns once, on the read that fixes the setting for the process, so an
operator can tell a later panic apart from an unrelated crash. The plain
`direct`/`compact` spellings are unchanged, and an unparseable `assert(...)`
falls back to the existing warn-and-use-direct behaviour rather than failing an
open.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@amunra
amunra force-pushed the adam/assert_compact_fri branch from 876a5d8 to f1a8116 Compare August 24, 2026 09:51
@amunra
amunra merged commit 49d9a40 into release-8.0.0 Aug 24, 2026
1 check passed
amunra added a commit that referenced this pull request Sep 10, 2026
A deployment that has committed to the compact reuse-remap form still has no
way to tell whether some code path quietly falls back to the direct one -- it
finds out as the memory blowup the compact form exists to avoid, long after the
call that chose it.

`LANCE_FRAG_REUSE_REMAP_MODE=assert(compact)` selects the compact form as the
process default and turns every other form into a panic, so the offending call
site shows up as a backtrace instead. The assert is a plain `assert!`, not
`debug_assert!`, because the deployments that need it run release builds.

Three sites cover the ways a form is chosen: `Dataset::checkout_manifest` (every
dataset open, whichever path built the mode), `open_frag_reuse_index_with_mode`
(callers that pass a mode not coming from a `Dataset`), and `commit_compaction`
(`CompactionOptions::index_remap_mode`). The compaction one is gated on
`needs_remapping`, since a stable-row-id or deferred compaction never consults
the mode and asserting there would report configuration that costs nothing.

Arming it warns once, on the read that fixes the setting for the process, so an
operator can tell a later panic apart from an unrelated crash. The plain
`direct`/`compact` spellings are unchanged, and an unparsable `assert(...)`
falls back to the existing warn-and-use-direct behaviour rather than failing an
open.

The production change applies unchanged: release-10.0.0 already carries
`parse_frag_reuse_remap_mode` and `default_frag_reuse_remap_mode` from #59. The
one conflict was the `#[case]` list of `test_parse_frag_reuse_remap_mode`,
resolved to the source's cases and its `expected_asserted` column while keeping
this branch's `unparsable` spelling, which is what the typos hook and the rest
of the tree use.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 49d9a40)
amunra added a commit that referenced this pull request Sep 10, 2026
#79)

A deployment that has committed to the compact reuse-remap form still has no
way to tell whether some code path quietly falls back to the direct one -- it
finds out as the memory blowup the compact form exists to avoid, long after the
call that chose it.

`LANCE_FRAG_REUSE_REMAP_MODE=assert(compact)` selects the compact form as the
process default and turns every other form into a panic, so the offending call
site shows up as a backtrace instead. The assert is a plain `assert!`, not
`debug_assert!`, because the deployments that need it run release builds.

Three sites cover the ways a form is chosen: `Dataset::checkout_manifest` (every
dataset open, whichever path built the mode), `open_frag_reuse_index_with_mode`
(callers that pass a mode not coming from a `Dataset`), and `commit_compaction`
(`CompactionOptions::index_remap_mode`). The compaction one is gated on
`needs_remapping`, since a stable-row-id or deferred compaction never consults
the mode and asserting there would report configuration that costs nothing.

Arming it warns once, on the read that fixes the setting for the process, so an
operator can tell a later panic apart from an unrelated crash. The plain
`direct`/`compact` spellings are unchanged, and an unparsable `assert(...)`
falls back to the existing warn-and-use-direct behaviour rather than failing an
open.

The production change applies unchanged: release-10.0.0 already carries
`parse_frag_reuse_remap_mode` and `default_frag_reuse_remap_mode` from #59. The
one conflict was the `#[case]` list of `test_parse_frag_reuse_remap_mode`,
resolved to the source's cases and its `expected_asserted` column while keeping
this branch's `unparsable` spelling, which is what the typos hook and the rest
of the tree use.


(cherry picked from commit 49d9a40)

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants