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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/BackgroundPipelineCreator.java:
##########
@@ -255,6 +236,59 @@ private void createPipelines() throws RuntimeException {
     LOG.debug("BackgroundPipelineCreator createPipelines finished.");
   }
 
+  @VisibleForTesting
+  List<ReplicationConfig> getReplicationConfigs(boolean autoCreateFactorOne) {
+    List<ReplicationConfig> list = new ArrayList<>();
+    ReplicationConfig defaultReplicationConfig = getDefaultReplicationConfig();
+    if (defaultReplicationConfig == null) {
+      LOG.warn("Skipping background pipeline creation: default replication "
+          + "config is invalid.");
+      return list;
+    }
+    // TODO: #CLUTIL Different replication factor may need to be supported
+    HddsProtos.ReplicationType type =
+        defaultReplicationConfig.getReplicationType();
+    if (type == EC) {
+      if (createRatisThreeForEcDefault) {
+        list.add(ReplicationConfig.fromProtoTypeAndFactor(RATIS,
+            ReplicationFactor.THREE));
+      }
+      return list;
+    }
+
+    for (HddsProtos.ReplicationFactor factor
+        : HddsProtos.ReplicationFactor.values()) {
+      if (factor == ReplicationFactor.ZERO) {
+        continue; // Ignore it.
+      }
+      final ReplicationConfig replicationConfig =
+          ReplicationConfig.fromProtoTypeAndFactor(type, factor);
+      if (skipCreation(replicationConfig, autoCreateFactorOne)) {
+        // Skip this iteration for creating pipeline
+        continue;
+      }
+      if (!list.contains(replicationConfig)) {
+        list.add(replicationConfig);
+      }
+    }
+    return list;
+  }
+
+  private ReplicationConfig getDefaultReplicationConfig() {

Review Comment:
   Both `BackgroundPipelineCreator` and `ECMinDataNodeSafeModeRule` have 
identical private `getDefaultReplicationConfig(ConfigurationSource conf)` 
methods. Extract to a shared utility or ReplicationConfig itself.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/SafeModeRuleFactory.java:
##########
@@ -75,10 +78,13 @@ private void loadRules(SCMSafeModeManager safeModeManager) {
         config, containerManager, safeModeManager);
     SafeModeExitRule<?> datanodeRule = new DataNodeSafeModeRule(eventQueue, 
         config, nodeManager, safeModeManager);
+    SafeModeExitRule<?> ecMinDnRule = new ECMinDataNodeSafeModeRule(eventQueue,
+        config, nodeManager, safeModeManager);
 
     safeModeRules.add(ratisContainerRule);
     safeModeRules.add(ecContainerRule);
     safeModeRules.add(datanodeRule);
+    safeModeRules.add(ecMinDnRule);

Review Comment:
   If EC is default then only we. should add ecMinDnRule. Something like
   if (isEcDefault(config)) {
       safeModeRules.add(ecMinDnRule);
   }



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

Review Comment:
   Do we even need to check `type == EC` . I think 
`if(createRatisThreeForEcDefault) `is true we should go ahead and create 
`Ratis-3` pipeline irrespctive of EC is default or not..



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/ECMinDataNodeSafeModeRule.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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;
+
+  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 synchronized boolean validate() {
+    if (!enabled) {
+      return true;
+    }
+    if (validateBasedOnReportProcessing()) {
+      return getRegisteredDns() >= requiredDns;
+    }
+    return nodeManager.getNodes(NodeStatus.inServiceHealthy()).size() >= 
requiredDns;
+  }
+
+  @Override
+  protected synchronized void process(NodeRegistrationContainerReport report) {
+    if (!enabled) {
+      return;
+    }
+    DatanodeID dnId = report.getDatanodeDetails().getID();
+    if (registeredDnSet.add(dnId)) {
+      if (scmInSafeMode()) {
+        SCMSafeModeManager.getLogger().info(
+            "SCM in safe mode. EC rule progress: {} of {} required "
+                + "DataNodes registered for EC {}.",
+            getRegisteredDns(), requiredDns, ecConfigLabel);
+      }
+    }
+  }
+
+  @Override
+  protected synchronized void cleanup() {
+    registeredDnSet.clear();
+  }
+
+  @Override
+  public synchronized 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, getRegisteredDns(), requiredDns);
+  }
+
+  @Override
+  public void refresh(boolean forceRefresh) {
+    // Nothing to refresh from SCM DB for this rule.
+  }
+
+  @VisibleForTesting
+  int getRequiredDns() {
+    return requiredDns;
+  }
+
+  @VisibleForTesting
+  synchronized int getRegisteredDns() {
+    return registeredDnSet.size();
+  }
+
+  @VisibleForTesting

Review Comment:
   `@VisibleForTesting` not required based on 
[HDDS-12725](https://issues.apache.org/jira/browse/HDDS-12725).



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/ECMinDataNodeSafeModeRule.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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;
+
+  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;

Review Comment:
   If `ec` is disabled and rule is not loaded in first place, lot of this if 
else will go away.



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