HDFS-14193. RBF: Inconsistency with the Default Namespace. Contributed by Ayush Saxena.
This commit is contained in:
parent
58c9bc1eca
commit
b20c5fa841
|
@ -17,8 +17,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hdfs.server.federation.resolver;
|
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;
|
||||||
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;
|
||||||
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT;
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT;
|
||||||
|
@ -50,8 +48,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.Path;
|
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.resolver.order.DestinationOrder;
|
||||||
import org.apache.hadoop.hdfs.server.federation.router.Router;
|
import org.apache.hadoop.hdfs.server.federation.router.Router;
|
||||||
import org.apache.hadoop.hdfs.server.federation.store.MountTableStore;
|
import org.apache.hadoop.hdfs.server.federation.store.MountTableStore;
|
||||||
|
@ -163,33 +159,22 @@ public class MountTableResolver
|
||||||
* @param conf Configuration for this resolver.
|
* @param conf Configuration for this resolver.
|
||||||
*/
|
*/
|
||||||
private void initDefaultNameService(Configuration conf) {
|
private void initDefaultNameService(Configuration conf) {
|
||||||
this.defaultNameService = conf.get(
|
|
||||||
DFS_ROUTER_DEFAULT_NAMESERVICE,
|
|
||||||
DFSUtil.getNamenodeNameServiceId(conf));
|
|
||||||
|
|
||||||
this.defaultNSEnable = conf.getBoolean(
|
this.defaultNSEnable = conf.getBoolean(
|
||||||
DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE,
|
DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE,
|
||||||
DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT);
|
DFS_ROUTER_DEFAULT_NAMESERVICE_ENABLE_DEFAULT);
|
||||||
|
|
||||||
if (defaultNameService == null) {
|
if (!this.defaultNSEnable) {
|
||||||
LOG.warn(
|
LOG.warn("Default name service is disabled.");
|
||||||
"{} and {} is not set. Fallback to {} as the default name service.",
|
return;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.defaultNameService = conf.get(DFS_ROUTER_DEFAULT_NAMESERVICE, "");
|
||||||
|
|
||||||
if (this.defaultNameService.equals("")) {
|
if (this.defaultNameService.equals("")) {
|
||||||
this.defaultNSEnable = false;
|
this.defaultNSEnable = false;
|
||||||
LOG.warn("Default name service is not set.");
|
LOG.warn("Default name service is not set.");
|
||||||
} else {
|
} else {
|
||||||
String enable = this.defaultNSEnable ? "enabled" : "disabled";
|
LOG.info("Default name service: {}, enabled to read or write",
|
||||||
LOG.info("Default name service: {}, {} to read or write",
|
this.defaultNameService);
|
||||||
this.defaultNameService, enable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,9 @@ import org.junit.Test;
|
||||||
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMESERVICE_ID;
|
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.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;
|
||||||
|
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.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link MountTableResolver} initialization.
|
* Test {@link MountTableResolver} initialization.
|
||||||
|
@ -43,40 +45,26 @@ public class TestInitializeMountTableResolver {
|
||||||
conf.set(DFS_ROUTER_DEFAULT_NAMESERVICE, "");
|
conf.set(DFS_ROUTER_DEFAULT_NAMESERVICE, "");
|
||||||
MountTableResolver mountTable = new MountTableResolver(conf);
|
MountTableResolver mountTable = new MountTableResolver(conf);
|
||||||
assertEquals("", mountTable.getDefaultNamespace());
|
assertEquals("", mountTable.getDefaultNamespace());
|
||||||
|
assertFalse("Default NS should be disabled if default NS is set empty",
|
||||||
|
mountTable.isDefaultNSEnable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRouterDefaultNameservice() {
|
public void testRouterDefaultNameservice() {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(DFS_ROUTER_DEFAULT_NAMESERVICE, "router_ns"); // this is priority
|
conf.set(DFS_ROUTER_DEFAULT_NAMESERVICE, "router_ns");
|
||||||
conf.set(DFS_NAMESERVICE_ID, "ns_id");
|
|
||||||
conf.set(DFS_NAMESERVICES, "nss");
|
|
||||||
MountTableResolver mountTable = new MountTableResolver(conf);
|
MountTableResolver mountTable = new MountTableResolver(conf);
|
||||||
assertEquals("router_ns", mountTable.getDefaultNamespace());
|
assertEquals("router_ns", mountTable.getDefaultNamespace());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default NS should be empty if configured false.
|
||||||
@Test
|
@Test
|
||||||
public void testNameserviceID() {
|
public void testRouterDefaultNameserviceDisabled() {
|
||||||
Configuration conf = new Configuration();
|
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");
|
conf.set(DFS_NAMESERVICES, "nss");
|
||||||
MountTableResolver mountTable = new MountTableResolver(conf);
|
MountTableResolver mountTable = new MountTableResolver(conf);
|
||||||
assertEquals("ns_id", mountTable.getDefaultNamespace());
|
assertEquals("", 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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue