wuchong commented on PR #2781: URL: https://github.com/apache/fluss/pull/2781#issuecomment-4212545286
This commit fixes a **race condition in leader election** and **refactors coordinator epoch to be immutable**. ### Key Changes - **`CoordinatorLeaderElection`**: Moved `isLeader.set(true)` from **before** to **after** `initLeaderServices.run()`, preventing the coordinator from accepting requests before initialization completes. Removed unnecessary `zkClient` and `coordinatorContext` fields. - **`CoordinatorContext`**: Made `coordinatorEpoch` and `coordinatorEpochZkVersion` **final** fields initialized via `ZkEpoch` in the constructor. Removed the mutable setter. Renamed `getCoordinatorEpochZkVersion()` → `getCoordinatorZkVersion()`. - **`CoordinatorServer`**: `CoordinatorContext` is now created **locally** in `initCoordinatorLeader()` per election cycle instead of being a long-lived server field. Removed redundant `resetContext()` calls from cleanup/close paths. - **`CoordinatorEventProcessor`**: Removed `ZkEpoch` constructor parameter (epoch now comes via `CoordinatorContext`). Added `resetContext()` in `close()`. - **`ReplicaManager`**: Added `getCoordinatorEpoch()` getter and epoch update logging; removed `resetCoordinatorEpoch()`. - **`ZkEpoch`**: Added `INITIAL_EPOCH` constant for test convenience. - **`ZooKeeperClient`**: Fixed Javadoc formatting (inline text → `<pre>` and `<ul>` blocks). - **Tests**: Deleted `TestCoordinatorContext`; updated HA tests to `waitUntil` leader is ready (since `isLeader` is now set after init); replaced manual `UpdateMetadataRequest` workaround with natural epoch propagation wait. - **ITCase**: Updated `CoordinatorHighAvailabilityITCase#testTabletServerRejectsStaleCoordinatorEpochAfterLeaderSwitch` to update the coordinator epoch of TabletServer by coordinator itself, rather than manually update it in IT case. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
