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

sammichen 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 b862a50325 HDDS-5560. Update clusterId to correct value. (#5289)
b862a50325 is described below

commit b862a50325ec1c53096b81a1e3415f9cc1670f22
Author: ashishkumar50 <[email protected]>
AuthorDate: Thu Sep 21 13:14:15 2023 +0530

    HDDS-5560. Update clusterId to correct value. (#5289)
---
 .../container/common/DatanodeLayoutStorage.java    | 11 +++
 .../states/endpoint/VersionEndpointTask.java       |  5 ++
 .../container/common/TestDatanodeStateMachine.java |  6 ++
 .../ozone/container/common/TestEndPoint.java       | 89 +++++++++++++++-------
 4 files changed, 83 insertions(+), 28 deletions(-)

diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/DatanodeLayoutStorage.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/DatanodeLayoutStorage.java
index f3dbe23a72..ca45ec6a8c 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/DatanodeLayoutStorage.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/DatanodeLayoutStorage.java
@@ -54,6 +54,12 @@ public class DatanodeLayoutStorage extends Storage {
         DATANODE_LAYOUT_VERSION_DIR, dataNodeId, layoutVersion);
   }
 
+  public DatanodeLayoutStorage(ConfigurationSource conf)
+      throws IOException {
+    super(NodeType.DATANODE, ServerUtils.getOzoneMetaDirPath(conf),
+        DATANODE_LAYOUT_VERSION_DIR, getDefaultLayoutVersion(conf));
+  }
+
   @Override
   public File getCurrentDir() {
     return new File(getStorageDir());
@@ -64,6 +70,11 @@ public class DatanodeLayoutStorage extends Storage {
     return new Properties();
   }
 
+  @Override
+  public void setClusterId(String clusterId) throws IOException {
+    super.getStorageInfo().setClusterId(clusterId);
+  }
+
   /**
    * Older versions of the code did not write a VERSION file to disk for the
    * datanode. Therefore, When a datanode starts up and does not find a 
metadata
diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/VersionEndpointTask.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/VersionEndpointTask.java
index f9b0d882f0..89ba03b08e 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/VersionEndpointTask.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/states/endpoint/VersionEndpointTask.java
@@ -22,6 +22,7 @@ import java.util.concurrent.Callable;
 import org.apache.hadoop.hdds.conf.ConfigurationSource;
 import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMVersionResponseProto;
 import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.ozone.container.common.DatanodeLayoutStorage;
 import 
org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine;
 import org.apache.hadoop.ozone.container.common.utils.StorageVolumeUtil;
 import org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet;
@@ -75,6 +76,10 @@ public class VersionEndpointTask implements
           // If end point is passive, datanode does not need to check volumes.
           String scmId = response.getValue(OzoneConsts.SCM_ID);
           String clusterId = response.getValue(OzoneConsts.CLUSTER_ID);
+          DatanodeLayoutStorage layoutStorage
+              = new DatanodeLayoutStorage(configuration);
+          layoutStorage.setClusterId(clusterId);
+          layoutStorage.persistCurrentState();
 
           Preconditions.checkNotNull(scmId,
               "Reply from SCM: scmId cannot be null");
diff --git 
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java
 
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java
index 97903fb13b..630308be22 100644
--- 
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java
+++ 
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.hdds.HddsConfigKeys;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.protocol.DatanodeDetails;
 import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature;
 import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.ozone.OzoneConfigKeys;
 import org.apache.hadoop.ozone.OzoneConsts;
@@ -251,6 +252,11 @@ public class TestDatanodeStateMachine {
       task = stateMachine.getContext().getTask();
       Assertions.assertEquals(RunningDatanodeState.class, task.getClass());
 
+      DatanodeLayoutStorage layoutStorage = new DatanodeLayoutStorage(conf,
+          UUID.randomUUID().toString(),
+          HDDSLayoutFeature.DATANODE_SCHEMA_V3.layoutVersion());
+      layoutStorage.initialize();
+
       // This execute will invoke getVersion calls against all SCM endpoints
       // that we know of.
 
diff --git 
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/container/common/TestEndPoint.java
 
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/container/common/TestEndPoint.java
index 2d40423f01..24e94b54ea 100644
--- 
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/container/common/TestEndPoint.java
+++ 
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/ozone/container/common/TestEndPoint.java
@@ -44,6 +44,7 @@ import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolPro
 import org.apache.hadoop.hdds.scm.HddsTestUtils;
 import org.apache.hadoop.hdds.scm.VersionInfo;
 import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
+import org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature;
 import org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager;
 import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.ozone.OzoneConfigKeys;
@@ -78,6 +79,7 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 import org.mockito.Mockito;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -90,6 +92,9 @@ public class TestEndPoint {
   private static ScmTestMock scmServerImpl;
   @TempDir
   private static File testDir;
+  private static OzoneConfiguration ozoneConf;
+  private static DatanodeLayoutStorage layoutStorage;
+  private static DatanodeDetails dnDetails;
 
   @AfterAll
   public static void tearDown() throws Exception {
@@ -101,8 +106,14 @@ public class TestEndPoint {
   @BeforeAll
   static void setUp() throws Exception {
     serverAddress = SCMTestUtils.getReuseableAddress();
+    ozoneConf = SCMTestUtils.getConf();
     scmServerImpl = new ScmTestMock();
-    scmServer = SCMTestUtils.startScmRpcServer(SCMTestUtils.getConf(),
+    dnDetails = randomDatanodeDetails();
+    layoutStorage = new DatanodeLayoutStorage(ozoneConf,
+        UUID.randomUUID().toString(),
+        HDDSLayoutFeature.DATANODE_SCHEMA_V3.layoutVersion());
+    layoutStorage.initialize();
+    scmServer = SCMTestUtils.startScmRpcServer(ozoneConf,
         scmServerImpl, serverAddress, 10);
   }
 
@@ -131,20 +142,19 @@ public class TestEndPoint {
    */
   @Test
   public void testGetVersionTask() throws Exception {
-    OzoneConfiguration conf = SCMTestUtils.getConf();
-    conf.setFromObject(new ReplicationConfig().setPort(0));
-    try (EndpointStateMachine rpcEndPoint = createEndpoint(conf,
+    ozoneConf.setFromObject(new ReplicationConfig().setPort(0));
+    try (EndpointStateMachine rpcEndPoint = createEndpoint(ozoneConf,
         serverAddress, 1000)) {
-      DatanodeDetails datanodeDetails = randomDatanodeDetails();
-      conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_DATASTREAM_ENABLED,
+      ozoneConf.setBoolean(
+          OzoneConfigKeys.DFS_CONTAINER_RATIS_DATASTREAM_ENABLED,
           true);
-      conf.setBoolean(
+      ozoneConf.setBoolean(
           OzoneConfigKeys.DFS_CONTAINER_RATIS_DATASTREAM_RANDOM_PORT, true);
       OzoneContainer ozoneContainer = new OzoneContainer(
-          datanodeDetails, conf, getContext(datanodeDetails));
+          dnDetails, ozoneConf, getContext(dnDetails));
       rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
       VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint,
-          conf, ozoneContainer);
+          ozoneConf, ozoneContainer);
       EndpointStateMachine.EndPointStates newState = versionTask.call();
 
       // if version call worked the endpoint should automatically move to the
@@ -165,18 +175,17 @@ public class TestEndPoint {
    */
   @Test
   public void testDeletedContainersClearedOnStartup() throws Exception {
-    OzoneConfiguration conf = SCMTestUtils.getConf();
-    conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT,
+    ozoneConf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT,
         true);
-    conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT,
+    ozoneConf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT,
         true);
-    conf.setFromObject(new ReplicationConfig().setPort(0));
-    try (EndpointStateMachine rpcEndPoint = createEndpoint(conf,
+    ozoneConf.setFromObject(new ReplicationConfig().setPort(0));
+    try (EndpointStateMachine rpcEndPoint = createEndpoint(ozoneConf,
         serverAddress, 1000)) {
-      OzoneContainer ozoneContainer = createVolume(conf);
+      OzoneContainer ozoneContainer = createVolume(ozoneConf);
       HddsVolume hddsVolume = (HddsVolume) ozoneContainer.getVolumeSet()
           .getVolumesList().get(0);
-      KeyValueContainer kvContainer = addContainer(conf, hddsVolume);
+      KeyValueContainer kvContainer = addContainer(ozoneConf, hddsVolume);
       // For testing, we are moving the container under the tmp directory,
       // in order to delete during datanode startup or shutdown
       KeyValueContainerUtil.moveToDeletedContainerDir(
@@ -189,7 +198,7 @@ public class TestEndPoint {
 
       // versionTask.call() cleans the tmp dir and removes container from DB
       VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint,
-          conf, ozoneContainer);
+          ozoneConf, ozoneContainer);
       EndpointStateMachine.EndPointStates newState = versionTask.call();
 
       Assertions.assertEquals(EndpointStateMachine.EndPointStates.REGISTER,
@@ -205,24 +214,22 @@ public class TestEndPoint {
 
   @Test
   public void testCheckVersionResponse() throws Exception {
-    OzoneConfiguration conf = SCMTestUtils.getConf();
-    conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT,
+    ozoneConf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT,
         true);
-    conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT,
+    ozoneConf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT,
         true);
-    conf.setBoolean(
+    ozoneConf.setBoolean(
         OzoneConfigKeys.DFS_CONTAINER_RATIS_DATASTREAM_RANDOM_PORT, true);
-    conf.setFromObject(new ReplicationConfig().setPort(0));
-    try (EndpointStateMachine rpcEndPoint = createEndpoint(conf,
+    ozoneConf.setFromObject(new ReplicationConfig().setPort(0));
+    try (EndpointStateMachine rpcEndPoint = createEndpoint(ozoneConf,
         serverAddress, 1000)) {
       GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer
           .captureLogs(VersionEndpointTask.LOG);
-      DatanodeDetails datanodeDetails = randomDatanodeDetails();
       OzoneContainer ozoneContainer = new OzoneContainer(
-          datanodeDetails, conf, getContext(datanodeDetails));
+          dnDetails, ozoneConf, getContext(dnDetails));
       rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
       VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint,
-          conf, ozoneContainer);
+          ozoneConf, ozoneContainer);
       EndpointStateMachine.EndPointStates newState = versionTask.call();
 
       // if version call worked the endpoint should automatically move to the
@@ -254,6 +261,33 @@ public class TestEndPoint {
     }
   }
 
+  /**
+   * This test checks that dnlayout version file contains proper
+   * clusterID identifying the scm cluster the datanode is part of.
+   * Dnlayout version file set upon call to version endpoint.
+   */
+  @Test
+  public void testDnLayoutVersionFile() throws Exception {
+    ozoneConf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT,
+        true);
+    try (EndpointStateMachine rpcEndPoint = createEndpoint(ozoneConf,
+        serverAddress, 1000)) {
+      OzoneContainer ozoneContainer = new OzoneContainer(
+          dnDetails, ozoneConf, getContext(dnDetails));
+      rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
+      VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint,
+          ozoneConf, ozoneContainer);
+      versionTask.call();
+
+      // After the version call, the datanode layout file should
+      // have its clusterID field set to the clusterID of the scm
+      DatanodeLayoutStorage layout
+          = new DatanodeLayoutStorage(ozoneConf,
+          "na_expect_storage_initialized");
+      assertEquals(scmServerImpl.getClusterId(), layout.getClusterID());
+    }
+  }
+
   /**
    * This test makes a call to end point where there is no SCM server. We
    * expect that versionTask should be able to handle it.
@@ -592,9 +626,8 @@ public class TestEndPoint {
 
   private OzoneContainer createVolume(OzoneConfiguration conf)
       throws IOException {
-    DatanodeDetails datanodeDetails = randomDatanodeDetails();
     OzoneContainer ozoneContainer = new OzoneContainer(
-        datanodeDetails, conf, getContext(datanodeDetails));
+        dnDetails, conf, getContext(dnDetails));
 
     String clusterId = scmServerImpl.getClusterId();
 


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

Reply via email to