HDFS-9208. Disabling atime may fail clients like distCp. (Kihwal Lee via yliu)

This commit is contained in:
yliu 2015-10-20 11:33:04 +08:00
parent 7e2837f830
commit 9cb5d35353
3 changed files with 34 additions and 8 deletions

View File

@ -2081,6 +2081,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9237. NPE at TestDataNodeVolumeFailureToleration#tearDown. HDFS-9237. NPE at TestDataNodeVolumeFailureToleration#tearDown.
(Brahma Reddy Battula via ozawa) (Brahma Reddy Battula via ozawa)
HDFS-9208. Disabling atime may fail clients like distCp. (Kihwal Lee via
yliu)
Release 2.7.2 - UNRELEASED Release 2.7.2 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -42,7 +42,6 @@
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; 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_QUOTA_BY_STORAGETYPE_ENABLED_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY;
@ -97,13 +96,6 @@ static HdfsFileStatus setOwner(
static HdfsFileStatus setTimes( static HdfsFileStatus setTimes(
FSDirectory fsd, String src, long mtime, long atime) FSDirectory fsd, String src, long mtime, long atime)
throws IOException { 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(); FSPermissionChecker pc = fsd.getPermissionChecker();
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src); byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);

View File

@ -40,6 +40,7 @@
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.test.MockitoUtil; import org.apache.hadoop.test.MockitoUtil;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -309,6 +310,36 @@ public void testGetBlockLocationsOnlyUsesReadLock() throws IOException {
} }
} }
/**
* 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 { public static void main(String[] args) throws Exception {
new TestSetTimes().testTimes(); new TestSetTimes().testTimes();
} }