Repository navigation
[spark][vector] Support appending shards to centroid indexes - #11712
Conversation
leaves12138
left a comment
There was a problem hiding this comment.
Reviewed base master at head 71b51ec0ff3cfaf39fa77f9e7f9ded8736182f51 (+1511/-355, 32 files): docs (centroid-vector.mdx, procedures), common CentroidIndexFile / CentroidShardFilterReader / CentroidVectorGlobalIndexer, core CentroidIndexMeta / DataEvolutionGlobalIndexRefreshPlanner / DataEvolutionConflictDetection / CentroidBitmapFilter / AbstractDataEvolutionVectorRead / GlobalIndexQuery / GlobalIndexVisibilityChecker, Python manifest grouping and source check, Spark add_global_index_shards procedure + CentroidGlobalIndexTopoBuilder / CentroidBitmapFieldAppender, vector NativeCentroidRoutedIndexReader / NativeCentroidVectorGlobalIndexer, tests and updated Rust interop warehouse zips.
Core change notice: this PR carries substantial generic core changes, not just Spark wiring:
CentroidIndexMeta: the v1 descriptor header grows from 14 to 30 bytes (rowIdOffset int64 + rowRangeSize int64), so shard/Bitmap files now declare explicit batch geometry inside a shared manifest range. This is a breaking descriptor change; per the PR description v1 is not yet released, and the interop warehouse zips are regenerated accordingly. The matching paimon-rust reader/writer update for the 30-byte header is declared open compatibility work, and staged Java abort cleanup plus mixed-schema Bitmap fallback are declared follow-ups. Cross-engine consumers must land the companion change before reading tables written by this version.DataEvolutionGlobalIndexRefreshPlanner: staleness is now evaluated per batch via the descriptor file range instead of the whole manifest range; any stale batch replaces the whole centroid group, and the router only covers the exclude(populated) span with its own baseline. This keeps null spans and reused files on their original scan snapshots.DataEvolutionConflictDetection.checkCentroidSourceChanges: DELETE routers record removed range ends; an ADD router whose range extends a removed one (previousEnd < newEnd) validates againstrowIdCheckFromSnapshotinstead of the original router scan snapshot, while pure rebuilds keep the strict original baseline. The Spark test proves an UPDATE inside the newly appended span is still rejected with "Centroid index source rows changed".CentroidBitmapFilterandCentroidBitmapFieldAppender: Bitmap validation and appends are batched by rowIdOffset, each batch checks its own vectorCount/schemaId/field coverage; mixed-schema batches fall back rather than fail.- Common interfaces:
CentroidShardFilterReader.withShardFilterstays as a default bridge to the newwithShardFileFilter, andCentroidVectorGlobalIndexergainsreadRoutingModel/forRoutingModel. The shard filter is now keyed by file, not centroid id, which is required once a centroid owns multiple batch files. - Python
centroid_index_groups.pymirrors the 30-byte header and per-batch validation (sorted non-overlapping batches within range, per-batch Bitmap coverage and schema consistency, router source snapshot as the group floor), keeping Java/Python manifest contracts aligned.
Analysis of the append path:
appendShardspicks the floor centroid group as template only whenrowRangeEnd == source.from - 1(strict adjacency); non-adjacent unindexed spans become independent groups, verified by the two-range test. IGNORE update policy with non-empty extras is rejected up front, which is the right guard since Bitmap appends cannot replay updated rows.- Router reuse:
readRoutingModel+forRoutingModelbind metric from router metadata and dimension from the native header, skipping training when a payload exists; retained files keep their descriptors viaextendRange(range start unchanged, so file-relative offsets stay valid), and a rewritten router inherits the old sourceMeta so the original null-span baseline survives. The all-null-then-first-vectors test covers training a fresh router over the full extended range. NativeCentroidRoutedIndexReader: shards become per-centroid lists keyed by (centroid, rowIdOffset);SearchFilterscaches oneBatchFilterper (offset, size) on the coordinator, solocalRowIdstranslation and Bitmap serialization happen once per batch, not per shard. The dedicated test asserts clips == 1 and serializations == 1 across two centroids in one batch.ShardTopK.addrestores global ids withMath.addExact(localRowId, offset), and the joint-layout probe requires a single file per centroid, which correctly disables the fused path for multi-batch centroids.localRowIdsreturns the include set unchanged only when offset == 0 and the last id fits the batch, otherwise it translates via the relative range; empty batches short-circuit before opening shard readers.
Test coverage is strong: Spark SQL tests for adjacent extension without rewriting files (byte-identical retained files), stale staged-commit rejection, repeated no-op appends, schema evolution + Bitmap field append + DELETE visibility, scan-snapshot preservation across range refresh, all-null router training; Java tests for descriptor round-trip/extension, per-batch filter reuse, and Rust interop with the 30-byte header; Python tests for duplicated per-batch field ids under a shared range.
No findings.
CI: 47 checks pass (all Python/native/interop/licensing), 8 Java suites still pending. Author ran Spark 3 centroid SQL tests with strict Kryo, Java manifest/planner/conflict/query tests, and Python commit tests locally. Approving without waiting for the remaining CI, as requested.
LGTM.
Purpose
Add
sys.add_global_index_shardsfor Centroid vector indexes on Data Evolution tables. An adjacent append reuses the router and existing index files, builds vector and scalar Bitmap files for the new rows, and commits the complete coverage range atomically. File-local row offsets preserve the mapping from each batch to that range. The unreleased v1 descriptor uses a single 30-byte header with explicit batch geometry for shards and Bitmaps.Reused files keep their original scan snapshots. Refresh checks use each file's source range and replace the complete Centroid group when it becomes stale. Vector searches also reuse each batch's translated row-ID filter across centroid files and probe rounds.
Tests
Open compatibility work
Cross-engine interoperability needs a matching update to Rust centroid readers, writers, and manifest validation for the 30-byte v1 descriptor. The staged Java abort cleanup and the mixed-schema Bitmap fallback are separate review follow-ups.