diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index f07c16f3f5c..a2b8e89c490 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -578,6 +578,9 @@ Release 2.4.1 - UNRELEASED HDFS-6325. Append should fail if the last block has insufficient number of replicas (Keith Pak via cos) + HDFS-6397. NN shows inconsistent value in deadnode count. + (Mohammad Kamrul Islam via kihwal) + Release 2.4.0 - 2014-04-07 INCOMPATIBLE CHANGES 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 c73b012eedb..8efaa886a81 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 @@ -1057,15 +1057,7 @@ public class DatanodeManager { /** @return the number of dead datanodes. */ public int getNumDeadDataNodes() { - int numDead = 0; - synchronized (datanodeMap) { - for(DatanodeDescriptor dn : datanodeMap.values()) { - if (isDatanodeDead(dn) ) { - numDead++; - } - } - } - return numDead; + return getDatanodeListForReport(DatanodeReportType.DEAD).size(); } /** @return list of datanodes where decommissioning is in progress. */ diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestHostsFiles.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestHostsFiles.java index c7c6500c8b8..1806d82de0b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestHostsFiles.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestHostsFiles.java @@ -129,4 +129,44 @@ public class TestHostsFiles { cluster.shutdown(); } } + + @Test + public void testHostsIncludeForDeadCount() throws Exception { + Configuration conf = getConf(); + + // Configure an excludes file + FileSystem localFileSys = FileSystem.getLocal(conf); + Path workingDir = localFileSys.getWorkingDirectory(); + Path dir = new Path(workingDir, "build/test/data/temp/decommission"); + Path excludeFile = new Path(dir, "exclude"); + Path includeFile = new Path(dir, "include"); + assertTrue(localFileSys.mkdirs(dir)); + StringBuilder includeHosts = new StringBuilder(); + includeHosts.append("localhost:52").append("\n").append("127.0.0.1:7777") + .append("\n"); + DFSTestUtil.writeFile(localFileSys, excludeFile, ""); + DFSTestUtil.writeFile(localFileSys, includeFile, includeHosts.toString()); + conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath()); + conf.set(DFSConfigKeys.DFS_HOSTS, includeFile.toUri().getPath()); + + MiniDFSCluster cluster = null; + try { + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); + final FSNamesystem ns = cluster.getNameNode().getNamesystem(); + assertTrue(ns.getNumDeadDataNodes() == 2); + assertTrue(ns.getNumLiveDataNodes() == 0); + + // Testing using MBeans + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + ObjectName mxbeanName = new ObjectName( + "Hadoop:service=NameNode,name=FSNamesystemState"); + String nodes = mbs.getAttribute(mxbeanName, "NumDeadDataNodes") + ""; + assertTrue((Integer) mbs.getAttribute(mxbeanName, "NumDeadDataNodes") == 2); + assertTrue((Integer) mbs.getAttribute(mxbeanName, "NumLiveDataNodes") == 0); + } finally { + if (cluster != null) { + cluster.shutdown(); + } + } + } }