errose28 commented on code in PR #12218:
URL: https://github.com/apache/ozone/pull/12218#discussion_r4773717968
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java:
##########
@@ -2350,7 +2349,10 @@ public boolean doesPeerExist(String scmId) {
.getGroup().getPeer(RaftPeerId.valueOf(scmId)) != null;
}
- public void scmHAMetricsUpdate(String leaderId) {
+ /**
+ * @param leaderId the current SCM leader, or null if it is not known.
+ */
+ public synchronized void scmHAMetricsUpdate(String leaderId) {
Review Comment:
This could cause strange behavior. In the latest commit I switched to
`MetricUtil.getMetricsSourceName` to assign source names for the metrics, which
handles this problem.
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestStorageContainerManagerHA.java:
##########
@@ -170,14 +172,25 @@ public void testSCMLeadershipMetric() throws IOException,
InterruptedException {
assertEquals(0, failedSCMs.get());
// THEN expect only one SCM node (leader) will have
'scmha_metrics_scmha_leader_state' metric set to 1
- int leaderCount = 0;
- for (StorageContainerManager scm :
cluster.getStorageContainerManagersList()) {
- if (scm.getScmHAMetrics() != null &&
scm.getScmHAMetrics().getSCMHAMetricsInfoLeaderState() == 1) {
- leaderCount++;
- break;
- }
+ StorageContainerManager oldLeader = cluster.getScmLeader(true);
+ waitForOnlyLeaderMetric(oldLeader);
+
+ // WHEN leadership is transferred to another SCM
+ StorageContainerManager newLeader = inactiveSCMs.get(0);
+ try (StorageContainerLocationProtocolClientSideTranslatorPB scmClient =
+ cluster.getStorageContainerLocationClient()) {
+ scmClient.transferLeadership(newLeader.getScmId());
}
- assertEquals(1, leaderCount);
+ GenericTestUtils.waitFor(newLeader::checkLeader, 100, 30000);
+
+ // THEN the old leader's metric drops to 0 and only the new leader has it
set to 1
+ waitForOnlyLeaderMetric(newLeader);
+ }
+
+ private void waitForOnlyLeaderMetric(StorageContainerManager leader) throws
TimeoutException, InterruptedException {
+ GenericTestUtils.waitFor(() ->
cluster.getStorageContainerManagersList().stream()
+ .allMatch(scm -> scm.getScmHAMetrics() != null
+ && scm.getScmHAMetrics().getSCMHAMetricsInfoLeaderState() == (scm
== leader ? 1 : 0)), 100, 30000);
Review Comment:
The refactored `SCMHAMetrics` now always pulls leader state from
`SCMContext` which should resolve this issue.
--
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]