HDFS-14193. RBF: Inconsistency with the Default Namespace. Contributed by Ayush Saxena.
This commit is contained in:
parent
7b61cbf672
commit
c012b09fb6
@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user