From d2b5531b0f034cbcde4f6dfaaba463b347fbc60b Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Fri, 3 Feb 2012 03:10:57 +0000 Subject: [PATCH] HDFS-2769. HA: When HA is enabled with a shared edits dir, that dir should be marked required. Contributed by Aaron T. Myers. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1239988 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-1623.txt | 3 ++ .../hdfs/server/namenode/FSNamesystem.java | 14 +++++++-- .../namenode/ha/TestFailureOfSharedDir.java | 29 +++++++++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt index e95eb5c94e6..9e24b2071fd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt @@ -155,3 +155,6 @@ HDFS-2859. LOCAL_ADDRESS_MATCHER.match has NPE when called from DFSUtil.getSuffi HDFS-2861. checkpointing should verify that the dfs.http.address has been configured to a non-loopback for peer NN (todd) HDFS-2860. TestDFSRollback#testRollback is failing. (atm) + +HDFS-2769. HA: When HA is enabled with a shared edits dir, that dir should be +marked required. (atm via eli) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java index b49005ff144..7754a9085b2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java @@ -632,9 +632,19 @@ void checkOperation(OperationCategory op) throws StandbyException { public static Collection getNamespaceDirs(Configuration conf) { return getStorageDirs(conf, DFS_NAMENODE_NAME_DIR_KEY); } - + + /** + * Get all edits dirs which are required. If any shared edits dirs are + * configured, these are also included in the set of required dirs. + * + * @param conf the HDFS configuration. + * @return all required dirs. + */ public static Collection getRequiredNamespaceEditsDirs(Configuration conf) { - return getStorageDirs(conf, DFS_NAMENODE_EDITS_DIR_REQUIRED_KEY); + Set ret = new HashSet(); + ret.addAll(getStorageDirs(conf, DFS_NAMENODE_EDITS_DIR_REQUIRED_KEY)); + ret.addAll(getSharedEditsDirs(conf)); + return ret; } private static Collection getStorageDirs(Configuration conf, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureOfSharedDir.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureOfSharedDir.java index 20c93b7e734..1fad704dc45 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureOfSharedDir.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureOfSharedDir.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.util.Collection; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -33,14 +34,38 @@ import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSNNTopology; +import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; +import com.google.common.base.Joiner; + public class TestFailureOfSharedDir { private static final Log LOG = LogFactory.getLog(TestFailureOfSharedDir.class); + /** + * Test that the shared edits dir is automatically added to the list of edits + * dirs that are marked required. + */ + @Test + public void testSharedDirIsAutomaticallyMarkedRequired() + throws URISyntaxException { + URI foo = new URI("file:/foo"); + URI bar = new URI("file:/bar"); + Configuration conf = new Configuration(); + conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, Joiner.on(",").join(foo, bar)); + conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_REQUIRED_KEY, foo.toString()); + assertFalse(FSNamesystem.getRequiredNamespaceEditsDirs(conf).contains( + bar)); + conf.set(DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY, bar.toString()); + Collection requiredEditsDirs = FSNamesystem + .getRequiredNamespaceEditsDirs(conf); + assertTrue(Joiner.on(",").join(requiredEditsDirs) + " does not contain " + bar, + requiredEditsDirs.contains(bar)); + } + /** * Test that marking the shared edits dir as being "required" causes the NN to * fail if that dir can't be accessed. @@ -48,11 +73,9 @@ public class TestFailureOfSharedDir { @Test public void testFailureOfSharedDir() throws Exception { Configuration conf = new Configuration(); + // The shared edits dir will automatically be marked required. URI sharedEditsUri = MiniDFSCluster.formatSharedEditsDir( new File(MiniDFSCluster.getBaseDirectory()), 0, 1); - // Mark the shared edits dir required. - conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_REQUIRED_KEY, - sharedEditsUri.toString()); MiniDFSCluster cluster = null; try {