sodonnel commented on PR #12218:
URL: https://github.com/apache/ozone/pull/12218#issuecomment-7345355838
I haven't went through this myself yet, but the Claude review suggests
@ArafatKhan2198 comments are mostly valid. It also suggests:
1. A simpler fix for the root cause. Register SCMHAMetrics once at startup,
and have getMetrics() work out the state when it runs, from
scm.getScmContext().isLeader() or the Ratis division's leader. Then the startup
race, the follower update and the step-down case all disappear, and no callback
needs to touch metrics. This goes further than comment 1, which still has the
callbacks updating a field. I'd suggest it as the main fix.
2. notifyNotLeader also fires during shutdown. I confirmed this in Ratis:
RaftServerImpl.close() calls shutdownLeaderState(true), which calls
LeaderStateImpl.stop(), which calls notifyNotLeader. So when a leader SCM
stops, the new scmHAMetricsUpdate(null) registers a fresh source and MBean.
SCM.stop() then unregisters it, because SCMHAMetrics.unRegister() (line 1751)
runs after scmHAManager.stop() (line 1745). Nothing leaks today, but it's
wasted work, and it only stays correct while that order holds. Fix 1 removes it.
3. The leader path has no unit test. The new tests cover only the follower
and step-down paths. Nothing checks that the restructured leader branch still
updates metrics, calls onBecomeLeader, or starts the datanode protocol server.
The ordering change above would not have failed any test.
4. Diff scope. The whole of notifyLeaderChanged was restructured and
rewrapped, against CLAUDE.md's "smallest correct change" and "don't rewrap
adjacent code" rules. The minimal fix for the follower case was one
scmHAMetricsUpdate(...) call before the early return. The real behaviour
change, the reorder, is buried in the reformatting, which is presumably why it
got through.
Suggested changes:
1. Register the metrics source once and compute leader state in
getMetrics(). This replaces the recreate-on-every-change approach, fixes the
cross-SCM race in the mini-cluster test (comment 2), and removes the shutdown
re-registration.
2. Put the leader-path order back: start the datanode protocol server before
onBecomeLeader. Better still, shrink the SCMStateMachine change to the minimum.
3. In the tests:
- Pick a transfer target other than oldLeader (comment 3).
- Read the gauge by calling getMetrics() on the object, not from the
cached holder (comment 4).
- Add a unit test for the leader path.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]