From 03bb40612e56b3061760095289368172795fdc08 Mon Sep 17 00:00:00 2001 From: yliu Date: Tue, 20 Oct 2015 11:31:14 +0800 Subject: [PATCH] HDFS-9208. Disabling atime may fail clients like distCp. (Kihwal Lee via yliu) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../hdfs/server/namenode/FSDirAttrOp.java | 8 ----- .../org/apache/hadoop/hdfs/TestSetTimes.java | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index dbd333a6ceb..a86750626bf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1254,6 +1254,9 @@ Release 2.8.0 - UNRELEASED HDFS-9237. NPE at TestDataNodeVolumeFailureToleration#tearDown. (Brahma Reddy Battula via ozawa) + HDFS-9208. Disabling atime may fail clients like distCp. (Kihwal Lee via + yliu) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java index df0bc2079ba..0a138f504cf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java @@ -42,7 +42,6 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.List; -import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_QUOTA_BY_STORAGETYPE_ENABLED_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY; @@ -97,13 +96,6 @@ public class FSDirAttrOp { static HdfsFileStatus setTimes( FSDirectory fsd, String src, long mtime, long atime) throws IOException { - if (!fsd.isAccessTimeSupported() && atime != -1) { - throw new IOException( - "Access time for hdfs is not configured. " + - " Please set " + DFS_NAMENODE_ACCESSTIME_PRECISION_KEY - + " configuration parameter."); - } - FSPermissionChecker pc = fsd.getPermissionChecker(); byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetTimes.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetTimes.java index 4e6091b8122..a90d139ab6a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetTimes.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSetTimes.java @@ -40,6 +40,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.test.MockitoUtil; import org.apache.hadoop.util.Time; +import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -309,6 +310,36 @@ public class TestSetTimes { } } + /** + * Test whether atime can be set explicitly even when the atime support is + * disabled. + */ + @Test + public void testAtimeUpdate() throws Exception { + Configuration conf = new HdfsConfiguration(); + conf.setInt(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, 0); + MiniDFSCluster cluster = null; + FileSystem fs = null; + + try { + cluster = new MiniDFSCluster.Builder(conf) + .numDataNodes(0) + .build(); + fs = cluster.getFileSystem(); + + // Create an empty file + Path p = new Path("/testAtimeUpdate"); + DFSTestUtil.createFile(cluster.getFileSystem(), p, 0, (short)1, 0L); + + fs.setTimes(p, -1L, 123456L); + Assert.assertEquals(123456L, fs.getFileStatus(p).getAccessTime()); + } finally { + if (cluster != null) { + cluster.shutdown(); + } + } + } + public static void main(String[] args) throws Exception { new TestSetTimes().testTimes(); }