adoroszlai commented on code in PR #8940:
URL: https://github.com/apache/ozone/pull/8940#discussion_r2273676715


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/RatisContainerSafeModeRule.java:
##########
@@ -137,53 +78,41 @@ protected void process(NodeRegistrationContainerReport 
report) {
     }
   }
 
-  /**
-   * Record the reported Container.
-   *
-   * @param containerID containerID
-   */
-  private void recordReportedContainer(long containerID) {
-    ratisContainerWithMinReplicas.getAndAdd(1);
-    getSafeModeMetrics()
-        .incCurrentContainersWithOneReplicaReportedCount();
+  /** Record the reported Container. */
+  private void recordReportedContainer() {
+    ratisContainerWithMinReplicas.incrementAndGet();
+    getSafeModeMetrics().incCurrentContainersWithOneReplicaReportedCount();
   }
 
   private void initializeRule() {
     ratisContainers.clear();
     containerManager.getContainers(ReplicationType.RATIS).stream()
-        .filter(this::isClosed).filter(c -> c.getNumberOfKeys() > 0)
-        .map(ContainerInfo::getContainerID).forEach(ratisContainers::add);
+        .filter(this::isClosed)
+        .filter(c -> c.getNumberOfKeys() > 0)
+        .map(ContainerInfo::containerID)
+        .forEach(ratisContainers::add);
     ratisMaxContainer = ratisContainers.size();
-    long ratisCutOff = (long) Math.ceil(ratisMaxContainer * safeModeCutoff);
+    long ratisCutOff = (long) Math.ceil(ratisMaxContainer * 
getSafeModeCutoff());
     
getSafeModeMetrics().setNumContainerWithOneReplicaReportedThreshold(ratisCutOff);
 
     LOG.info("Refreshed Containers with one replica threshold count {}.", 
ratisCutOff);
   }

Review Comment:
   Logic in `initializeRule()` is still duplicated.  Can pass call 
`getContainers(getContainerType())` instead of hard-coding.  With that, the 
only differences are the specific metric being set and the log message.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/AbstractContainerSafeModeRule.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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 static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT;
+import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT_DEFAULT;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Set;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.ContainerManager;
+import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
+import org.apache.hadoop.hdds.scm.events.SCMEvents;
+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;
+
+/**
+ * Abstract class for Container Safe mode exit rule.
+ */
+public abstract class AbstractContainerSafeModeRule extends 
SafeModeExitRule<NodeRegistrationContainerReport> {
+
+  private final ContainerManager containerManager;
+  private final double safeModeCutoff;
+
+  public AbstractContainerSafeModeRule(ConfigurationSource conf,
+                                       SCMSafeModeManager safeModeManager,
+                                       ContainerManager containerManager,
+                                       String ruleName,
+                                       EventQueue eventQueue) {

Review Comment:
   nit: Please do not format method signature like this. Whenever visibility / 
return type / method name / other modifiers are changed, we would have to 
reindent all parameters.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/AbstractContainerSafeModeRule.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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 static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT;
+import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_SAFEMODE_THRESHOLD_PCT_DEFAULT;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Set;
+import org.apache.hadoop.hdds.client.ReplicationConfig;
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.ContainerManager;
+import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
+import org.apache.hadoop.hdds.scm.events.SCMEvents;
+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;
+
+/**
+ * Abstract class for Container Safe mode exit rule.
+ */
+public abstract class AbstractContainerSafeModeRule extends 
SafeModeExitRule<NodeRegistrationContainerReport> {
+
+  private final ContainerManager containerManager;
+  private final double safeModeCutoff;
+
+  public AbstractContainerSafeModeRule(ConfigurationSource conf,
+                                       SCMSafeModeManager safeModeManager,
+                                       ContainerManager containerManager,
+                                       String ruleName,
+                                       EventQueue eventQueue) {
+    super(safeModeManager, ruleName, eventQueue);
+    this.containerManager = containerManager;
+    this.safeModeCutoff = getSafeModeCutoff(conf);
+  }
+
+  protected abstract ReplicationType getContainerType();
+
+  protected abstract long getTotalNumberOfContainers();
+
+  protected abstract long getNumberOfContainersWithMinReplica();
+
+  protected abstract  Set<ContainerID> getSampleMissingContainers();
+
+  protected double getSafeModeCutoff() {
+    return safeModeCutoff;
+  }
+
+  @Override
+  protected TypedEvent<NodeRegistrationContainerReport> getEventType() {
+    return SCMEvents.CONTAINER_REGISTRATION_REPORT;
+  }
+
+  @Override
+  protected synchronized boolean validate() {
+    if (validateBasedOnReportProcessing()) {
+      return getCurrentContainerThreshold() >= getSafeModeCutoff();
+    }
+
+    final List<ContainerInfo> containers = 
containerManager.getContainers(getContainerType());
+    return containers.stream()
+        .filter(this::isClosed)
+        .map(ContainerInfo::containerID)
+        .noneMatch(this::isMissing);
+  }
+
+  @VisibleForTesting
+  public double getCurrentContainerThreshold() {
+    return getTotalNumberOfContainers() == 0 ? 1 :
+        ((double) getNumberOfContainersWithMinReplica() / 
getTotalNumberOfContainers());

Review Comment:
   nit: store result of `getTotalNumberOfContainers()` in variable



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