bharatviswa504 commented on a change in pull request #2257:
URL: https://github.com/apache/ozone/pull/2257#discussion_r634023911



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/ScmHAUnfinalizedStateValidationAction.java
##########
@@ -37,13 +45,22 @@
   public void execute(StorageContainerManager scm) throws Exception {
     boolean isHAEnabled =
         
scm.getConfiguration().getBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY,
-        ScmConfigKeys.OZONE_SCM_HA_ENABLE_DEFAULT);
+            ScmConfigKeys.OZONE_SCM_HA_ENABLE_DEFAULT);
 
     if (isHAEnabled) {
-      throw new UpgradeException(String.format("Configuration %s cannot be " +
-          "used until SCM upgrade has been finalized",
-          ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY),
-          UpgradeException.ResultCodes.PREFINALIZE_ACTION_VALIDATION_FAILED);
+      long lastIndex = scm.getScmHAManager()

Review comment:
       I believe we don't need this, we can check SCM StorageConfig SCM_HA 
Property.
   For Ha enabled cluster, this property is set.
   

##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/upgrade/TestScmHAUnfinalizedStateValidationAction.java
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.hdds.upgrade;
+
+import static org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature.INITIAL_VERSION;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
+import 
org.apache.hadoop.hdds.scm.server.upgrade.ScmHAUnfinalizedStateValidationAction;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.MiniOzoneClusterImpl;
+import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
+import org.apache.hadoop.ozone.upgrade.UpgradeException;
+import org.apache.hadoop.test.LambdaTestUtils;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Tests that the SCM HA pre-finalize validation action is only triggered in
+ * pre-finalize startup if SCM HA was not already being used in the cluster,
+ * but has been turned on after.
+ *
+ * Starting a new SCM HA cluster finalized should not trigger the action. This
+ * is tested by all other tests that use SCM HA from the latest version of the
+ * code.
+ *
+ * Starting a new cluster finalized without SCM HA enabled should not trigger
+ * the action. This is tested by all other tests that run non-HA clusters.
+ */
+// Tests are ignored to speed up CI runs. Run manually if changes are made
+// relating to the SCM HA validation action.
+@Ignore
+public class TestScmHAUnfinalizedStateValidationAction {
+  private static final OzoneConfiguration CONF = new OzoneConfiguration();
+
+  @Test
+  public void testHAEnabledAlreadyUsedFinalized() throws Exception {
+    // Verification should pass.
+    MiniOzoneCluster cluster = new MiniOzoneHAClusterImpl.Builder(CONF)
+        .setNumDatanodes(1)
+        .setNumOfStorageContainerManagers(3)
+        .setNumOfOzoneManagers(1)
+        .setSCMServiceId("id1")
+        .setOMServiceId("id2")
+        .build();
+
+    // Manually trigger the upgrade action after setup, to see if it detects
+    // that HA is being used based on disk structures.
+    // This avoids saving disk state between mini ozone cluster restart.
+    ScmHAUnfinalizedStateValidationAction action =
+        new ScmHAUnfinalizedStateValidationAction();
+    for (StorageContainerManager scm:
+        ((MiniOzoneHAClusterImpl) cluster).getStorageContainerManagers()) {
+      action.execute(scm);
+    }
+
+    cluster.shutdown();
+  }
+
+  @Test
+  public void testHAEnabledNotAlreadyUsedPreFinalized() throws Exception {
+    // Verification should fail.
+    MiniOzoneCluster.Builder builder = new MiniOzoneHAClusterImpl.Builder(CONF)
+        .setNumDatanodes(1)
+        .setNumOfStorageContainerManagers(3)
+        .setNumOfOzoneManagers(1)
+        .setSCMServiceId("id1")
+        .setOMServiceId("id2")
+        .setScmLayoutVersion(INITIAL_VERSION.layoutVersion())

Review comment:
       Question:
   So init will successfully happen but startup will fail?

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
##########
@@ -1158,6 +1158,8 @@ public String getDatanodeRpcPort() {
    */
   @Override
   public void start() throws IOException {
+    upgradeFinalizer.runPrefinalizeStateActions(scmStorageConfig, this);

Review comment:
       Question:
   So init will successfully happen but the startup will fail?
   
   
   Because if init happens every time after the upgrade, ratis sever might have 
started and already initialized ratis server, and wait for leader election.
   
   Do we want to run these checks in init also to avoid ratis server 
initialization.
   




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to