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 @@ public class FSDirectory implements Closeable {
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 @@ public class FSDirectory implements Closeable {
} 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 @@ public class FSDirectory implements Closeable {
} 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 @@ public class FSDirectory implements Closeable {
} }
} }
} }
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 @@ public class FSDirectory implements Closeable {
} 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 @@ public class FSDirectory implements Closeable {
} 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 @@ public class FSDirectory implements Closeable {
} }
} }
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 {
@ -1590,7 +1570,7 @@ public class FSDirectory implements Closeable {
throws UnresolvedLinkException, IOException { throws UnresolvedLinkException, IOException {
Preconditions.checkState(hasReadLock()); Preconditions.checkState(hasReadLock());
Preconditions.checkArgument( Preconditions.checkArgument(
src.endsWith(HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR), src.endsWith(HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR),
"%s does not end with %s", src, HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR); "%s does not end with %s", src, HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR);
final String dirPath = normalizePath(src.substring(0, final String dirPath = normalizePath(src.substring(0,
@ -1654,7 +1634,7 @@ public class FSDirectory implements Closeable {
private INode getINode4DotSnapshot(String src) throws UnresolvedLinkException { private INode getINode4DotSnapshot(String src) throws UnresolvedLinkException {
Preconditions.checkArgument( Preconditions.checkArgument(
src.endsWith(HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR), src.endsWith(HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR),
"%s does not end with %s", src, HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR); "%s does not end with %s", src, HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR);
final String dirPath = normalizePath(src.substring(0, final String dirPath = normalizePath(src.substring(0,
@ -1669,21 +1649,6 @@ public class FSDirectory implements Closeable {
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);
@ -1708,7 +1673,7 @@ public class FSDirectory implements Closeable {
readUnlock(); readUnlock();
} }
} }
/** /**
* Get {@link INode} associated with the file / directory. * Get {@link INode} associated with the file / directory.
*/ */
@ -1745,12 +1710,8 @@ public class FSDirectory implements Closeable {
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 @@ public class FSDirectory implements Closeable {
// 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 @@ public class FSDirectory implements Closeable {
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 @@ public class FSDirectory implements Closeable {
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 @@ public class FSDirectory implements Closeable {
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 @@ public class FSDirectory implements Closeable {
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) {