Skip to content

[FLINK-41564][pipeline-connector/fluss] Balance source split assignment across partitions - #4629

Open
loserwang1024 wants to merge 3 commits into
apache:masterfrom
loserwang1024:poc-fluss-split-assign
Open

loserwang1024 wants to merge 3 commits into
apache:masterfrom
loserwang1024:poc-fluss-split-assign

Conversation

@loserwang1024

Copy link
Copy Markdown
Contributor

…

What is the purpose of this pull request?

Briefly describe the problem this PR fixes or the feature it introduces. Reference Flink JIRA ticket when possible.

Brief change log

List the key changes in this PR.


Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change added tests and can be verified as follows:

  • Added/Updated unit tests in ...*
  • Added/Updated integration tests in ...*
  • Manually tested by ...

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

@fxbing fxbing 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.

LGTM

@loserwang1024

Copy link
Copy Markdown
Contributor Author

@leonardBang , WDYT?

}
for (int reader = 0; reader < parallelism; reader++) {
Set<TableBucket> buckets =
new HashSet<>(readerBuckets.getOrDefault(reader, Collections.emptySet()));

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.

Would it make sense to defer owner selection until all reader reports are available?

During a partial recovery, an already scheduled split initialization could complete after addReader() has removed the restarting reader's bucket view but before its ReaderSplitReportEvent is handled. This fallback then treats that reader as having no existing load. handleTableBucketChanges() groups the new splits by owner before assignPendingPartitionSplits() checks allReadersReported(), so waiting for the report only delays delivery; the preselected owners are not recomputed.

I reproduced this interleaving in an enumerator test: with two readers initially owning eight one-bucket partitions each and four new one-bucket partitions, the final distribution is 12:8 rather than 10:10. Deferring owner selection until the restored-split report arrives makes the same test pass.

Could we keep these initialized splits without selecting owners until the reports arrive, while preserving their initialized offsets? It may also be helpful to add a regression test covering initialization completion between re-registration and the restored-split report.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@leonardBang Thanks for catching this interleaving. I've pushed the fix in 1ca062f and clarified the Javadoc in e8d8ad0.

The change distinguishes initial ownership reconstruction from a local reader restart:

  • On startup or enumerator recovery, owner selection waits for every reader's initial report and the first discovery to prune inactive buckets. Initialized and coordinator-restored pending splits stay in unassignedPendingSplits with their existing offsets. pendingPartitionSplitAssignment holds splits with selected owners awaiting delivery.
  • During a local restart, readerBuckets retains the enumerator's logical ownership view. addReader() no longer clears it, and later reports from known readers do not overwrite it, since a checkpoint-restored report can omit more recent assignments. addSplitsBack() still returns splits to their original owners. Assignment requires all readers to be registered, but does not require another report from a restarting reader whose ownership is already known.
  • The new regression test covers initialization completing both before re-registration and between re-registration and the restored-split report. Starting from 8:8 with four new one-bucket partitions produces 10:10. It also checks offset preservation without reinitialization, and verifies that a late report does not skew subsequent assignments (two more partitions produce 11:11).

Focused enumerator and state serializer tests passed on Flink 1.20.3 / Java 11 (19 tests) and Flink 2.2.0 / Java 17 (28 tests).

Hongshun Wang added 3 commits November 27, 2026 17:16
…oss reader restarts

Retain logical bucket ownership across local reader restarts and defer owner
selection until the initial distribution is known. Preserve initialized
offsets and cover initialization around reader re-registration in tests.

Generated-by: Codex CLI 0.167.2
AI-Model: gpt-6
AI-Contributed/Feature: 81/81
AI-Contributed/UT: 110/110
Clarify logical bucket ownership, pending split states, and recovery
contracts while removing repeated implementation details.

Generated-by: Codex CLI 0.167.2
AI-Model: gpt-6
AI-Contributed/Feature: 94/94
AI-Contributed/UT: 0/0

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants