rakeshadr commented on code in PR #10157:
URL: https://github.com/apache/ozone/pull/10157#discussion_r3419976720


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/SafeModeRuleFactory.java:
##########
@@ -93,14 +99,41 @@ private void loadRules(SCMSafeModeManager safeModeManager) {
     }
 
     if (pipelineManager != null) {
-      safeModeRules.add(new HealthyPipelineSafeModeRule(eventQueue, 
pipelineManager,
-          safeModeManager, config, scmContext, nodeManager));
+      if (shouldEnableHealthyPipelineRule()) {
+        safeModeRules.add(new HealthyPipelineSafeModeRule(eventQueue,
+            pipelineManager, safeModeManager, config, scmContext, 
nodeManager));
+      } else {
+        SCMSafeModeManager.getLogger().info("HealthyPipelineSafeModeRule is "
+            + "disabled for EC-default cluster because "
+            + "{} is false.",
+            ScmConfigKeys.OZONE_SCM_EC_PIPELINE_CREATE_RATIS_THREE);
+      }
       safeModeRules.add(new OneReplicaPipelineSafeModeRule(eventQueue, 
pipelineManager,
           safeModeManager, config));
     }
 
   }
 
+  private boolean shouldEnableHealthyPipelineRule() {
+    ReplicationConfig defaultReplicationConfig;
+    try {
+      defaultReplicationConfig = ReplicationConfig.getDefault(config);
+    } catch (IllegalArgumentException e) {
+      SCMSafeModeManager.getLogger().warn("Falling back to enabling "
+          + "HealthyPipelineSafeModeRule because default replication config "
+          + "could not be parsed.", e);
+      return true;

Review Comment:
   why returning true?



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/BackgroundPipelineCreator.java:
##########
@@ -255,6 +236,57 @@ private void createPipelines() throws RuntimeException {
     LOG.debug("BackgroundPipelineCreator createPipelines finished.");
   }
 
+  @VisibleForTesting
+  List<ReplicationConfig> getReplicationConfigs(boolean autoCreateFactorOne) {
+    List<ReplicationConfig> list = new ArrayList<>();
+    ReplicationConfig defaultReplicationConfig = getDefaultReplicationConfig();
+    // TODO: #CLUTIL Different replication factor may need to be supported
+    HddsProtos.ReplicationType type = defaultReplicationConfig != null

Review Comment:
   don't fall back to raw config when getDefaultReplicationConfig() fails
   
   ```
       if (defaultReplicationConfig == null) {
         LOG.warn("Skipping background pipeline creation: default replication 
config is invalid.");
         return list;
       }
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/SafeModeRuleFactory.java:
##########
@@ -93,14 +99,41 @@ private void loadRules(SCMSafeModeManager safeModeManager) {
     }
 
     if (pipelineManager != null) {
-      safeModeRules.add(new HealthyPipelineSafeModeRule(eventQueue, 
pipelineManager,
-          safeModeManager, config, scmContext, nodeManager));
+      if (shouldEnableHealthyPipelineRule()) {
+        safeModeRules.add(new HealthyPipelineSafeModeRule(eventQueue,
+            pipelineManager, safeModeManager, config, scmContext, 
nodeManager));
+      } else {
+        SCMSafeModeManager.getLogger().info("HealthyPipelineSafeModeRule is "
+            + "disabled for EC-default cluster because "
+            + "{} is false.",
+            ScmConfigKeys.OZONE_SCM_EC_PIPELINE_CREATE_RATIS_THREE);
+      }
       safeModeRules.add(new OneReplicaPipelineSafeModeRule(eventQueue, 
pipelineManager,
           safeModeManager, config));
     }
 
   }
 
+  private boolean shouldEnableHealthyPipelineRule() {

Review Comment:
   add javadoc:
   
   ```
     /**
      * Returns true when RATIS/THREE pipeline safemode rules should be active.
      * For EC-default clusters, these rules are only meaningful when 
RATIS/THREE
      * background pipeline creation is also enabled (same flag); if no 
RATIS/THREE
      * pipelines are created, requiring them in safemode would block safemode 
exit.
      */
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/SafeModeRuleFactory.java:
##########
@@ -93,14 +99,41 @@ private void loadRules(SCMSafeModeManager safeModeManager) {
     }
 
     if (pipelineManager != null) {
-      safeModeRules.add(new HealthyPipelineSafeModeRule(eventQueue, 
pipelineManager,
-          safeModeManager, config, scmContext, nodeManager));
+      if (shouldEnableHealthyPipelineRule()) {
+        safeModeRules.add(new HealthyPipelineSafeModeRule(eventQueue,
+            pipelineManager, safeModeManager, config, scmContext, 
nodeManager));
+      } else {
+        SCMSafeModeManager.getLogger().info("HealthyPipelineSafeModeRule is "
+            + "disabled for EC-default cluster because "
+            + "{} is false.",
+            ScmConfigKeys.OZONE_SCM_EC_PIPELINE_CREATE_RATIS_THREE);
+      }
       safeModeRules.add(new OneReplicaPipelineSafeModeRule(eventQueue, 
pipelineManager,
           safeModeManager, config));
     }
 
   }
 
+  private boolean shouldEnableHealthyPipelineRule() {

Review Comment:
   Please rename this method to `shouldEnableRatisThreePipelineRules()`



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/ECMinDataNodeSafeModeRule.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.scm.safemode;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.hadoop.hdds.client.ECReplicationConfig;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.protocol.DatanodeID;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.events.SCMEvents;
+import org.apache.hadoop.hdds.scm.node.NodeManager;
+import org.apache.hadoop.hdds.scm.node.NodeStatus;
+import 
org.apache.hadoop.hdds.scm.server.SCMDatanodeProtocolServer.NodeRegistrationContainerReport;
+import org.apache.hadoop.hdds.server.events.EventQueue;
+import org.apache.hadoop.hdds.server.events.TypedEvent;
+
+/**
+ * Safe mode exit rule for EC-default clusters.
+ *
+ * <p>EC pipelines are ephemeral and created on demand. This rule ensures that
+ * at least {@code data + parity} healthy DataNodes are available before SCM
+ * exits safe mode for EC-default clusters.
+ *
+ * <p>For non-EC defaults this rule is a no-op.
+ */
+public class ECMinDataNodeSafeModeRule
+    extends SafeModeExitRule<NodeRegistrationContainerReport> {
+
+  private final boolean enabled;
+  private final int requiredDns;
+  private final String ecConfigLabel;
+  private final NodeManager nodeManager;
+  private final Set<DatanodeID> registeredDnSet;
+  private int registeredDns = 0;
+
+  public ECMinDataNodeSafeModeRule(EventQueue eventQueue,
+      ConfigurationSource conf,
+      NodeManager nodeManager,
+      SCMSafeModeManager safeModeManager) {
+    super(safeModeManager, eventQueue);
+    this.nodeManager = nodeManager;
+
+    ReplicationConfig defaultConfig = getDefaultReplicationConfig(conf);
+    if (defaultConfig != null
+        && defaultConfig.getReplicationType() == 
HddsProtos.ReplicationType.EC) {
+      ECReplicationConfig ecConfig = (ECReplicationConfig) defaultConfig;
+      this.requiredDns = ecConfig.getRequiredNodes();
+      this.ecConfigLabel = ecConfig.configFormat();
+      this.enabled = true;
+      this.registeredDnSet = new HashSet<>(Math.max(requiredDns * 2, 1));
+      SCMSafeModeManager.getLogger().info(
+          "ECMinDataNodeSafeModeRule enabled for default EC config {}. "
+              + "Required healthy DataNodes for safemode exit: {}.",
+          ecConfigLabel, requiredDns);
+    } else {
+      this.requiredDns = 0;
+      this.ecConfigLabel = "";
+      this.enabled = false;
+      this.registeredDnSet = new HashSet<>(0);
+      SCMSafeModeManager.getLogger().debug(
+          "ECMinDataNodeSafeModeRule disabled: default replication is not 
EC.");
+    }
+  }
+
+  @Override
+  protected TypedEvent<NodeRegistrationContainerReport> getEventType() {
+    return SCMEvents.NODE_REGISTRATION_CONT_REPORT;
+  }
+
+  @Override
+  protected boolean validate() {
+    if (!enabled) {
+      return true;
+    }
+    if (validateBasedOnReportProcessing()) {
+      return registeredDns >= requiredDns;
+    }
+    return nodeManager.getNodes(NodeStatus.inServiceHealthy()).size() >= 
requiredDns;
+  }
+
+  @Override
+  protected void process(NodeRegistrationContainerReport report) {
+    if (!enabled) {
+      return;
+    }
+    DatanodeID dnId = report.getDatanodeDetails().getID();
+    if (registeredDnSet.add(dnId)) {
+      registeredDns = registeredDnSet.size();
+      if (scmInSafeMode()) {
+        SCMSafeModeManager.getLogger().info(
+            "SCM in safe mode. EC rule progress: {} of {} required "
+                + "DataNodes registered for EC {}.",
+            registeredDns, requiredDns, ecConfigLabel);
+      }
+    }
+  }
+
+  @Override
+  protected void cleanup() {
+    registeredDnSet.clear();
+  }
+
+  @Override
+  public String getStatusText() {
+    if (!enabled) {
+      return "ECMinDataNodeSafeModeRule is not applicable "
+          + "(default replication is not EC)";
+    }
+    return String.format(
+        "EC (%s) safemode: registered DataNodes (=%d) >= required DataNodes 
(=%d)",
+        ecConfigLabel, registeredDns, requiredDns);
+  }
+
+  @Override
+  public void refresh(boolean forceRefresh) {
+    // Nothing to refresh from SCM DB for this rule.
+  }
+
+  @VisibleForTesting
+  int getRequiredDns() {

Review Comment:
   can we change this to below and use this `getRegisteredDns()` instead of 
plain `registeredDns`
   
   ```
     synchronized int getRegisteredDns() {
       return registeredDnSet.size();
     }
   ```



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

Reply via email to