Repository: hadoop Updated Branches: refs/heads/branch-2 bb5dd7f77 -> 8726a5e02
HDFS-9396. Total files and directories on jmx and web UI on standby is uninitialized. Contributed by Kihwal Lee. (cherry picked from commit a2a104f3d30182953db6690304146f0a582ed241) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8726a5e0 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8726a5e0 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8726a5e0 Branch: refs/heads/branch-2 Commit: 8726a5e02004bc5c7e30acb39982c23b09eaec10 Parents: bb5dd7f Author: Kihwal Lee <kih...@apache.org> Authored: Wed Nov 11 15:37:11 2015 -0600 Committer: Kihwal Lee <kih...@apache.org> Committed: Wed Nov 11 15:37:11 2015 -0600 ---------------------------------------------------------------------- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../hdfs/server/namenode/FSDirectory.java | 8 +-- .../hdfs/server/namenode/ha/TestHAMetrics.java | 56 ++++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/8726a5e0/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 87585d8..b3d73b1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1444,6 +1444,9 @@ Release 2.8.0 - UNRELEASED HDFS-9245. Fix findbugs warnings in hdfs-nfs/WriteCtx. (Mingliang Liu via xyao) + HDFS-9396. Total files and directories on jmx and web UI on standby is + uninitialized. (kihwal) + Release 2.7.3 - UNRELEASED INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/hadoop/blob/8726a5e0/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java index 0df6053..52b2616 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java @@ -1218,13 +1218,7 @@ public class FSDirectory implements Closeable { } long totalInodes() { - readLock(); - try { - return rootDir.getDirectoryWithQuotaFeature().getSpaceConsumed() - .getNameSpace(); - } finally { - readUnlock(); - } + return getInodeMapSize(); } /** http://git-wip-us.apache.org/repos/asf/hadoop/blob/8726a5e0/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java index 6f9fc6e..432f7df 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAMetrics.java @@ -24,8 +24,10 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; +import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSNNTopology; +import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.io.IOUtils; import org.junit.Test; @@ -119,4 +121,58 @@ public class TestHAMetrics { cluster.shutdown(); } } + + @Test + public void testHAInodeCount() throws Exception { + Configuration conf = new Configuration(); + conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); + conf.setInt(DFSConfigKeys.DFS_HA_LOGROLL_PERIOD_KEY, Integer.MAX_VALUE); + + MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) + .nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes(1) + .build(); + FileSystem fs = null; + try { + cluster.waitActive(); + + FSNamesystem nn0 = cluster.getNamesystem(0); + FSNamesystem nn1 = cluster.getNamesystem(1); + + cluster.transitionToActive(0); + fs = HATestUtil.configureFailoverFs(cluster, conf); + DFSTestUtil.createFile(fs, new Path("/testHAInodeCount1"), + 10, (short)1, 1L); + DFSTestUtil.createFile(fs, new Path("/testHAInodeCount2"), + 10, (short)1, 1L); + DFSTestUtil.createFile(fs, new Path("/testHAInodeCount3"), + 10, (short)1, 1L); + DFSTestUtil.createFile(fs, new Path("/testHAInodeCount4"), + 10, (short)1, 1L); + + // 1 dir and 4 files + assertEquals(5, nn0.getFilesTotal()); + // The SBN still has one dir, which is "/". + assertEquals(1, nn1.getFilesTotal()); + + // Save fsimage so that nn does not build up namesystem by replaying + // edits, but load from the image. + ((DistributedFileSystem)fs).setSafeMode(SafeModeAction.SAFEMODE_ENTER); + ((DistributedFileSystem)fs).saveNamespace(); + + // Flip the two namenodes and restart the standby, which will load + // the fsimage. + cluster.transitionToStandby(0); + cluster.transitionToActive(1); + cluster.restartNameNode(0); + assertEquals(nn0.getHAState(), "standby"); + + // The restarted standby should report the correct count + nn0 = cluster.getNamesystem(0); + assertEquals(5, nn0.getFilesTotal()); + } finally { + IOUtils.cleanup(LOG, fs); + cluster.shutdown(); + } + + } }