sadanand48 commented on code in PR #10249:
URL: https://github.com/apache/ozone/pull/10249#discussion_r3246803648


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/safemode/AbstractContainerSafeModeRule.java:
##########
@@ -80,6 +81,27 @@ protected void initializeRule() {
     totalContainers.set(containers.size());
     final long cutOff = (long) Math.ceil(getTotalNumberOfContainers() * 
getSafeModeCutoff());
     getSafeModeMetrics().setNumContainerReportedThreshold(getContainerType(), 
cutOff);
+    SCMSafeModeManager.getLogger().info("Initialized {} Containers threshold 
count to {}.", getContainerType(), cutOff);
+  }
+
+  protected void reinitializeRule() {
+    // Remove closed containers that are moved to deleted state as DN will not 
report those containers during
+    // registration. Update totalContainers, cutoff and threshold based on 
reduced containers.
+    // Since ContainerSafeModeRule is updated with container list notified 
during DN registration only,
+    // So its not required to add newly created container after DN 
registration.
+    int oldContainerCount = containers.size();
+    Set<ContainerID> containerInfoSet = 
containerManager.getContainers(getContainerType()).stream()
+        .filter(this::isClosed)
+        .filter(c -> c.getNumberOfKeys() > 0)
+        .filter(c -> 
containers.containsKey(ContainerID.valueOf(c.getContainerID())))
+        .map(c -> ContainerID.valueOf(c.getContainerID()))
+        .collect(Collectors.toSet());
+    // remove deleted containers from containers list
+    containers.keySet().removeIf(c -> !containerInfoSet.contains(c));
+    // update new total with reducing removed containers
+    totalContainers.set(totalContainers.get() - (oldContainerCount - 
containers.size()));

Review Comment:
   I think this can be simply set to 
   totalContainers.set(containers.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