Skip to content

[server] Fix thread-safety bug in RebalanceManager ZooKeeper recovery path - #4232

Open
fhan688 wants to merge 2 commits into
apache:mainfrom
fhan688:Fix-thread-safety-bug-in-RebalanceManager-ZooKeeper-recovery-path
Open

[server] Fix thread-safety bug in RebalanceManager ZooKeeper recovery path#4232
fhan688 wants to merge 2 commits into
apache:mainfrom
fhan688:Fix-thread-safety-bug-in-RebalanceManager-ZooKeeper-recovery-path

Conversation

@fhan688

@fhan688 fhan688 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Purpose

RebalanceManager.initialize() is invoked on the startup thread but currently calls registerRebalance() directly, which mutates non-thread-safe state owned by the coordinator event thread. This violates the single-threaded execution contract and opens a race window during coordinator HA failover or restart.

Brief change log

  • Add RecoverRebalanceEvent, a new coordinator event that carries the RebalanceTask read from ZooKeeper during startup recovery.
  • Change RebalanceManager.initialize() to enqueue a RecoverRebalanceEvent via eventManager.put(...) instead of directly calling registerRebalance().
  • Handle RecoverRebalanceEvent in CoordinatorEventProcessor to delegate registerRebalance() onto the coordinator event thread.
  • Add testStartupQueuesRecoverRebalanceEvent, which verifies that startup() enqueues the recovery event rather than executing the rebalance inline.

Tests

  • org.apache.fluss.server.coordinator.rebalance.RebalanceManagerTest#testStartupQueuesRecoverRebalanceEvent — verifies the recovery event is enqueued instead of registerRebalance being called inline.
  • Existing RebalanceManagerTest suite (5 tests) — all pass, no regressions.

API and Format

No.

Documentation

No.

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.

1 participant