This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new a8836a77263 HDDS-17381. Reduce allocations in SCM placement validation 
(#11717)
a8836a77263 is described below

commit a8836a772636a2486ec0cc07f4bc75f73f7ce6ff
Author: Shuo Huang <[email protected]>
AuthorDate: Thu Nov 12 22:34:56 2026 +0800

    HDDS-17381. Reduce allocations in SCM placement validation (#11717)
---
 .../hadoop/hdds/scm/SCMCommonPlacementPolicy.java  | 56 +++++++++++-----------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMCommonPlacementPolicy.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMCommonPlacementPolicy.java
index 0deece79c6d..a63145815a4 100644
--- 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMCommonPlacementPolicy.java
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMCommonPlacementPolicy.java
@@ -32,7 +32,6 @@
 import java.util.Queue;
 import java.util.Random;
 import java.util.Set;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 import org.apache.hadoop.hdds.conf.ConfigurationSource;
 import org.apache.hadoop.hdds.protocol.DatanodeDetails;
@@ -460,33 +459,36 @@ public ContainerPlacementStatus 
validateContainerPlacement(
         return invalidPlacement;
       }
     }
-    List<Integer> currentRackCount = new ArrayList<>(dns.stream()
-        .map(dn -> {
-          Node rack = getPlacementGroup(dn);
-          if (rack == null) {
-            try {
-              NodeStatus nodeStatus = nodeManager.getNodeStatus(dn);
-              if (nodeStatus.isDead() && nodeStatus.isMaintenance()) {
-                LOG.debug("Using rack [{}] for dead and in-maintenance dn 
{}.", dn.getNetworkLocation(), dn);
-                return dn.getNetworkLocation();
-              }
-              return null;
-            } catch (NodeNotFoundException e) {
-              LOG.debug("Could not get NodeStatus for dn {}.", dn, e);
-              return null;
-            }
+    Map<String, Integer> rackCounts = new HashMap<>();
+    for (DatanodeDetails dn : dns) {
+      Node rack = getPlacementGroup(dn);
+      String rackPath;
+      if (rack == null) {
+        try {
+          NodeStatus nodeStatus = nodeManager.getNodeStatus(dn);
+          if (!nodeStatus.isDead() || !nodeStatus.isMaintenance()) {
+            continue;
           }
-          /*
-          data-centre/rack1/dn1. Here, data-centre/rack1 is the network 
location of dn1 and data-centre/rack1 is also
-          the network full path of rack1.
-          */
-          return rack.getNetworkFullPath();
-        })
-        .filter(Objects::nonNull)
-        .collect(Collectors.groupingBy(
-            Function.identity(),
-            Collectors.reducing(0, e -> 1, Integer::sum)))
-        .values());
+          rackPath = dn.getNetworkLocation();
+          LOG.debug("Using rack [{}] for dead and in-maintenance dn {}.",
+              rackPath, dn);
+        } catch (NodeNotFoundException e) {
+          LOG.debug("Could not get NodeStatus for dn {}.", dn, e);
+          continue;
+        }
+      } else {
+        /*
+        data-centre/rack1/dn1. Here, data-centre/rack1 is the network location 
of dn1 and data-centre/rack1 is also
+        the network full path of rack1.
+        */
+        rackPath = rack.getNetworkFullPath();
+      }
+      if (rackPath != null) {
+        Integer count = rackCounts.get(rackPath);
+        rackCounts.put(rackPath, count == null ? 1 : count + 1);
+      }
+    }
+    List<Integer> currentRackCount = new ArrayList<>(rackCounts.values());
     if (replicas < requiredRacks) {
       requiredRacks = replicas;
     }


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

Reply via email to