From 30cb540b4dd05af15aabe28c8426a52a9ead364b Mon Sep 17 00:00:00 2001 From: Kihwal Lee Date: Fri, 8 May 2015 15:20:14 -0500 Subject: [PATCH] HDFS-7433. Optimize performance of DatanodeManager's node map. Contributed by Daryn Sharp. (cherry picked from commit 7a7960be41c32f20ffec9fea811878b113da62db) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../server/blockmanagement/DatanodeManager.java | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 787f309da2b..e27954a3886 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -205,6 +205,9 @@ Release 2.8.0 - UNRELEASED HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than DFSOutputStream#writeChunk (cmccabe) + HDFS-7433. Optimize performance of DatanodeManager's node map. + (daryn via kihwal) + BUG FIXES HDFS-8091: ACLStatus and XAttributes should be presented to diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java index 808ee7598a7..5c3e79805fd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/DatanodeManager.java @@ -40,7 +40,6 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.Namesystem; import org.apache.hadoop.hdfs.server.protocol.*; import org.apache.hadoop.hdfs.server.protocol.BlockRecoveryCommand.RecoveringBlock; -import org.apache.hadoop.hdfs.util.CyclicIteration; import org.apache.hadoop.ipc.Server; import org.apache.hadoop.net.*; import org.apache.hadoop.net.NetworkTopology.InvalidTopologyException; @@ -84,8 +83,8 @@ public class DatanodeManager { *

* Mapping: StorageID -> DatanodeDescriptor */ - private final NavigableMap datanodeMap - = new TreeMap(); + private final Map datanodeMap + = new HashMap(); /** Cluster network topology */ private final NetworkTopology networktopology; @@ -405,11 +404,6 @@ public class DatanodeManager { } } - CyclicIteration getDatanodeCyclicIteration( - final String firstkey) { - return new CyclicIteration( - datanodeMap, firstkey); - } /** @return the datanode descriptor for the host. */ public DatanodeDescriptor getDatanodeByHost(final String host) { @@ -526,9 +520,10 @@ public class DatanodeManager { /** Prints information about all datanodes. */ void datanodeDump(final PrintWriter out) { synchronized (datanodeMap) { + Map sortedDatanodeMap = + new TreeMap(datanodeMap); out.println("Metasave: Number of datanodes: " + datanodeMap.size()); - for(Iterator it = datanodeMap.values().iterator(); it.hasNext();) { - DatanodeDescriptor node = it.next(); + for (DatanodeDescriptor node : sortedDatanodeMap.values()) { out.println(node.dumpDatanode()); } } @@ -1288,6 +1283,7 @@ public class DatanodeManager { foundNodes.add(HostFileManager.resolvedAddressFromDatanodeID(dn)); } } + Collections.sort(nodes); if (listDeadNodes) { for (InetSocketAddress addr : includedNodes) {