HDFS-8164. cTime is 0 in VERSION file for newly formatted NameNode. Contributed by Xiao Chen.

(cherry picked from commit 1107bd399c)
This commit is contained in:
Yongjun Zhang 2015-10-07 23:20:10 -07:00
parent 22ed1471bd
commit aaf7b73fe4
4 changed files with 41 additions and 2 deletions

View File

@ -673,6 +673,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9170. Move libhdfs / fuse-dfs / libwebhdfs to hdfs-client. (wheat9) 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 OPTIMIZATIONS
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

View File

@ -1505,6 +1505,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. * Version of @see #getNamespaceInfo() that is not protected by a lock.
*/ */

View File

@ -573,7 +573,7 @@ public class NNStorage extends Storage implements Closeable,
public static NamespaceInfo newNamespaceInfo() public static NamespaceInfo newNamespaceInfo()
throws UnknownHostException { throws UnknownHostException {
return new NamespaceInfo(newNamespaceID(), newClusterID(), return new NamespaceInfo(newNamespaceID(), newClusterID(),
newBlockPoolID(), 0L); newBlockPoolID(), Time.now());
} }
public void format() throws IOException { public void format() throws IOException {

View File

@ -48,6 +48,7 @@ import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType;
import org.apache.hadoop.hdfs.util.MD5FileUtils; import org.apache.hadoop.hdfs.util.MD5FileUtils;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.PathUtils; import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.util.Time;
import org.junit.Test; import org.junit.Test;
public class TestFSImage { public class TestFSImage {
@ -233,6 +234,29 @@ 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 * 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 * preferredblockSize = 0. We are trying to read this image (since file with