errose28 opened a new pull request, #12218:
URL: https://github.com/apache/ozone/pull/12218
## What changes were proposed in this pull request?
In a test cluster it was noticed that once an SCM is elected leader, the
node's `SCMHALeaderState` metric continues to report it as the leader even if
it becomes a follower. The metric is not corrected until the node is restarted.
A few issues were identified which can cause this.
### Issues
#### Metric update was skipped when SCM switches to a follower
- When SCM was notified of a new leader in
`SCMStateMachine#notifyLeaderChanged`,
`StorageContainerManager#scmHAMetricsUpdate` was never called if the node was a
follower.
- This method recreates the metrics object, which is required to update
the immutable `leaderId` field.
- To prevent similar issues, `SCMStateMachine#notifyLeaderChanged` was
rearranged to remove the early return and leave common logic for leaders and
followers in one place.
#### Metric was not updated when SCM leader steps down
- Even with the above change, a leader's metric would continue to report
itself as leader after stepping down and until the next election completed.
- The leader metric must also be updated in
`SCMStateMachine#notifyNotLeader` when the leader steps down.
#### Metrics initialization on startup could race with Ratis leader election
- The metrics object is initialized by
`StorageContainerManager#scmHAMetricsUpdate` both on SCM startup and Ratis
callbacks
- The `SCMStateMachine#notifyLeaderChanged` callback could be invoked any
time after starting the ratis server. It could populate correct leader
information, just for the init by `StorageContainerManager#start` to overwrite
it with stale information
- This was fixed to initialize the metric with no leader before starting the
Ratis server, and letting Ratis populate leader information once it starts.
## What is the link to the Apache JIRA
HDDS-17968
## How was this patch tested?
- Unit tests for metrics updates in `SCMStateMachine#notifyLeaderChanged`
and `SCMStateMachine#notifyNotLeader` added.
- Existing integration test of leadership metrics was updated to include a
leader transfer while all SCMs remain running and verify the metrics after this.
- Other cases like the Ratis leader election racing SCM startup and metrics
state in-between elections were not given explicit tests due to timing
difficulties.
--
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]