From 05151ecf79a5d3dff38fe738a3e5be9f3c253b86 Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Wed, 15 Feb 2012 22:19:12 +0000 Subject: [PATCH] HDFS-2934. Allow configs to be scoped to all NNs in the nameservice. Contributed by Todd Lipcon. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1244759 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES.HDFS-1623.txt | 2 ++ .../java/org/apache/hadoop/hdfs/DFSUtil.java | 10 +++++- .../org/apache/hadoop/hdfs/TestDFSUtil.java | 33 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt index 6a3d45bdc2..de3ba8c18c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-1623.txt @@ -204,3 +204,5 @@ HDFS-2942. TestActiveStandbyElectorRealZK fails if build dir does not exist. (at HDFS-2948. NN throws NPE during shutdown if it fails to startup (todd) HDFS-2909. HA: Inaccessible shared edits dir not getting removed from FSImage storage dirs upon error. (Bikas Saha via jitendra) + +HDFS-2934. Allow configs to be scoped to all NNs in the nameservice. (todd) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java index c56a6ad387..1c7afd40ba 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java @@ -746,7 +746,10 @@ public class DFSUtil { /** * Sets the node specific setting into generic configuration key. Looks up * value of "key.nameserviceId.namenodeId" and if found sets that value into - * generic key in the conf. Note that this only modifies the runtime conf. + * generic key in the conf. If this is not found, falls back to + * "key.nameserviceId" and then the unmodified key. + * + * Note that this only modifies the runtime conf. * * @param conf * Configuration object to lookup specific key and to set the value @@ -764,6 +767,11 @@ public class DFSUtil { String nameserviceId, String nnId, String... keys) { for (String key : keys) { String value = conf.get(addKeySuffixes(key, nameserviceId, nnId)); + if (value != null) { + conf.set(key, value); + continue; + } + value = conf.get(addKeySuffixes(key, nameserviceId)); if (value != null) { conf.set(key, value); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java index 5b67cf5491..e49bb107e2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java @@ -325,6 +325,39 @@ public class TestDFSUtil { } } + /** + * Regression test for HDFS-2934. + */ + @Test + public void testSomeConfsNNSpecificSomeNSSpecific() { + final HdfsConfiguration conf = new HdfsConfiguration(); + + String key = DFSConfigKeys.DFS_NAMENODE_SHARED_EDITS_DIR_KEY; + conf.set(key, "global-default"); + conf.set(key + ".ns1", "ns1-override"); + conf.set(key + ".ns1.nn1", "nn1-override"); + + // A namenode in another nameservice should get the global default. + Configuration newConf = new Configuration(conf); + NameNode.initializeGenericKeys(newConf, "ns2", "nn1"); + assertEquals("global-default", newConf.get(key)); + + // A namenode in another non-HA nameservice should get global default. + newConf = new Configuration(conf); + NameNode.initializeGenericKeys(newConf, "ns2", null); + assertEquals("global-default", newConf.get(key)); + + // A namenode in the same nameservice should get the ns setting + newConf = new Configuration(conf); + NameNode.initializeGenericKeys(newConf, "ns1", "nn2"); + assertEquals("ns1-override", newConf.get(key)); + + // The nn with the nn-specific setting should get its own override + newConf = new Configuration(conf); + NameNode.initializeGenericKeys(newConf, "ns1", "nn1"); + assertEquals("nn1-override", newConf.get(key)); + } + /** * Tests for empty configuration, an exception is thrown from * {@link DFSUtil#getNNServiceRpcAddresses(Configuration)}