Skip to content

Commit

Permalink
HDFS-7638: Small fix and few refinements for FSN#truncate. (yliu)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-liu committed Jan 19, 2015
1 parent 5e5e35b commit 5a6c084
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Expand Up @@ -276,6 +276,8 @@ Trunk (Unreleased)

HDFS-7606. Fix potential NPE in INodeFile.getBlocks(). (Byron Wong via shv)

HDFS-7638: Small fix and few refinements for FSN#truncate. (yliu)

Release 2.7.0 - UNRELEASED

INCOMPATIBLE CHANGES
Expand Down
Expand Up @@ -1917,18 +1917,22 @@ boolean truncateInt(String srcArg, long newLength,
boolean res;
byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src);
writeLock();
BlocksMapUpdateInfo toRemoveBlocks = new BlocksMapUpdateInfo();
try {
checkOperation(OperationCategory.WRITE);
checkNameNodeSafeMode("Cannot truncate for " + src);
src = dir.resolvePath(pc, src, pathComponents);
res = truncateInternal(src, newLength, clientName,
clientMachine, mtime, pc);
stat = FSDirStatAndListingOp.getFileInfo(dir, src, false,
FSDirectory.isReservedRawName(src), true);
clientMachine, mtime, pc, toRemoveBlocks);
stat = dir.getAuditFileInfo(dir.getINodesInPath4Write(src, false));
} finally {
writeUnlock();
}
getEditLog().logSync();
if (!toRemoveBlocks.getToDeleteList().isEmpty()) {
removeBlocks(toRemoveBlocks);
toRemoveBlocks.clear();
}
logAuditEvent(true, "truncate", src, null, stat);
return res;
}
Expand All @@ -1939,17 +1943,17 @@ boolean truncateInt(String srcArg, long newLength,
*/
boolean truncateInternal(String src, long newLength,
String clientName, String clientMachine,
long mtime, FSPermissionChecker pc)
long mtime, FSPermissionChecker pc,
BlocksMapUpdateInfo toRemoveBlocks)
throws IOException, UnresolvedLinkException {
assert hasWriteLock();
INodesInPath iip = dir.getINodesInPath4Write(src, true);
if (isPermissionEnabled) {
dir.checkPathAccess(pc, iip, FsAction.WRITE);
}
INodeFile file = iip.getLastINode().asFile();
INodeFile file = INodeFile.valueOf(iip.getLastINode(), src);
// Opening an existing file for write. May need lease recovery.
recoverLeaseInternal(iip, src, clientName, clientMachine, false);
file = INodeFile.valueOf(iip.getLastINode(), src);
// Truncate length check.
long oldLength = file.computeFileSize();
if(oldLength == newLength) {
Expand All @@ -1961,9 +1965,8 @@ boolean truncateInternal(String src, long newLength,
", truncate size: " + newLength + ".");
}
// Perform INodeFile truncation.
BlocksMapUpdateInfo collectedBlocks = new BlocksMapUpdateInfo();
boolean onBlockBoundary = dir.truncate(iip, newLength,
collectedBlocks, mtime);
toRemoveBlocks, mtime);
Block truncateBlock = null;
if(! onBlockBoundary) {
// Open file for write, but don't log into edits
Expand All @@ -1974,7 +1977,6 @@ boolean truncateInternal(String src, long newLength,
}
getEditLog().logTruncate(src, clientName, clientMachine, newLength, mtime,
truncateBlock);
removeBlocks(collectedBlocks);
return onBlockBoundary;
}

Expand Down

0 comments on commit 5a6c084

Please sign in to comment.