sodonnel commented on a change in pull request #2377:
URL: https://github.com/apache/ozone/pull/2377#discussion_r668668853



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java
##########
@@ -275,28 +276,38 @@ private Node chooseNode(List<Node> excludedNodes, Node 
affinityNode,
         throw new SCMException("No satisfied datanode to meet the" +
             " excludedNodes and affinityNode constrains.", null);
       }
-      if (super.hasEnoughSpace((DatanodeDetails)node, sizeRequired)) {
-        LOG.debug("Datanode {} is chosen. Required size is {}",
-            node.toString(), sizeRequired);
-        metrics.incrDatanodeChooseSuccessCount();
-        if (isFallbacked) {
-          metrics.incrDatanodeChooseFallbackCount();
-        }
-        return node;
+
+      DatanodeDetails datanodeDetails = (DatanodeDetails)node;
+      DatanodeInfo datanodeInfo = (DatanodeInfo)getNodeManager()
+          .getNodeByUuid(datanodeDetails.getUuidString());
+      if (datanodeInfo == null) {
+        LOG.error("Failed to find the DatanodeInfo for datanode {}",
+            datanodeDetails);

Review comment:
       You can get the nodeStatus directly via NodeManager:
   
   ```
     public NodeStatus getNodeStatus(DatanodeDetails datanodeDetails)
         throws NodeNotFoundException {
   ```
   
   Its doing basically what you are doing here, but I think its safer as an 
immutable NodeStatus object is returned under a lock to you:
   
   ```
     public NodeStatus getNodeStatus(UUID uuid) throws NodeNotFoundException {
       lock.readLock().lock();
       try {
         DatanodeInfo dn = nodeMap.get(uuid);
         if (dn == null) {
           throw new NodeNotFoundException("Node not found in node map." +
               " UUID: " + uuid);
         }
         return dn.getNodeStatus();
       } finally {
         lock.readLock().unlock();
       }
     }
   ```
   
   That means we don't need to worry about any side effects or concurrent 
modification here at all.




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