Skip to content

[ISSUE #11045] Rebind broker channel atomically on heartbeat and guard expiry scan and closed-channel heartbeats - #11551

Open
yraivo wants to merge 1 commit into
apache:developfrom
yraivo:pr-11045-controller-heartbeat-rebind
Open

yraivo wants to merge 1 commit into
apache:developfrom
yraivo:pr-11045-controller-heartbeat-rebind

Conversation

@yraivo

@yraivo yraivo commented Nov 22, 2026

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

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, #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).

…d guard expiry scan and closed-channel heartbeats
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.69027% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.92%. Comparing base (28960fd) to head (9d7523d).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
.../impl/heartbeat/DefaultBrokerHeartbeatManager.java 94.69% 0 Missing and 6 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #11551      +/-   ##
=============================================
+ Coverage      49.86%   49.92%   +0.06%     
- Complexity     14454    14487      +33     
=============================================
  Files           1391     1391              
  Lines         103432   103510      +78     
  Branches       13550    13561      +11     
=============================================
+ Hits           51573    51677     +104     
+ Misses         45636    45594      -42     
- Partials        6223     6239      +16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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] Controller: a stale channel-close event evicts a re-registered broker and triggers a spurious master election

2 participants