yraivo opened a new pull request, #11551: URL: https://github.com/apache/rocketmq/pull/11551
### Which Issue(s) This PR Fixes - Fixes #11045 ### Brief Description Fixes stale channel-close broker eviction in `DefaultBrokerHeartbeatManager` (#11045), including the two concurrency review items noted by @RongtongJin on closed PR #11046 ([#discussion_r4227688656](https://github.com/apache/rocketmq/pull/11046#discussion_r4227688656), [#discussion_r4227688667](https://github.com/apache/rocketmq/pull/11046#discussion_r4227688667)): 1. **Atomic channel rebinding and conditional close eviction**: `onBrokerHeartbeat` updates/rebinds `BrokerLiveInfo` inside `brokerLiveTable.compute`, and `onBrokerChannelClose` removes entries via `computeIfPresent` only while `live.getChannel() == channel` (ignoring `null` channels and capturing removed fields before submitting `notifyBrokerInActive`). 2. **Atomic expiry recheck and shared-channel safety in `scanNotActiveBroker`**: rechecks `lastUpdateTimestamp` and `heartbeatTimeoutMillis` inside `computeIfPresent`, and coordinates channel closing with concurrent heartbeats via `channelLifecycleLock` (`ReadWriteLock`) plus `closingChannels` so an expired entry only closes its channel when no other live broker entry shares or concurrently rebinds onto that channel (e.g. `BrokerContainer` sharing `BrokerOuterAPI`). 3. **Closed-channel rejection and publish-window cleanup**: `onBrokerHeartbeat` rejects heartbeats from inactive or expiry-closing channels inside `compute`, and rechecks right after `compute` to conditionally evict the same `(identity, channel)` if the channel closed before a newly created entry became visible to `onBrokerChannelClose` (without affecting any replacement channel that already took over). Overlapping active connections follow latest-processed-active-heartbeat takeover (`brokerEpoch` tracks master election rather than connection generation), `channel == null` registration/timeout behavior is preserved, and mutable `BrokerLiveInfo` fields are marked `volatile` for lock-free readers. ### How Did You Test This Change? Added deterministic interleaving tests (plus a 500-round concurrent stress test) in `DefaultBrokerHeartbeatManagerTest` and verified with JDK 8 (`1.8.0_514`): - Reconnect `oldChannel -> newChannel` followed by stale `oldChannel` close, current-channel close positive control, overlapping active connections under the same `brokerEpoch`, `null`-channel non-eviction, and the 500-round close/rebind stress test. - Expiry scan paused after reading an expired `lastUpdateTimestamp` while `newChannel` rebinds, two broker identities sharing an `EmbeddedChannel` (steady-state sharing, sibling broker rebinding during `scanNotActiveBroker`, delayed in-flight close, and failed close recovery), and exclusive-channel expiry positive control. - Late queued `RequestTask` from a closed `EmbeddedChannel` through `ControllerRequestProcessor` and `BrokerHousekeepingService`, and first-heartbeat publish-window close interleaved with `onBrokerChannelClose` and replacement channel takeover. - `mvn -B -ntp -pl controller -Dtest=DefaultBrokerHeartbeatManagerTest,ReplicasInfoManagerTest,ControllerRequestProcessorTest,DefaultElectPolicyTest,BrokerIdentityInfoTest,EventSerializerTest,ListEventSerializerTest,ControllerManagerTest test` (`46/46` tests in those 8 suites pass, Checkstyle and SpotBugs clean). -- 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]
