svn merge -c 1409311 FIXES: HDFS-4182. SecondaryNameNode leaks NameCache entries (bobby)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1409316 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Joseph Evans 2012-11-14 19:29:17 +00:00
parent 8ca6059743
commit d0a66f405f
5 changed files with 41 additions and 3 deletions

View File

@ -1726,6 +1726,8 @@ Release 0.23.5 - UNRELEASED
HDFS-4172. namenode does not URI-encode parameters when building URI for HDFS-4172. namenode does not URI-encode parameters when building URI for
datanode request (Derek Dagit via bobby) datanode request (Derek Dagit via bobby)
HDFS-4182. SecondaryNameNode leaks NameCache entries (bobby)
Release 0.23.4 - UNRELEASED Release 0.23.4 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -59,6 +59,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.BlockUCState;
import org.apache.hadoop.hdfs.util.ByteArray; import org.apache.hadoop.hdfs.util.ByteArray;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
/************************************************* /*************************************************
@ -174,6 +175,12 @@ public class FSDirectory implements Closeable {
} }
} }
//This is for testing purposes only
@VisibleForTesting
boolean isReady() {
return ready;
}
// exposed for unit tests // exposed for unit tests
protected void setReady(boolean flag) { protected void setReady(boolean flag) {
ready = flag; ready = flag;
@ -2003,9 +2010,16 @@ public class FSDirectory implements Closeable {
* Reset the entire namespace tree. * Reset the entire namespace tree.
*/ */
void reset() { void reset() {
writeLock();
try {
setReady(false);
rootDir = new INodeDirectoryWithQuota(INodeDirectory.ROOT_NAME, rootDir = new INodeDirectoryWithQuota(INodeDirectory.ROOT_NAME,
getFSNamesystem().createFsOwnerPermissions(new FsPermission((short)0755)), getFSNamesystem().createFsOwnerPermissions(new FsPermission((short)0755)),
Integer.MAX_VALUE, -1); Integer.MAX_VALUE, -1);
nameCache.reset();
} finally {
writeUnlock();
}
} }
/** /**

View File

@ -152,4 +152,14 @@ class NameCache<K> {
cache.put(name, name); cache.put(name, name);
lookups += useThreshold; lookups += useThreshold;
} }
public void reset() {
initialized = false;
cache.clear();
if (transientMap == null) {
transientMap = new HashMap<K, UseCount>();
} else {
transientMap.clear();
}
}
} }

View File

@ -886,6 +886,7 @@ public class SecondaryNameNode implements Runnable {
"just been downloaded"); "just been downloaded");
} }
dstImage.reloadFromImageFile(file, dstNamesystem); dstImage.reloadFromImageFile(file, dstNamesystem);
dstNamesystem.dir.imageLoadComplete();
} }
Checkpointer.rollForwardByApplyingLogs(manifest, dstImage, dstNamesystem); Checkpointer.rollForwardByApplyingLogs(manifest, dstImage, dstNamesystem);

View File

@ -58,6 +58,17 @@ public class TestNameCache {
for (String s : notMatching) { for (String s : notMatching) {
verifyNameReuse(cache, s, false); verifyNameReuse(cache, s, false);
} }
cache.reset();
cache.initialized();
for (String s : matching) {
verifyNameReuse(cache, s, false);
}
for (String s : notMatching) {
verifyNameReuse(cache, s, false);
}
} }
private void verifyNameReuse(NameCache<String> cache, String s, boolean reused) { private void verifyNameReuse(NameCache<String> cache, String s, boolean reused) {