Repository navigation
Conversation
|
aa91774 to
842dffb
Compare
842dffb to
3b7b7b6
Compare
## Summary Use the existing `lance_table::format::Transaction::try_from(&Transaction)` conversion in the two places that rebuilt the format wrapper by hand: - detached commit collision retry, when rebuilding the inline transaction copy - injected foreign-commit test helper Also correct the `format::Transaction` docs. The wrapper holds a `pb::Transaction` message in memory; the manifest writer serializes it at `write_protobuf`. Because `inner` and `From<pb::Transaction>` are public, wrapping does not imply validation. The reverse `From` only moves the message out without another conversion. ## Behavior and compatibility - `lance_table::format::Transaction`, `inner`, `as_pb`, `CommitHandler`, and `ManifestWriter` are unchanged. - No durable-format change; inline/spill decisions and schema classification remain in their existing paths. - Commit outcome verification still compares durable protobuf messages, preserving the rewrite frag-reuse case. - The detached retry still only rebuilds the inline copy; the external `.txn` file is still written once before the retry loop. - The injected foreign-commit test still exercises the same retry path through the shared conversion. ## Validation - `cargo fmt --all -- --check` - `cargo clippy --all --tests --benches --profile ci -j 8 -- -D warnings` - `cargo test -p lance-table --lib --profile ci format::transaction`: 4 passed - One `cargo test -p lance --lib --profile ci -j 1 --no-run` link; 18 targeted runtime tests passed from the same binary: - 8 commit outcome and transaction-file tests - 3 injected foreign-commit/raw-arrow retry tests (one rstest case pair) - 7 dataset transaction inline/external/detached tests There is no deterministic test for the detached random-version collision retry itself; that branch is compile-covered, and the same conversion is exercised by the injected foreign-commit tests. The detached first-attempt path is covered by `test_list_detached_manifests`. No diff overlap with #11232 (inline toggle), #11021 (expected-head mode), or #11280 (test metadata); none changes these conversion sites.
wjones127
left a comment
There was a problem hiding this comment.
Thanks for pushing this through. The single-hop translation and the cache namespacing look right to me, and the non-transitive map tests (especially the Bitmap double-translation one) are exactly what I'd want here.
Three things block approval:
- The spec still says flag 20 is reserved and readers must reject it (inline).
- RTree's
calculate_included_fragschange has no test (inline). - FTS has no alias coverage:
issue(blocking): FTS/Inverted has no alias coverage. The alias tests have no IndexType::Inverted case. Inverted takes the batch-remap open path, and its compaction goes through the _ => arm in remap.rs, which prepends aliases. That's the same shape as the Bitmap double-translation bug. The promotion fix (keeping aliases via ..segment.clone()) is here, but the regression test from 842dffb didn't survive onto this branch.
Could we add tests, using the dataset_with_aliased_scalar_index fixtures, for:
- an aliased inverted segment whose FTS query matches a full scan
- compaction with a non-transitive map
merge_existing_index_segmentson a single aliased segment, which keeps the UUID and aliases and returns the same row addresses
Done when those pass and would fail on a double or missing translation.
Non-blocking: a design suggestion on applying aliases at decode time (inline on remap.rs), a commit-time stable-row-id check, the Java binding, and a note on the calculate_included_frags behavior change for non-aliased segments.
suggestion: +1 to the breaking-change label / feat(index)!: title, since adding a public field breaks Rust callers who build IndexMetadata with literals. Maybe as a follow-up: #[non_exhaustive] plus a constructor or Default impl would let us add fields like this without a break next time.
| // postings via `load_bitmap` / `null_map`, which already apply | ||
| // the remapper installed at open (including local_fragment_aliases). | ||
| // Wrapping `row_id_map` again would apply aliases twice. | ||
| IndexType::Bitmap | IndexType::LabelList => { |
There was a problem hiding this comment.
suggestion: I wonder if aliases should be applied as part of decoding a segment's files rather than as a remapper. Since a segment's map never changes, we can treat its stored addresses as if they'd been written with the committed ids: translate wherever an index decodes row addresses (as decode_page / load_bitmap effectively do today), and have maintenance read through that same decode. Then this match goes away and nothing ever prepends.
Today some remap_streaming impls read raw ids and others read through the open-time remapper, and getting that wrong is the Bitmap double-translation bug. Keeping aliases separate from the FRI remapper slot would also make "already translated" explicit. Fine as a follow-up.
There was a problem hiding this comment.
makes sense, i can track as a follow up
| import_vec_from_method(env, java_operation, "getRemovedIndices", |env, index| { | ||
| index.extract_object(env) | ||
| })?; | ||
| if !new_indices.is_empty() |
There was a problem hiding this comment.
question: Why a guard here rather than adding local_fragment_aliases to Java's Index, like Python does? Adding CreateIndex to the read_dataset list means every Java CreateIndex now checks out the read version when the handle isn't already at it. The guard also only catches republishing a UUID that was already aliased at read_version. If the field round-trips, we don't need the special case.
Also, all four Java CI jobs failed while resolving google-java-format, before the compile step, so CI hasn't built this path or run any tests on it.
There was a problem hiding this comment.
Good call, adding local_fragment_aliases directly to Java's Index so it round trips is definitely cleaner than checking out the read version. Let's do that in a follow up PR once the Java CI maven resolution issue is sorted out.
| while let Some((_, serialized)) = pages.try_next().await? { | ||
| let page = FlatIndex::try_new(serialized)?; | ||
| let page = if let Some(remapper) = self.batch_remapper.as_ref() { | ||
| let serialized = remap_record_batch_async(remapper.as_ref(), serialized, 1).await?; |
There was a problem hiding this comment.
question: This also changes behavior for non-aliased segments: with a V0 FRI, calculate_included_frags now returns post-compaction fragment ids where it used to return stored ones. The same goes for ZoneMap, BloomFilter and RTree. It looks like a fix to me. Was it intended? If so, could the description mention it, since it affects existing tables that recover a missing fragment_bitmap?
There was a problem hiding this comment.
Yes, that was intended. Returning post compaction fragment ids when recovering a missing fragment_bitmap under a V0 FRI is the right behavior.
## Problem Every scalar index merge repeated the same field and declaration validation, row-domain guard, per-segment filters, destination store allocation, source opening/downcast, and `IndexMetadata` assembly. Bitmap also depended on btree for its empty new-data stream, and append's merge dispatch rebuilt the same filters per arm. ## Change Add `scalar/segment_merge.rs` to own the shared merge inputs and output: - empty groups, keyed field/path and same-declaration checks - per-type stable-row-id legacy guard, preserving Bitmap/BTree/LabelList/MinHash bottom-level mixed-domain errors; RTree/NGram keep the shared-domain guard - per-segment filters and coverage unions - typed source opening/downcast - UUID/store allocation and one metadata constructor - the empty value/address stream used by pure consolidation All scalar merge modules now use it; Bitmap no longer reaches into btree. `append.rs` constructs filters once for the simple merge primitives. MinHash keeps its historical admission rule: non-stable tables can merge disjoint v0 and v1 segments into v1, while stable tables still reject legacy input. No public API, persisted format, or Python wrapper changes. #11273, #11231 and #11280 are complementary and not dependencies; their behaviors are not pulled in here. Overlap is mechanical in the same scalar modules and append dispatch. Current main's #11290 only changes tagged FRI retention bookkeeping and #11391 changes commit configuration; neither changes a caller contract used by this change. ## Validation - `cargo fmt --all -- --check`: pass - `cargo clippy --all --tests --benches --profile ci -j 4 -- -D warnings`: pass (only existing lance-linalg build-script notices) - Runtime on head `d23cbafd5`, one test executable, 49 unique tests: - scalar MinHash module: 16 passed, including mixed v0-layout/v1 disjoint merge, commit, reopen and `fast_search` for both stable and non-stable datasets, plus the historical-layout legacy regression - `index::tests::merge`: 8 passed - append/optimize: BTree 9, Bitmap 7, NGram 1, BloomFilter 4, FTS 3, scalar stale-row 1 No released MinHash v0 fixture exists; the v0 layout is reconstructed from a current segment (`_rowid`, version 0) by the test helper. The test exercises real merge, commit, reopen and search rather than mocked metadata. Remaining coverage: the full workspace test matrix and a Python wheel were not run. The Python wrapper is unchanged, and the mixed historical layout is not constructible through it. Clean merge tree with current main `e90fe4b8e7c8c819bb51171a43fc94d01b40e2c7`: `bdbb1029cd3e7ab3a54ac3036d258cd4e6dcbcaa`.
| /// updates `fragment_bitmap` to post-compaction fragment ids while | ||
| /// preserving `local_fragment_aliases`. Ensuring no unmapped stored | ||
| /// fragment id collides with a mapped destination is a writer invariant. | ||
| pub fn validate_local_fragment_aliases(&self) -> Result<()> { |
There was a problem hiding this comment.
We intentionally don't validate aliases against fragment_bitmap here. Since the 0th (lol) version of FRI can
update coverage after compaction while the index files still use their original aliases. This validates the metadata itself and stored ID collision checks belong to the writer.
| index.uuid | ||
| ))); | ||
| } | ||
| if !plugin.supports_batch_row_id_remapping() { |
There was a problem hiding this comment.
Reusing supports_batch_row_id_remapping() rather than adding another plugin capability. Aliases compose ahead of FRI, and indexes storing logical row IDs on srid tables are rejected.
| // postings via `load_bitmap` / `null_map`, which already apply | ||
| // the remapper installed at open (including local_fragment_aliases). | ||
| // Wrapping `row_id_map` again would apply aliases twice. | ||
| IndexType::Bitmap | IndexType::LabelList => { |
There was a problem hiding this comment.
Bitmap and LabelList already translate postings when loading them. Applying aliases again during remap would corrupt results. Other indexes read raw pages, so they need aliases prepended to the remapper.
| }) | ||
| { | ||
| return Err(Error::unsupported_error(format!( | ||
| "Cannot republish aliased index segment {} through Java CreateIndex: Java Index does not carry local_fragment_aliases", |
There was a problem hiding this comment.
Java's Index representation doesn't carry aliases yet. Rejecting republishing an existing aliased UUID prevents CreateIndex from silently dropping its mapping.
| // postings via `load_bitmap` / `null_map`, which already apply | ||
| // the remapper installed at open (including local_fragment_aliases). | ||
| // Wrapping `row_id_map` again would apply aliases twice. | ||
| IndexType::Bitmap | IndexType::LabelList => { |
There was a problem hiding this comment.
makes sense, i can track as a follow up
| import_vec_from_method(env, java_operation, "getRemovedIndices", |env, index| { | ||
| index.extract_object(env) | ||
| })?; | ||
| if !new_indices.is_empty() |
There was a problem hiding this comment.
Good call, adding local_fragment_aliases directly to Java's Index so it round trips is definitely cleaner than checking out the read version. Let's do that in a follow up PR once the Java CI maven resolution issue is sorted out.
| while let Some((_, serialized)) = pages.try_next().await? { | ||
| let page = FlatIndex::try_new(serialized)?; | ||
| let page = if let Some(remapper) = self.batch_remapper.as_ref() { | ||
| let serialized = remap_record_batch_async(remapper.as_ref(), serialized, 1).await?; |
There was a problem hiding this comment.
Yes, that was intended. Returning post compaction fragment ids when recovering a missing fragment_bitmap under a V0 FRI is the right behavior.
Xuanwo
left a comment
There was a problem hiding this comment.
I found two additional merge blockers by tracing the Java and IVF paths. Both are still present on da117191f.
-
Java can republish a BTree segment without its aliases.
Dataset.getIndexes()followed bycommitExistingIndexSegments()keeps the UUID, but Java extraction initializeslocal_fragment_aliasesto an empty map. JNI then calls Rust directly, bypassing the JavaCreateIndexguard. A segment whose file stores fragment 17 and whose manifest covers 42 loses the17 → 42mapping. Please preserve the mapping from the existing UUID or reject the commit before publication. A round-trip test can reopen the table and compare indexed results against a full scan, or verify the version stays unchanged on rejection. -
A multi-segment IVF merge can discard vectors and still claim their coverage. On a table without stable row IDs, put the
17 → 42alias on the second segment only. The merge builds its ownership filter from committed fragment 42, butfilter_batch_to_owned_rowsapplies it to stored fragment 17. The output unions both coverage bitmaps and inherits the first segment’s empty alias map. Please translate each input or reject unsupported aliased inputs before merging. A query whose nearest neighbor is in the second segment should agree with an exact scan after reopen.
Xuanwo
left a comment
There was a problem hiding this comment.
The new IVF guard checks every input, including an aliased second segment. Two issues remain at the Java boundary on 6366217.
- JNI compilation fails at
blocking_dataset/index.rs:608becauseIndexSegmenthas nolocal_fragment_aliasesfield (E0609). Lines 610 and 615 also access its privateuuidfield (E0616). The incomingsegment_metadatastill containsIndexMetadatawith a public UUID. That is where the input can be checked against the manifest before conversion. CI log - Tracing
mergeExistingIndexSegments, Java imports bothIndexobjects fromgetIndexes()with empty alias maps. The Rust guard therefore sees no aliases even if the second committed IVF segment needs them. A multi-segment merge then assigns a new UUID, so checking that output UUID at commit time cannot identify the aliased source. Please preserve or reject aliases on the Java merge inputs too.
Could you cover both direct commit and merge through Java, checking that rejection leaves the table version unchanged, or that the reopened index agrees with a full scan if the operation succeeds?
Xuanwo
left a comment
There was a problem hiding this comment.
Thanks for carrying localFragmentAliases through Java and JNI. I traced three remaining paths on 73fcf660.
- Publication accepts aliases on logical-row-ID segments.
test_aliased_unsupported_segments_rejectedsuccessfully commits v0 Bitmap and BTree metadata on a stable-row-ID table, then expects opening the index to fail. The format prohibits those segments from carrying aliases. Please reject them before publishing and assert that the table version stays unchanged. A physical-row-address segment on the same kind of table should still work. - Aliased RTree merges stop before reaching the merger. The
all_rtreebranch inlifecycle.rsusesIntoIndexSegmentto prune coverage. That conversion rejects every nonempty alias map. Please prune the coverage while retaining the mapping for the merger, and compare a merged aliased RTree query with an exact scan undergeo. - Java
getZonemapStats()exposes stored fragment IDs to scan planners. JNI loads raw zone statistics withZoneMapIndex::load_zone_statisticsand returns the file's IDs. For a segment mapping 17 to 42, callers need zone entries for committed fragment 42. Please apply the mapping and cover this through the Java API.
Xuanwo
left a comment
There was a problem hiding this comment.
[AI review] The test_index_metadata fixture at rust/lance-table-runtime/src/commit/transaction.rs:1131 still omits local_fragment_aliases. Clippy and MSRV stop while compiling the test crate. Could you initialize the alias map in that fixture so the tests can run? CI log
Xuanwo
left a comment
There was a problem hiding this comment.
[AI review] CI fails to compile the lance library tests with E0063 on the merge with main. Could you integrate main and initialize local_fragment_aliases in two more IndexMetadata fixtures under rust/lance/src/? The affected helpers are segment() in index/lifecycle.rs (line 2171) and segment_over() in io/exec/knn.rs (line 6417). CI log
…tenance Co-authored-by: Drew <[email protected]>
6b1c182 to
da355b8
Compare
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The rebase preserves the alias contract across readers and maintenance: translate stored IDs once before fragment reuse, retain aliases with retained files, and clear them after rewriting addresses. ZoneMap statistics still report committed fragment IDs, and optimization after tagged fragment reuse preserves indexed rows.
Follow up to #10780. This wires up
local_fragment_aliasesin the readers and index maintenance paths so that once staged transactions start writing aliases, they dont get lost or break queries, compaction, FRI, or index merges.When an index is built before commit, the index file has whatever fragment ids it saw during training (say frag 0). On commit or rebase, the dataset might assign that fragment a different id (say frag 42). Instead of rewriting the index file, we keep
{0: 42}inIndexMetadata.local_fragment_aliasesand translate on read before FRI runs:flowchart LR A["Index file (frag 0)"] --> B["local_fragment_aliases {0: 42}"] B --> C["Committed frag 42"] C --> D["FRI (if compacted)"] D --> E["Current frag"]When compaction, remap, or
optimize_indicesrewrites the index files, the new files have the real fragment ids andlocal_fragment_aliases(plus bit 20) gets cleared. Metadata only updates keep the map.What changed:
local_fragment_aliaseson commit and read, and set or clearFLAG_LOCAL_FRAGMENT_ALIASES(bit 20) inassemble_manifestandwrite_manifest_filesupports_batch_row_id_remapping), and namespace the index cache by the alias map (alias_cache_namespace)calculate_included_fragsfor BTree, ZoneMap, BloomFilter, and RTree so bitmap recovery doesnt write old training ids back intofragment_bitmapremap_streaming(prepend_fragment_aliases) for raw page readers during compaction while leaving already translated Bitmap and LabelList postings untouched, wire per source remappers into NGram merges, and rebuild aliased ZoneMap and BloomFilter segments duringoptimize_indicesCreateIndexround trips that would silently drop aliasesBreaking change (Rust):
lance_table::format::IndexMetadatanow has a publiclocal_fragment_aliases: BTreeMap<u32, u32>field, so external Rust callers constructingIndexMetadatastruct literals directly will need to initialize it.