[ 
https://issues.apache.org/jira/browse/HDFS-15783?focusedWorklogId=537963&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-537963
 ]

ASF GitHub Bot logged work on HDFS-15783:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Jan/21 18:35
            Start Date: 19/Jan/21 18:35
    Worklog Time Spent: 10m 
      Work Description: goiri commented on a change in pull request #2626:
URL: https://github.com/apache/hadoop/pull/2626#discussion_r560397258



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyRackFaultTolerant.java
##########
@@ -237,14 +237,11 @@ public BlockPlacementStatus 
verifyBlockPlacement(DatanodeInfo[] locs,
       // only one rack
       return new BlockPlacementStatusDefault(1, 1, 1);
     }
-    // 1. Check that all locations are different.
-    // 2. Count locations on different racks.
-    Set<String> racks = new TreeSet<>();
-    for (DatanodeInfo dn : locs) {
-      racks.add(dn.getNetworkLocation());
-    }
-    return new BlockPlacementStatusDefault(racks.size(), numberOfReplicas,
-        clusterMap.getNumOfRacks());
+    // Count locations on different racks.
+    final long rackCount = Arrays.stream(locs)
+        .map(DatanodeInfo::getNetworkLocation).distinct().count();
+    return new BlockPlacementStatusDefault(Math.toIntExact(rackCount),

Review comment:
       You are following the same as in HDFS-14102 but I'd prefer extracting 
the int casting instead of doing it in the call.
   A little more verbose but I would extract it.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 537963)
    Time Spent: 0.5h  (was: 20m)

> Speed up BlockPlacementPolicyRackFaultTolerant#verifyBlockPlacement
> -------------------------------------------------------------------
>
>                 Key: HDFS-15783
>                 URL: https://issues.apache.org/jira/browse/HDFS-15783
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: block placement
>            Reporter: Akira Ajisaka
>            Assignee: Akira Ajisaka
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> {code:java}
> Set<String> racks = new TreeSet<>();
> for (DatanodeInfo dn : locs) {
>   racks.add(dn.getNetworkLocation());
> }
> return new BlockPlacementStatusDefault(racks.size(), numberOfReplicas,
>     clusterMap.getNumOfRacks());{code}
> Here, HashMap should be used instead of TreeSet.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to