From c012b09fb678db11a10d0a8e1f64ee1a7229a417 Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Wed, 16 Jan 2019 18:06:17 +0530 Subject: [PATCH] HDFS-14193. RBF: Inconsistency with the Default Namespace. Contributed by Ayush Saxena. --- .../resolver/MountTableResolver.java | 27 ++++------------ .../TestInitializeMountTableResolver.java | 32 ++++++------------- 2 files changed, 16 insertions(+), 43 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java index 9e69840af9..da585515c3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java @@ -17,8 +17,6 @@ */ package org.apache.hadoop.hdfs.server.federation.resolver; -import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_NAMESERVICES; -import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DeprecatedKeys.DFS_NAMESERVICE_ID; import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE; import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE; import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT; @@ -50,8 +48,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hdfs.DFSUtil; -import org.apache.hadoop.hdfs.DFSUtilClient; import org.apache.hadoop.hdfs.server.federation.resolver.order.DestinationOrder; import org.apache.hadoop.hdfs.server.federation.router.Router; import org.apache.hadoop.hdfs.server.federation.store.MountTableStore; @@ -163,33 +159,22 @@ private void registerCacheExternal() { * @param conf Configuration for this resolver. */ private void initDefaultNameService(Configuration conf) { - this.defaultNameService = conf.get( - DFS_ROUTER_DEFAULT_NAMESERVICE, - DFSUtil.getNamenodeNameServiceId(conf)); - this.defaultNSEnable = conf.getBoolean( DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE, DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT); - if (defaultNameService == null) { - LOG.warn( - "{} and {} is not set. Fallback to {} as the default name service.", - DFS_ROUTER_DEFAULT_NAMESERVICE, DFS_NAMESERVICE_ID, DFS_NAMESERVICES); - Collection nsIds = DFSUtilClient.getNameServiceIds(conf); - if (nsIds.isEmpty()) { - this.defaultNameService = ""; - } else { - this.defaultNameService = nsIds.iterator().next(); - } + if (!this.defaultNSEnable) { + LOG.warn("Default name service is disabled."); + return; } + this.defaultNameService = conf.get(DFS_ROUTER_DEFAULT_NAMESERVICE, ""); if (this.defaultNameService.equals("")) { this.defaultNSEnable = false; LOG.warn("Default name service is not set."); } else { - String enable = this.defaultNSEnable ? "enabled" : "disabled"; - LOG.info("Default name service: {}, {} to read or write", - this.defaultNameService, enable); + LOG.info("Default name service: {}, enabled to read or write", + this.defaultNameService); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestInitializeMountTableResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestInitializeMountTableResolver.java index 5db7531c4d..8a22ade074 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestInitializeMountTableResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestInitializeMountTableResolver.java @@ -23,7 +23,9 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMESERVICE_ID; import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_NAMESERVICES; import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE; +import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * Test {@link MountTableResolver} initialization. @@ -43,40 +45,26 @@ public void testDefaultNameserviceWithEmptyString() { conf.set(DFS_ROUTER_DEFAULT_NAMESERVICE, ""); MountTableResolver mountTable = new MountTableResolver(conf); assertEquals("", mountTable.getDefaultNamespace()); + assertFalse("Default NS should be disabled if default NS is set empty", + mountTable.isDefaultNSEnable()); } @Test public void testRouterDefaultNameservice() { Configuration conf = new Configuration(); - conf.set(DFS_ROUTER_DEFAULT_NAMESERVICE, "router_ns"); // this is priority - conf.set(DFS_NAMESERVICE_ID, "ns_id"); - conf.set(DFS_NAMESERVICES, "nss"); + conf.set(DFS_ROUTER_DEFAULT_NAMESERVICE, "router_ns"); MountTableResolver mountTable = new MountTableResolver(conf); assertEquals("router_ns", mountTable.getDefaultNamespace()); } + // Default NS should be empty if configured false. @Test - public void testNameserviceID() { + public void testRouterDefaultNameserviceDisabled() { Configuration conf = new Configuration(); - conf.set(DFS_NAMESERVICE_ID, "ns_id"); // this is priority + conf.setBoolean(DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE, false); + conf.set(DFS_NAMESERVICE_ID, "ns_id"); conf.set(DFS_NAMESERVICES, "nss"); MountTableResolver mountTable = new MountTableResolver(conf); - assertEquals("ns_id", mountTable.getDefaultNamespace()); - } - - @Test - public void testSingleNameservices() { - Configuration conf = new Configuration(); - conf.set(DFS_NAMESERVICES, "ns1"); - MountTableResolver mountTable = new MountTableResolver(conf); - assertEquals("ns1", mountTable.getDefaultNamespace()); - } - - @Test - public void testMultipleNameservices() { - Configuration conf = new Configuration(); - conf.set(DFS_NAMESERVICES, "ns1,ns2"); - MountTableResolver mountTable = new MountTableResolver(conf); - assertEquals("ns1", mountTable.getDefaultNamespace()); + assertEquals("", mountTable.getDefaultNamespace()); } } \ No newline at end of file