sodonnel commented on code in PR #3744:
URL: https://github.com/apache/ozone/pull/3744#discussion_r976665346


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/SCMCommonPlacementPolicy.java:
##########
@@ -146,8 +159,14 @@ object of DatanodeDetails(with Topology Information) while 
trying to get the
   random node from NetworkTopology should fix this. Check HDDS-7015
  */
     return chooseDatanodesInternal(
+            Objects.isNull(usedNodes) ? Collections.emptyList()

Review Comment:
   The modified code looks like:
   
   ```
    return chooseDatanodesInternal(
             Objects.isNull(usedNodes) ? Collections.emptyList()
                       : usedNodes.stream().map(node -> {
                         DatanodeDetails datanodeDetails =
                                 
nodeManager.getNodeByUuid(node.getUuidString());
                         return datanodeDetails != null ? datanodeDetails : 
node;
                       }).collect(Collectors.toList()),
               Objects.isNull(excludedNodes)
                       ? excludedNodes : excludedNodes.stream()
                       ? Collections.emptyList() : excludedNodes.stream()
                       .map(node -> {
                         DatanodeDetails datanodeDetails =
                                 
nodeManager.getNodeByUuid(node.getUuidString());
                         return datanodeDetails != null ? datanodeDetails : 
node;
                       }).collect(Collectors.toList()));
   ```
   
   Could we not change this to look like:
   
   ```
   private List<DatanodeDetails> validateDatanodes(List<DatanodeDetails> dns) {
     return Objects.isNull(dns) ? Collections.emptyList()
                       : dns.stream().map(node -> {
                         DatanodeDetails datanodeDetails =
                                 
nodeManager.getNodeByUuid(node.getUuidString());
                         return datanodeDetails != null ? datanodeDetails : 
node;
                       }).collect(Collectors.toList())
   }
   
    return chooseDatanodesInternal(
     validateDatanodes(usedNodes), validateDatanode(excludedNodes);
   _
   ```
   
   The logic used to map both used and excluded looks to be the same to me, and 
its complicated enough it should be extracted into a method I think.



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