From d0a66f405f7140e22199ce129885a0ad097b0ed9 Mon Sep 17 00:00:00 2001 From: Robert Joseph Evans Date: Wed, 14 Nov 2012 19:29:17 +0000 Subject: [PATCH] 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 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ .../hdfs/server/namenode/FSDirectory.java | 20 ++++++++++++++++--- .../hdfs/server/namenode/NameCache.java | 10 ++++++++++ .../server/namenode/SecondaryNameNode.java | 1 + .../hdfs/server/namenode/TestNameCache.java | 11 ++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 45ae0691c67..d511db5f08c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1726,6 +1726,8 @@ Release 0.23.5 - UNRELEASED HDFS-4172. namenode does not URI-encode parameters when building URI for datanode request (Derek Dagit via bobby) + HDFS-4182. SecondaryNameNode leaks NameCache entries (bobby) + Release 0.23.4 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java index ef9ab48d262..4d2888db24b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java @@ -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.util.ByteArray; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; /************************************************* @@ -173,6 +174,12 @@ public class FSDirectory implements Closeable { writeUnlock(); } } + + //This is for testing purposes only + @VisibleForTesting + boolean isReady() { + return ready; + } // exposed for unit tests protected void setReady(boolean flag) { @@ -2003,9 +2010,16 @@ public class FSDirectory implements Closeable { * Reset the entire namespace tree. */ void reset() { - rootDir = new INodeDirectoryWithQuota(INodeDirectory.ROOT_NAME, - getFSNamesystem().createFsOwnerPermissions(new FsPermission((short)0755)), - Integer.MAX_VALUE, -1); + writeLock(); + try { + setReady(false); + rootDir = new INodeDirectoryWithQuota(INodeDirectory.ROOT_NAME, + getFSNamesystem().createFsOwnerPermissions(new FsPermission((short)0755)), + Integer.MAX_VALUE, -1); + nameCache.reset(); + } finally { + writeUnlock(); + } } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameCache.java index 59c0a30b07f..cf4f9a739da 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameCache.java @@ -152,4 +152,14 @@ class NameCache { cache.put(name, name); lookups += useThreshold; } + + public void reset() { + initialized = false; + cache.clear(); + if (transientMap == null) { + transientMap = new HashMap(); + } else { + transientMap.clear(); + } + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java index 9b1b9fcab58..cd6227397ba 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SecondaryNameNode.java @@ -886,6 +886,7 @@ public class SecondaryNameNode implements Runnable { "just been downloaded"); } dstImage.reloadFromImageFile(file, dstNamesystem); + dstNamesystem.dir.imageLoadComplete(); } Checkpointer.rollForwardByApplyingLogs(manifest, dstImage, dstNamesystem); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameCache.java index 8d635f63bc0..e32e77e3519 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameCache.java @@ -58,6 +58,17 @@ public class TestNameCache { for (String s : notMatching) { 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 cache, String s, boolean reused) {