Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS-14529. SetTimes to throw FileNotFoundException if inode is not found #3243

Merged
merged 3 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ static FileStatus setTimes(
if (fsd.isPermissionEnabled()) {
fsd.checkPathAccess(pc, iip, FsAction.WRITE);
}
final INode inode = iip.getLastINode();
if (inode == null) {
throw new FileNotFoundException("File/Directory " + iip.getPath() +
" does not exist.");
}
boolean changed = unprotectedSetTimes(fsd, iip, mtime, atime, true);
if (changed) {
fsd.getEditLog().logTimes(iip.getPath(), mtime, atime);
Expand Down Expand Up @@ -305,7 +300,7 @@ static boolean unprotectedSetOwner(

static boolean setTimes(
FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force)
throws QuotaExceededException {
throws QuotaExceededException, FileNotFoundException {
fsd.writeLock();
try {
return unprotectedSetTimes(fsd, iip, mtime, atime, force);
Expand Down Expand Up @@ -497,10 +492,14 @@ private static void setDirStoragePolicy(

static boolean unprotectedSetTimes(
FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force)
throws QuotaExceededException {
throws QuotaExceededException, FileNotFoundException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: looks like throwing QuotaExceededException is redundant here

assert fsd.hasWriteLock();
boolean status = false;
INode inode = iip.getLastINode();
if (inode == null) {
throw new FileNotFoundException("File/Directory " + iip.getPath() +
" does not exist.");
}
int latest = iip.getLatestSnapshotId();
if (mtime >= 0) {
inode = inode.setModificationTime(mtime, latest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.junit.Test;
import org.mockito.Mockito;

import java.io.FileNotFoundException;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
Expand All @@ -40,7 +42,8 @@ public class TestFSDirAttrOp {
LoggerFactory.getLogger(TestFSDirAttrOp.class);

private boolean unprotectedSetTimes(long atime, long atime0, long precision,
long mtime, boolean force) throws QuotaExceededException {
long mtime, boolean force)
throws QuotaExceededException, FileNotFoundException {
FSNamesystem fsn = Mockito.mock(FSNamesystem.class);
SnapshotManager ssMgr = Mockito.mock(SnapshotManager.class);
FSDirectory fsd = Mockito.mock(FSDirectory.class);
Expand Down Expand Up @@ -131,4 +134,16 @@ public void testUnprotectedSetTimes() throws Exception {
assertTrue("SetTimes should update access time",
unprotectedSetTimes(100, 0, 1000, 1, false));
}

@Test(expected = FileNotFoundException.class)
public void testUnprotectedSetTimesFNFE()
throws QuotaExceededException, FileNotFoundException {
FSDirectory fsd = Mockito.mock(FSDirectory.class);
INodesInPath iip = Mockito.mock(INodesInPath.class);

when(fsd.hasWriteLock()).thenReturn(Boolean.TRUE);
when(iip.getLastINode()).thenReturn(null);

FSDirAttrOp.unprotectedSetTimes(fsd, iip, 0, 0, false);
}
}