HDFS-7638: Small fix and few refinements for FSN#truncate. (yliu)
This commit is contained in:
parent
5e5e35b185
commit
5a6c084f07
|
@ -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
|
||||
|
|
|
@ -1917,18 +1917,22 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|||
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;
|
||||
}
|
||||
|
@ -1939,17 +1943,17 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|||
*/
|
||||
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) {
|
||||
|
@ -1961,9 +1965,8 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|||
", 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
|
||||
|
@ -1974,7 +1977,6 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|||
}
|
||||
getEditLog().logTruncate(src, clientName, clientMachine, newLength, mtime,
|
||||
truncateBlock);
|
||||
removeBlocks(collectedBlocks);
|
||||
return onBlockBoundary;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue