Skip to content

[core] Wire sorted primary-key indexes into writes#8602

Merged
JingsongLi merged 1 commit into
apache:masterfrom
JingsongLi:codex/pk-sorted-index-write-integration
Jul 13, 2026
Merged

[core] Wire sorted primary-key indexes into writes#8602
JingsongLi merged 1 commit into
apache:masterfrom
JingsongLi:codex/pk-sorted-index-write-integration

Conversation

@JingsongLi

@JingsongLi JingsongLi commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Purpose

Wire source-backed BTree and Bitmap indexes into the primary-key table write lifecycle.

Changes

  • Create a unified bucket-local coordinator for vector, BTree, and Bitmap primary-key index definitions.
  • Restore source-backed payloads and construct sorted-index builders from the table schema, bucket path, reader factory, and shared IOManager.
  • Filter restored payloads by indexType and field ID at each maintainer boundary, so scalar payloads never enter vector state.
  • Stage all definition results and publish caller increments only after every definition succeeds; abort prepared vector/scalar commits in reverse order and clean generated payloads when a later definition fails or is interrupted.
  • Run multiple scalar index definitions sequentially while allowing a failed definition to remain uncovered without suppressing other definitions.
  • Publish index additions and deletions through the append or compact increment that owns the corresponding source-file transition.
  • Enable the file-store writer whenever BTree or Bitmap primary-key index columns are configured.
  • Keep source-backed payloads out of the ordinary global row-id scanner and coverage calculation, so both index models can coexist safely.
  • Keep Postpone Bucket writes unindexed in bucket -2; the fixed-bucket runtime view used by background compaction creates and publishes the coordinator.
  • Cover mixed Vector+BTree+Bitmap write/restore, coordinator interruption rollback/retry, and non-blocking scalar scheduling without the prior latch race.

Impact

Compacted primary-key table files now automatically receive configured BTree and Bitmap payloads. Read-side source pruning remains intentionally deferred to a follow-up PR.

Validation

  • mvn -pl paimon-codegen-loader -am -Pfast-build -DskipTests package
  • mvn -pl paimon-core -am -Pfast-build -DfailIfNoTests=false -DwildcardSuites=none -Dtest=BucketedVectorIndexMaintainerTest,PkVectorBucketIndexStateTest,BucketedSortedIndexMaintainerTest,BucketedPrimaryKeyIndexMaintainerTest,PrimaryKeySortedIndexMaintenanceTest,PrimaryKeyIndexWriteTest,PrimaryKeyVectorIndexWriteTest,BtreeGlobalIndexTableTest test (46 tests)
  • mvn -pl paimon-core -DskipTests validate

@JingsongLi JingsongLi marked this pull request as ready for review July 13, 2026 13:26

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found two blocking correctness issues in the mixed/multi-index write lifecycle, plus a reproducible failure in the new concurrency test.

vectorFactory == null
? null
: vectorFactory.create(
partition, bucket, dataFiles, payloads, executor);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

restoredPayloads is the full result of scanSourceIndexes, so it contains the payloads for every configured source-backed definition. Passing that unfiltered list into the vector factory makes PkVectorBucketIndexState validate BTree/Bitmap payloads as vector segments and throw Vector payload ... has a different index type. A table configured with both a vector index and a scalar index therefore cannot restore a bucket writer after scalar payloads have been committed. Please filter the restored payloads by the vector field/index type before creating the vector maintainer, and add a mixed vector + scalar write/restore test.

}

if (waitCompaction) {
prepareSortedBlocking(appendIncrement, compactIncrement);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The coordinator publishes each maintainer's state and merges its files into the caller increments before later maintainers have succeeded, but there is no coordinator-level rollback. If an earlier vector/scalar definition completes and a later blocking scalar prepareCommit is interrupted, the overall call throws while the earlier definition remains covered and its generated payload remains in the increment. Retrying or discarding that failed prepare can then omit the payload or leave it orphaned. Individual maintainers only roll back their own invocation. Please make this operation atomic across all definitions (or defer publication until all definitions succeed) and cover an interruption after the first of two scalar definitions completes.

assertThat(firstCompleted.await(5, TimeUnit.SECONDS)).isTrue();
maintainer.prepareCommit(
DataIncrement.emptyIncrement(), CompactIncrement.emptyIncrement(), false);
assertThat(secondStarted.await(5, TimeUnit.SECONDS)).isTrue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test is racy and fails consistently on my machine. firstCompleted is counted down inside the callable immediately before it returns, so the following non-blocking prepareCommit may still observe Future.isDone() == false and return without starting the second definition; the await here then times out. Please wait/poll until the first future is actually consumed (for example, retry non-blocking prepare until the second build starts) instead of treating the in-callable latch as future completion.

@JingsongLi JingsongLi force-pushed the codex/pk-sorted-index-write-integration branch from b4dd08a to 4520ae2 Compare July 13, 2026 13:50
@JingsongLi JingsongLi force-pushed the codex/pk-sorted-index-write-integration branch from 4520ae2 to ca917ff Compare July 13, 2026 14:07

@leaves12138 leaves12138 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the updated head. The mixed vector/scalar restore filtering, coordinator-wide rollback, and scalar build concurrency regression are addressed. The focused core test suite and repeated concurrency test pass locally.

@JingsongLi JingsongLi merged commit 4dddb86 into apache:master Jul 13, 2026
11 of 12 checks passed
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