svn merge -c 1190708 from trunk for HDFS-2436.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1190711 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-10-29 00:22:34 +00:00
parent 1d54c6e5a7
commit bf72abd737
5 changed files with 40 additions and 12 deletions

View File

@ -755,6 +755,9 @@ Release 0.23.0 - Unreleased
HDFS-2509. Add a test for DistributedFileSystem.getFileChecksum(..) on HDFS-2509. Add a test for DistributedFileSystem.getFileChecksum(..) on
directories or non existing files. (Uma Maheswara Rao G via szetszwo) directories or non existing files. (Uma Maheswara Rao G via szetszwo)
HDFS-2436. Change FSNamesystem.setTimes(..) for allowing setting times on
directories. (Uma Maheswara Rao G via szetszwo)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-1458. Improve checkpoint performance by avoiding unnecessary image HDFS-1458. Improve checkpoint performance by avoiding unnecessary image

View File

@ -1250,13 +1250,21 @@ public class FSDirectory implements Closeable {
* Get {@link INode} associated with the file. * Get {@link INode} associated with the file.
*/ */
INodeFile getFileINode(String src) throws UnresolvedLinkException { INodeFile getFileINode(String src) throws UnresolvedLinkException {
INode inode = getINode(src);
if (inode == null || inode.isDirectory())
return null;
assert !inode.isLink();
return (INodeFile) inode;
}
/**
* Get {@link INode} associated with the file / directory.
*/
INode getINode(String src) throws UnresolvedLinkException {
readLock(); readLock();
try { try {
INode inode = rootDir.getNode(src, true); INode iNode = rootDir.getNode(src, true);
if (inode == null || inode.isDirectory()) return iNode;
return null;
assert !inode.isLink();
return (INodeFile)inode;
} finally { } finally {
readUnlock(); readUnlock();
} }
@ -1991,9 +1999,9 @@ public class FSDirectory implements Closeable {
} }
/** /**
* Sets the access time on the file. Logs it in the transaction log. * Sets the access time on the file/directory. Logs it in the transaction log.
*/ */
void setTimes(String src, INodeFile inode, long mtime, long atime, boolean force) { void setTimes(String src, INode inode, long mtime, long atime, boolean force) {
boolean status = false; boolean status = false;
writeLock(); writeLock();
try { try {
@ -2009,11 +2017,11 @@ public class FSDirectory implements Closeable {
boolean unprotectedSetTimes(String src, long mtime, long atime, boolean force) boolean unprotectedSetTimes(String src, long mtime, long atime, boolean force)
throws UnresolvedLinkException { throws UnresolvedLinkException {
assert hasWriteLock(); assert hasWriteLock();
INodeFile inode = getFileINode(src); INode inode = getINode(src);
return unprotectedSetTimes(src, inode, mtime, atime, force); return unprotectedSetTimes(src, inode, mtime, atime, force);
} }
private boolean unprotectedSetTimes(String src, INodeFile inode, long mtime, private boolean unprotectedSetTimes(String src, INode inode, long mtime,
long atime, boolean force) { long atime, boolean force) {
assert hasWriteLock(); assert hasWriteLock();
boolean status = false; boolean status = false;

View File

@ -940,7 +940,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
if (isPermissionEnabled) { if (isPermissionEnabled) {
checkPathAccess(src, FsAction.WRITE); checkPathAccess(src, FsAction.WRITE);
} }
INodeFile inode = dir.getFileINode(src); INode inode = dir.getINode(src);
if (inode != null) { if (inode != null) {
dir.setTimes(src, inode, mtime, atime, true); dir.setTimes(src, inode, mtime, atime, true);
if (auditLog.isInfoEnabled() && isExternalInvocation()) { if (auditLog.isInfoEnabled() && isExternalInvocation()) {
@ -950,7 +950,7 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
"setTimes", src, null, stat); "setTimes", src, null, stat);
} }
} else { } else {
throw new FileNotFoundException("File " + src + " does not exist."); throw new FileNotFoundException("File/Directory " + src + " does not exist.");
} }
} finally { } finally {
writeUnlock(); writeUnlock();

View File

@ -304,7 +304,6 @@ public abstract class INode implements Comparable<byte[]>, FSInodeInfo {
* Always set the last modification time of inode. * Always set the last modification time of inode.
*/ */
void setModificationTimeForce(long modtime) { void setModificationTimeForce(long modtime) {
assert !isDirectory();
this.modificationTime = modtime; this.modificationTime = modtime;
} }

View File

@ -158,6 +158,24 @@ public class TestSetTimes extends TestCase {
assertTrue(atime2 == stat.getAccessTime()); assertTrue(atime2 == stat.getAccessTime());
assertTrue(mtime2 == mtime3); assertTrue(mtime2 == mtime3);
long mtime4 = System.currentTimeMillis() - (3600L * 1000L);
long atime4 = System.currentTimeMillis();
fileSys.setTimes(dir1, mtime4, atime4);
// check new modification time on file
stat = fileSys.getFileStatus(dir1);
assertTrue("Not matching the modification times", mtime4 == stat
.getModificationTime());
assertTrue("Not matching the access times", atime4 == stat
.getAccessTime());
Path nonExistingDir = new Path(dir1, "/nonExistingDir/");
try {
fileSys.setTimes(nonExistingDir, mtime4, atime4);
fail("Expecting FileNotFoundException");
} catch (FileNotFoundException e) {
assertTrue(e.getMessage().contains(
"File/Directory " + nonExistingDir.toString() + " does not exist."));
}
// shutdown cluster and restart // shutdown cluster and restart
cluster.shutdown(); cluster.shutdown();
try {Thread.sleep(2*MAX_IDLE_TIME);} catch (InterruptedException e) {} try {Thread.sleep(2*MAX_IDLE_TIME);} catch (InterruptedException e) {}