Skip to content

Commit 8f316af

Browse files
adminhfutatzhanghb
authored andcommitted
HDFS-16993. Datanode supports configure TopN DatanodeNetworkCounts
1 parent 55eebcf commit 8f316af

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
468468
public static final long DFS_DATANODE_PROCESS_COMMANDS_THRESHOLD_DEFAULT =
469469
TimeUnit.SECONDS.toMillis(2);
470470

471+
public static final String DFS_DATANODE_NETWORKERRORS_DISPLAY_TOPCOUNT =
472+
"dfs.datanode.networkerrors.display.topcount";
473+
public static final int DFS_DATANODE_NETWORKERRORS_DISPLAY_TOPCOUNT_DEFAULT = 10;
474+
471475
public static final String DFS_NAMENODE_DATANODE_REGISTRATION_IP_HOSTNAME_CHECK_KEY = "dfs.namenode.datanode.registration.ip-hostname-check";
472476
public static final boolean DFS_NAMENODE_DATANODE_REGISTRATION_IP_HOSTNAME_CHECK_DEFAULT = true;
473477

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
import java.util.Arrays;
118118
import java.util.Collection;
119119
import java.util.Collections;
120+
import java.util.Comparator;
120121
import java.util.EnumSet;
121122
import java.util.HashMap;
122123
import java.util.HashSet;
@@ -128,6 +129,7 @@
128129
import java.util.UUID;
129130
import java.util.concurrent.Callable;
130131
import java.util.concurrent.ConcurrentHashMap;
132+
import java.util.concurrent.ConcurrentMap;
131133
import java.util.concurrent.ExecutionException;
132134
import java.util.concurrent.ExecutorService;
133135
import java.util.concurrent.Executors;
@@ -2630,7 +2632,29 @@ public int getActiveTransferThreadCount() {
26302632

26312633
@Override // DataNodeMXBean
26322634
public Map<String, Map<String, Long>> getDatanodeNetworkCounts() {
2633-
return datanodeNetworkCounts.asMap();
2635+
int maxDisplay = getConf().getInt(DFSConfigKeys.DFS_DATANODE_NETWORKERRORS_DISPLAY_TOPCOUNT,
2636+
DFSConfigKeys.DFS_DATANODE_NETWORKERRORS_DISPLAY_TOPCOUNT_DEFAULT);
2637+
ConcurrentMap<String, Map<String, Long>> map = datanodeNetworkCounts.asMap();
2638+
Set<Map.Entry<String, Map<String, Long>>> entries = map.entrySet();
2639+
List<Map.Entry<String, Map<String, Long>>> list = new ArrayList<>(entries);
2640+
Collections.sort(list, new Comparator<Entry<String, Map<String, Long>>>() {
2641+
@Override
2642+
public int compare(Map.Entry<String, Map<String, Long>> o1,
2643+
Map.Entry<String, Map<String, Long>> o2) {
2644+
Map<String, Long> value1Map = o1.getValue();
2645+
Map<String, Long> value2Map = o2.getValue();
2646+
long compared = value2Map.getOrDefault(DataNode.NETWORK_ERRORS, 0L) -
2647+
value1Map.getOrDefault(DataNode.NETWORK_ERRORS, 0L);
2648+
return (int)compared;
2649+
}
2650+
});
2651+
Map<String, Map<String, Long>> resultMap = new ConcurrentHashMap<>();
2652+
maxDisplay = list.size() > maxDisplay ? maxDisplay : list.size();
2653+
for (int i = 0; i < maxDisplay; i++) {
2654+
resultMap.put(list.get(i).getKey(), list.get(i).getValue());
2655+
}
2656+
list.clear();
2657+
return resultMap;
26342658
}
26352659

26362660
void incrDatanodeNetworkErrors(String host) {

0 commit comments

Comments
 (0)