Repository: hadoop Updated Branches: refs/heads/branch-2 22ed1471b -> aaf7b73fe
HDFS-8164. cTime is 0 in VERSION file for newly formatted NameNode. Contributed by Xiao Chen. (cherry picked from commit 1107bd399c790467b22e55291c2611fd1c16e156) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/aaf7b73f Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/aaf7b73f Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/aaf7b73f Branch: refs/heads/branch-2 Commit: aaf7b73fe474c332cefba943df50a1873b49bcb7 Parents: 22ed147 Author: Yongjun Zhang <[email protected]> Authored: Wed Oct 7 23:20:10 2015 -0700 Committer: Yongjun Zhang <[email protected]> Committed: Wed Oct 7 23:23:36 2015 -0700 ---------------------------------------------------------------------- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/namenode/FSNamesystem.java | 12 +++++++++ .../hadoop/hdfs/server/namenode/NNStorage.java | 2 +- .../hdfs/server/namenode/TestFSImage.java | 26 +++++++++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/aaf7b73f/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 756052c..97a50bc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -673,6 +673,9 @@ Release 2.8.0 - UNRELEASED HDFS-9170. Move libhdfs / fuse-dfs / libwebhdfs to hdfs-client. (wheat9) + HDFS-8164. cTime is 0 in VERSION file for newly formatted NameNode. + (Xiao Chen via Yongjun Zhang) + OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than http://git-wip-us.apache.org/repos/asf/hadoop/blob/aaf7b73f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index bcdcc33..9dc9d42 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -1506,6 +1506,18 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean, } /** + * Get the creation time of the file system. + * Notice that this time is initialized to NameNode format time, and updated + * to upgrade time during upgrades. + * @return time in milliseconds. + * See {@link org.apache.hadoop.util.Time#now()}. + */ + @VisibleForTesting + long getCTime() { + return fsImage == null ? 0 : fsImage.getStorage().getCTime(); + } + + /** * Version of @see #getNamespaceInfo() that is not protected by a lock. */ NamespaceInfo unprotectedGetNamespaceInfo() { http://git-wip-us.apache.org/repos/asf/hadoop/blob/aaf7b73f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java index 14647f0..d872c03 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NNStorage.java @@ -573,7 +573,7 @@ public class NNStorage extends Storage implements Closeable, public static NamespaceInfo newNamespaceInfo() throws UnknownHostException { return new NamespaceInfo(newNamespaceID(), newClusterID(), - newBlockPoolID(), 0L); + newBlockPoolID(), Time.now()); } public void format() throws IOException { http://git-wip-us.apache.org/repos/asf/hadoop/blob/aaf7b73f/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java index df20fd6..ebfc2ed 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImage.java @@ -48,6 +48,7 @@ import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType; import org.apache.hadoop.hdfs.util.MD5FileUtils; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.PathUtils; +import org.apache.hadoop.util.Time; import org.junit.Test; public class TestFSImage { @@ -232,7 +233,30 @@ public class TestFSImage { } } } - + + /** + * Ensure ctime is set during namenode formatting. + */ + @Test(timeout=60000) + public void testCtime() throws Exception { + Configuration conf = new Configuration(); + MiniDFSCluster cluster = null; + try { + final long pre = Time.now(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); + cluster.waitActive(); + final long post = Time.now(); + final long ctime = cluster.getNamesystem().getCTime(); + + assertTrue(pre <= ctime); + assertTrue(ctime <= post); + } finally { + if (cluster != null) { + cluster.shutdown(); + } + } + } + /** * In this test case, I have created an image with a file having * preferredblockSize = 0. We are trying to read this image (since file with
