hfutatzhanghb commented on code in PR #5597:
URL: https://github.com/apache/hadoop/pull/5597#discussion_r1205453041


##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java:
##########
@@ -2630,6 +2632,31 @@ public int getActiveTransferThreadCount() {
 
   @Override // DataNodeMXBean
   public Map<String, Map<String, Long>> getDatanodeNetworkCounts() {
+    int maxDisplay = 
getConf().getInt(DFSConfigKeys.DFS_DATANODE_NETWORKERRORS_DISPLAY_TOPCOUNT,
+        DFSConfigKeys.DFS_DATANODE_NETWORKERRORS_DISPLAY_TOPCOUNT_DEFAULT);
+    if (maxDisplay >= 0) {
+      ConcurrentMap<String, Map<String, Long>> map = 
datanodeNetworkCounts.asMap();
+      Set<Map.Entry<String, Map<String, Long>>> entries = map.entrySet();
+      List<Map.Entry<String, Map<String, Long>>> list = new 
ArrayList<>(entries);
+      Collections.sort(list, new Comparator<Entry<String, Map<String, 
Long>>>() {
+        @Override
+        public int compare(Map.Entry<String, Map<String, Long>> o1,
+            Map.Entry<String, Map<String, Long>> o2) {
+          Map<String, Long> value1Map = o1.getValue();
+          Map<String, Long> value2Map = o2.getValue();
+          long compared = value2Map.getOrDefault(DataNode.NETWORK_ERRORS, 0L) -
+              value1Map.getOrDefault(DataNode.NETWORK_ERRORS, 0L);
+          return (int)compared;
+        }
+      });
+      Map<String, Map<String, Long>> resultMap = new ConcurrentHashMap<>();
+      maxDisplay = list.size() > maxDisplay ? maxDisplay : list.size();
+      for (int i = 0; i < maxDisplay; i++) {
+        resultMap.put(list.get(i).getKey(), list.get(i).getValue());
+      }
+      list.clear();

Review Comment:
   Sir, it's better to clear the list here to prevent memory leak.



-- 
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: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to