HDFS-6328. Clean up dead code in FSDirectory. Contributed by Haohui Mai.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1593755 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Haohui Mai 2014-05-11 05:06:22 +00:00
parent 58c81d56e9
commit ae9109b911
2 changed files with 20 additions and 57 deletions

View File

@ -346,6 +346,8 @@ Release 2.5.0 - UNRELEASED
HDFS-6294. Use INode IDs to avoid conflicts when a file open for write is HDFS-6294. Use INode IDs to avoid conflicts when a file open for write is
renamed. (cmccabe) renamed. (cmccabe)
HDFS-6328. Clean up dead code in FSDirectory. (wheat9)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-6214. Webhdfs has poor throughput for files >2GB (daryn) HDFS-6214. Webhdfs has poor throughput for files >2GB (daryn)

View File

@ -275,7 +275,7 @@ void waitForReady() {
while (!ready) { while (!ready) {
try { try {
cond.await(5000, TimeUnit.MILLISECONDS); cond.await(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException ie) { } catch (InterruptedException ignored) {
} }
} }
} finally { } finally {
@ -722,9 +722,8 @@ boolean unprotectedRenameTo(String src, String dst, long timestamp)
} else { } else {
withCount.getReferredINode().setLocalName(dstChildName); withCount.getReferredINode().setLocalName(dstChildName);
int dstSnapshotId = dstIIP.getLatestSnapshotId(); int dstSnapshotId = dstIIP.getLatestSnapshotId();
final INodeReference.DstReference ref = new INodeReference.DstReference( toDst = new INodeReference.DstReference(
dstParent.asDirectory(), withCount, dstSnapshotId); dstParent.asDirectory(), withCount, dstSnapshotId);
toDst = ref;
} }
added = addLastINodeNoQuotaCheck(dstIIP, toDst); added = addLastINodeNoQuotaCheck(dstIIP, toDst);
@ -763,14 +762,12 @@ boolean unprotectedRenameTo(String src, String dst, long timestamp)
} else if (!srcChildIsReference) { // src must be in snapshot } else if (!srcChildIsReference) { // src must be in snapshot
// the withCount node will no longer be used thus no need to update // the withCount node will no longer be used thus no need to update
// its reference number here // its reference number here
final INode originalChild = withCount.getReferredINode(); srcChild = withCount.getReferredINode();
srcChild = originalChild;
srcChild.setLocalName(srcChildName); srcChild.setLocalName(srcChildName);
} else { } else {
withCount.removeReference(oldSrcChild.asReference()); withCount.removeReference(oldSrcChild.asReference());
final INodeReference originalRef = new INodeReference.DstReference( srcChild = new INodeReference.DstReference(
srcParent, withCount, srcRefDstSnapshot); srcParent, withCount, srcRefDstSnapshot);
srcChild = originalRef;
withCount.getReferredINode().setLocalName(srcChildName); withCount.getReferredINode().setLocalName(srcChildName);
} }
@ -813,7 +810,7 @@ boolean unprotectedRenameTo(String src, String dst, long timestamp,
} }
} }
} }
String error = null; final String error;
final INodesInPath srcIIP = getINodesInPath4Write(src, false); final INodesInPath srcIIP = getINodesInPath4Write(src, false);
final INode srcInode = srcIIP.getLastINode(); final INode srcInode = srcIIP.getLastINode();
// validate source // validate source
@ -980,9 +977,8 @@ boolean unprotectedRenameTo(String src, String dst, long timestamp,
} else { } else {
withCount.getReferredINode().setLocalName(dstChildName); withCount.getReferredINode().setLocalName(dstChildName);
int dstSnapshotId = dstIIP.getLatestSnapshotId(); int dstSnapshotId = dstIIP.getLatestSnapshotId();
final INodeReference.DstReference ref = new INodeReference.DstReference( toDst = new INodeReference.DstReference(
dstIIP.getINode(-2).asDirectory(), withCount, dstSnapshotId); dstIIP.getINode(-2).asDirectory(), withCount, dstSnapshotId);
toDst = ref;
} }
// add src as dst to complete rename // add src as dst to complete rename
@ -1043,14 +1039,12 @@ boolean unprotectedRenameTo(String src, String dst, long timestamp,
} else if (!srcChildIsReference) { // src must be in snapshot } else if (!srcChildIsReference) { // src must be in snapshot
// the withCount node will no longer be used thus no need to update // the withCount node will no longer be used thus no need to update
// its reference number here // its reference number here
final INode originalChild = withCount.getReferredINode(); srcChild = withCount.getReferredINode();
srcChild = originalChild;
srcChild.setLocalName(srcChildName); srcChild.setLocalName(srcChildName);
} else { } else {
withCount.removeReference(oldSrcChild.asReference()); withCount.removeReference(oldSrcChild.asReference());
final INodeReference originalRef = new INodeReference.DstReference( srcChild = new INodeReference.DstReference(
srcParent, withCount, srcRefDstSnapshot); srcParent, withCount, srcRefDstSnapshot);
srcChild = originalRef;
withCount.getReferredINode().setLocalName(srcChildName); withCount.getReferredINode().setLocalName(srcChildName);
} }
@ -1162,20 +1156,6 @@ long getPreferredBlockSize(String path) throws UnresolvedLinkException,
} }
} }
boolean exists(String src) throws UnresolvedLinkException {
src = normalizePath(src);
readLock();
try {
INode inode = getNode(src, false);
if (inode == null) {
return false;
}
return !inode.isFile() || inode.asFile().getBlocks() != null;
} finally {
readUnlock();
}
}
void setPermission(String src, FsPermission permission) void setPermission(String src, FsPermission permission)
throws FileNotFoundException, UnresolvedLinkException, throws FileNotFoundException, UnresolvedLinkException,
QuotaExceededException, SnapshotAccessControlException { QuotaExceededException, SnapshotAccessControlException {
@ -1669,21 +1649,6 @@ private INode getINode4DotSnapshot(String src) throws UnresolvedLinkException {
return null; return null;
} }
/**
* Get the blocks associated with the file.
*/
Block[] getFileBlocks(String src) throws UnresolvedLinkException {
waitForReady();
readLock();
try {
final INode i = getNode(src, false);
return i != null && i.isFile()? i.asFile().getBlocks(): null;
} finally {
readUnlock();
}
}
INodesInPath getExistingPathINodes(byte[][] components) INodesInPath getExistingPathINodes(byte[][] components)
throws UnresolvedLinkException { throws UnresolvedLinkException {
return INodesInPath.resolve(rootDir, components); return INodesInPath.resolve(rootDir, components);
@ -1745,12 +1710,8 @@ boolean isValidToCreate(String src) throws UnresolvedLinkException,
String srcs = normalizePath(src); String srcs = normalizePath(src);
readLock(); readLock();
try { try {
if (srcs.startsWith("/") && !srcs.endsWith("/") return srcs.startsWith("/") && !srcs.endsWith("/")
&& getINode4Write(srcs, false) == null) { && getINode4Write(srcs, false) == null;
return true;
} else {
return false;
}
} finally { } finally {
readUnlock(); readUnlock();
} }
@ -2003,7 +1964,7 @@ boolean mkdirs(String src, PermissionStatus permissions,
// create directories beginning from the first null index // create directories beginning from the first null index
for(; i < inodes.length; i++) { for(; i < inodes.length; i++) {
pathbuilder.append(Path.SEPARATOR + names[i]); pathbuilder.append(Path.SEPARATOR).append(names[i]);
unprotectedMkdir(namesystem.allocateNewInodeId(), iip, i, unprotectedMkdir(namesystem.allocateNewInodeId(), iip, i,
components[i], (i < lastInodeIndex) ? parentPermissions components[i], (i < lastInodeIndex) ? parentPermissions
: permissions, null, now); : permissions, null, now);
@ -2132,7 +2093,7 @@ private void verifyQuotaForRename(INode[] src, INode[] dst)
return; return;
} }
int i = 0; int i = 0;
for(; src[i] == dst[i]; i++); while(src[i] == dst[i]) { i++; }
// src[i - 1] is the last common ancestor. // src[i - 1] is the last common ancestor.
final Quota.Counts delta = src[src.length - 1].computeQuotaUsage(); final Quota.Counts delta = src[src.length - 1].computeQuotaUsage();
@ -2293,7 +2254,7 @@ private boolean addChild(INodesInPath iip, int pos,
counts.get(Quota.NAMESPACE), counts.get(Quota.DISKSPACE), checkQuota); counts.get(Quota.NAMESPACE), counts.get(Quota.DISKSPACE), checkQuota);
boolean isRename = (child.getParent() != null); boolean isRename = (child.getParent() != null);
final INodeDirectory parent = inodes[pos-1].asDirectory(); final INodeDirectory parent = inodes[pos-1].asDirectory();
boolean added = false; boolean added;
try { try {
added = parent.addChild(child, true, iip.getLatestSnapshotId()); added = parent.addChild(child, true, iip.getLatestSnapshotId());
} catch (QuotaExceededException e) { } catch (QuotaExceededException e) {
@ -2657,7 +2618,7 @@ private HdfsLocatedFileStatus createLocatedFileStatus(byte[] path,
blocksize = fileNode.getPreferredBlockSize(); blocksize = fileNode.getPreferredBlockSize();
final boolean inSnapshot = snapshot != Snapshot.CURRENT_STATE_ID; final boolean inSnapshot = snapshot != Snapshot.CURRENT_STATE_ID;
final boolean isUc = inSnapshot ? false : fileNode.isUnderConstruction(); final boolean isUc = !inSnapshot && fileNode.isUnderConstruction();
final long fileSize = !inSnapshot && isUc ? final long fileSize = !inSnapshot && isUc ?
fileNode.computeFileSizeNotIncludingLastUcBlock() : size; fileNode.computeFileSizeNotIncludingLastUcBlock() : size;
loc = getFSNamesystem().getBlockManager().createLocatedBlocks( loc = getFSNamesystem().getBlockManager().createLocatedBlocks(
@ -3011,7 +2972,7 @@ static String resolvePath(String src, byte[][] pathComponents, FSDirectory fsd)
return src; return src;
} }
final String inodeId = DFSUtil.bytes2String(pathComponents[3]); final String inodeId = DFSUtil.bytes2String(pathComponents[3]);
long id = 0; final long id;
try { try {
id = Long.parseLong(inodeId); id = Long.parseLong(inodeId);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {