Skip to content

fix(index): reuse primary-key index groups with retired source files - #253

Open
wangyong9999 wants to merge 3 commits into
apache:mainfrom
wangyong9999:fix/pk-index-partially-active-source-groups
Open

fix(index): reuse primary-key index groups with retired source files#253
wangyong9999 wants to merge 3 commits into
apache:mainfrom
wangyong9999:fix/pk-index-partially-active-source-groups

Conversation

@wangyong9999

@wangyong9999 wangyong9999 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #252

A source-backed primary-key index payload uses one immutable ordered source list as its ordinal namespace. After an update retires only part of that list, the current reader requires the payload to equal the complete active source set of its data level. It rejects the still-valid payload and degrades every surviving indexed file to an ordinary scan.

The same lifecycle issue is tracked for Java and Python in apache/paimon#9458, with the aligned fix in apache/paimon#9460.

Key code and data-flow changes

  • Keep the payload's complete source list for group-ordinal localization, but compute coverage from its intersection with eligible active files at source_meta.DataLevel().
  • Preserve the existing one-group-per-level invariant. Multiple valid payload candidates for one level are rejected and fall back to an ordinary scan.
  • Map an accepted group only to files allowed by PrimaryKeyIndexSourcePolicy::ShouldRead, using data level + file name + row count as the scan-side source identity.
  • Preserve retired prefix or middle source offsets and deletion files when converting surviving files to IndexedSplit.
  • Leave uncovered, newly written, or cross-level files on the existing ordinary-scan path.

This restores index reuse for surviving compact files without introducing a new writer lifecycle or allowing an uncovered file to depend on stale index metadata.

Error and compatibility boundaries

  • Source names remain canonically ordered; an active source must match the payload's recorded row count.
  • A payload with no active source at its metadata-declared level is rejected. A file with the same name and row count at another level cannot inherit the group.
  • Invalid field/type metadata, row range, source metadata, or multiple candidates at one level fail closed to the existing ordinary scan.
  • No public include API, storage format, index protocol, write path, or concurrency behavior changes.

Tests

  • Current x86_64 GCC 8 internal branch: focused PkSortedBucketIndexStateTest.*:PrimaryKeySortedIndexScanTest.* — 37/37 passed.
  • Current x86_64 GCC 8 internal branch: full core_test — 1,747 passed, 100 skipped, 0 failed (1,847 total).
  • Follow-up DataLevel binding regression set — 3/3 passed: cross-level source fallback, retired-source ordinal preservation, and wrong-level payload rejection.
  • Added/retained coverage for partial active intersection, one group per level, metadata level mismatch, retired prefix/middle ordinal offsets, row-count mismatch, a mixed update with deletion-vector preservation, a non-eligible APPEND source, and cross-level source movement.
  • clang-format dry-run and git diff --check pass.

API and Format

No public include API, storage format, or index protocol changes. The change only broadens safe read-side reuse of one existing source-backed payload per level.

Documentation

Updated the primary-key global-index user guide to describe immutable source groups, partial active coverage, the one-group-per-level boundary, declared-level validation, and fallback behavior.

Generative AI tooling

Generated-by: OpenAI Codex (GPT-5)

Comment thread src/paimon/core/index/pksorted/pk_sorted_bucket_index_state.cpp Outdated
@lxy-9602

Copy link
Copy Markdown
Member

The current changes seem reasonable to me. That said, to avoid PkSortedBucketIndexState in C++ gradually diverging too much from the Java implementation and becoming harder to align later — for example, if additional features or refactors are introduced on the Java side in the future — I’d suggest merging this logic into paimon-java first, and then bringing it into C++.

Comment thread src/paimon/core/index/pksorted/pk_sorted_bucket_index_state.cpp Outdated
wangyong.alen added 2 commits August 28, 2026 21:28
Keep the full immutable source metadata for ordinal localization while covering only eligible sources present in the current scan. Reject conflicting or mismatched active intersections and leave uncovered files on the normal scan path.
@wangyong9999
wangyong9999 force-pushed the fix/pk-index-partially-active-source-groups branch from cc1ea0d to 9a1f257 Compare August 29, 2026 01:28
@wangyong9999

Copy link
Copy Markdown
Contributor Author

Thanks. I narrowed the revision to preserve the existing one-group-per-level lifecycle and added strict source_meta.DataLevel() validation; it does not add a writer/protocol state or a C++-only multi-group model. The remaining change fixes C++ read-side validation of an already-written immutable source group after partial retirement. Because no Java behavior or persisted format changes, could this narrow reader correction proceed independently while keeping the Java/C++ lifecycle aligned?

@wangyong9999

Copy link
Copy Markdown
Contributor Author

I checked the current Paimon Java and Python readers and confirmed the same exact-active-set rejection there. I filed apache/paimon#9458 and opened the aligned Java/Python fix in apache/paimon#9460. This C++ branch now also binds scan-side source matching to the group's data level, with a regression test for a source moving to another level.

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.

[Bug] Primary-key sorted index falls back after partial source retirement

2 participants