unbridled-41 commented on PR #11046:
URL: https://github.com/apache/rocketmq/pull/11046#issuecomment-5970066740

   Made atomic in 4f46a0708, following the shape you suggested:
   
   - `onBrokerHeartbeat` now performs the whole create/update/rebind through 
`brokerLiveTable.compute(...)`, so an entry is never observed half-updated.
   - `onBrokerChannelClose` walks the identities and calls 
`computeIfPresent(...)`, returning `null` only while the live entry still 
carries the closing channel; a heartbeat that rebound the identity first makes 
the stale close a no-op. The inactive notification is submitted with the values 
captured at removal (`closed.getBrokerName()`, `closed.getBrokerId()`), not by 
closing over the mutable entry.
   
   **Coordinated concurrency test.** 
`testConcurrentHeartbeatDuringStaleChannelCloseKeepsBrokerAlive` runs 500 
rounds: each round starts with the broker live on the old channel, releases the 
stale close and the rebinding heartbeat from a common latch, then requires the 
entry to still exist and carry the new channel. Before the change it fails on 
the very first round:
   
   ```
   round 1: the live entry must survive the stale close
   ```
   
   After: `mvn -pl controller -Dtest=DefaultBrokerHeartbeatManagerTest test` → 
`Tests run: 3, Failures: 0, Errors: 0, Skipped: 0`.
   
   One note: pausing the close deterministically after its match would need a 
test-only hook in production code, so I used the coordinated race instead — 
happy to add the hook if you would rather have the deterministic interleaving.


-- 
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]

Reply via email to