This is an automated email from the ASF dual-hosted git repository.

ivandika3 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new dff9474faf5 HDDS-17130. Wait for bootstrapped SCM readiness in mini 
cluster (#11621)
dff9474faf5 is described below

commit dff9474faf5e61793ce4be18ac294eb1c1adee38
Author: Andy Huang <[email protected]>
AuthorDate: Wed Oct 21 12:53:54 2026 +0800

    HDDS-17130. Wait for bootstrapped SCM readiness in mini cluster (#11621)
---
 .../hadoop/ozone/TestMiniOzoneHACluster.java       | 101 +++++++++++++++++++++
 .../hadoop/ozone/MiniOzoneHAClusterImpl.java       |  12 +--
 2 files changed, 107 insertions(+), 6 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMiniOzoneHACluster.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMiniOzoneHACluster.java
new file mode 100644
index 00000000000..cc43768201c
--- /dev/null
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMiniOzoneHACluster.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.net.BindException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
+import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl.SCMHAService;
+import org.apache.ratis.statemachine.SnapshotInfo;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.mockito.MockedStatic;
+
+/**
+ * Tests the SCM bootstrap readiness guarantees of the HA mini cluster.
+ */
+@Timeout(30)
+class TestMiniOzoneHACluster {
+
+  @TempDir
+  private Path testDir;
+
+  @ParameterizedTest
+  @CsvSource({"true, false", "false, false", "true, true", "false, true"})
+  void testBootstrapSCMWaitsForReadiness(boolean updateConfigs, boolean 
portConflict) throws Exception {
+    StorageContainerManager leader = mock(StorageContainerManager.class, 
RETURNS_DEEP_STUBS);
+    StorageContainerManager newSCM = mock(StorageContainerManager.class, 
RETURNS_DEEP_STUBS);
+    when(leader.getSCMNodeId()).thenReturn("scm1");
+    when(leader.getScmId()).thenReturn("leader-scm-id");
+    when(leader.checkLeader()).thenReturn(true);
+    
when(leader.getScmHAManager().getRatisServer().getSCMStateMachine().getLatestSnapshot().getIndex())
+        .thenReturn(10L);
+    when(newSCM.getSCMNodeId()).thenReturn("scm2");
+    when(newSCM.getScmId()).thenReturn("new-scm-id");
+    SnapshotInfo snapshot = 
newSCM.getScmHAManager().getRatisServer().getSCMStateMachine().getLatestSnapshot();
+    when(snapshot.getIndex()).thenReturn(9L, 10L);
+    when(leader.doesPeerExist(anyString())).thenReturn(true);
+    when(newSCM.doesPeerExist(anyString())).thenReturn(true);
+
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(ScmConfigKeys.OZONE_SCM_NAMES, "localhost:1234");
+    conf.set(ScmConfigKeys.OZONE_SCM_NODES_KEY + ".scm-service", "scm1");
+    SCMHAService scmService = new SCMHAService(new 
ArrayList<>(Collections.singletonList(leader)),
+        new ArrayList<>(), "scm-service");
+    MiniOzoneHAClusterImpl cluster = new MiniOzoneHAClusterImpl(conf, null, 
null, scmService,
+        Collections.emptyList(), testDir.toString(), Collections.emptyList());
+
+    try (MockedStatic<StorageContainerManager> scmFactory = 
mockStatic(StorageContainerManager.class)) {
+      if (portConflict) {
+        scmFactory.when(() -> 
StorageContainerManager.createSCM(any(OzoneConfiguration.class)))
+            .thenThrow(new BindException("Port already in 
use")).thenReturn(newSCM);
+      } else {
+        scmFactory.when(() -> 
StorageContainerManager.createSCM(any(OzoneConfiguration.class))).thenReturn(newSCM);
+      }
+
+      cluster.bootstrapSCM("scm2", updateConfigs);
+
+      verify(snapshot, times(2)).getIndex();
+      if (updateConfigs) {
+        verify(leader).doesPeerExist(newSCM.getScmId());
+        verify(newSCM).doesPeerExist(leader.getScmId());
+      } else {
+        verify(leader, never()).doesPeerExist(anyString());
+        verify(newSCM, never()).doesPeerExist(anyString());
+      }
+      scmFactory.verify(() -> 
StorageContainerManager.createSCM(any(OzoneConfiguration.class)),
+          times(portConflict ? 2 : 1));
+    }
+  }
+}
diff --git 
a/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
 
b/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
index 21ba4a74732..07f767c3879 100644
--- 
a/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
+++ 
b/hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
@@ -1131,11 +1131,11 @@ public void bootstrapSCM(String scmNodeId, boolean 
updateConfigs) throws Excepti
           throw e;
         }
       }
+    }
 
-      waitForBootstrappedNodeToBeReady(scm, leaderSnapshotIndex);
-      if (updateConfigs) {
-        waitForConfigUpdateOnActiveSCMs(scmNodeId);
-      }
+    waitForBootstrappedNodeToBeReady(scm, leaderSnapshotIndex);
+    if (updateConfigs) {
+      waitForConfigUpdateOnActiveSCMs(scmNodeId);
     }
   }
 
@@ -1181,10 +1181,10 @@ private void waitForConfigUpdateOnActiveSCMs(
       // Also, the new SCM should contain each existing active SCM in it's SCM
       // peer list and RatisServer peerList.
       for (StorageContainerManager scm : scmhaService.getActiveServices()) {
-        if (!scm.doesPeerExist(scm.getScmId())) {
+        if (!scm.doesPeerExist(newSCMNode.getScmId())) {
           return false;
         }
-        if (!newSCMNode.doesPeerExist(scm.getSCMNodeId())) {
+        if (!newSCMNode.doesPeerExist(scm.getScmId())) {
           return false;
         }
       }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to