|
@@ -20,6 +20,8 @@ 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;
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_MOUNT_TABLE_MAX_CACHE_SIZE;
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_MOUNT_TABLE_MAX_CACHE_SIZE_DEFAULT;
|
|
|
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_MOUNT_TABLE_CACHE_ENABLE;
|
|
@@ -95,6 +97,8 @@ public class MountTableResolver
|
|
|
|
|
|
/** Default nameservice when no mount matches the math. */
|
|
|
private String defaultNameService = "";
|
|
|
+ /** If use default nameservice to read and write files. */
|
|
|
+ private boolean defaultNSEnable = true;
|
|
|
|
|
|
/** Synchronization for both the tree and the cache. */
|
|
|
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
|
@@ -163,6 +167,10 @@ public class MountTableResolver
|
|
|
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.",
|
|
@@ -176,9 +184,12 @@ public class MountTableResolver
|
|
|
}
|
|
|
|
|
|
if (this.defaultNameService.equals("")) {
|
|
|
+ this.defaultNSEnable = false;
|
|
|
LOG.warn("Default name service is not set.");
|
|
|
} else {
|
|
|
- LOG.info("Default name service: {}", this.defaultNameService);
|
|
|
+ String enable = this.defaultNSEnable ? "enabled" : "disabled";
|
|
|
+ LOG.info("Default name service: {}, {} to read or write",
|
|
|
+ this.defaultNameService, enable);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -406,13 +417,17 @@ public class MountTableResolver
|
|
|
* @param path Path to check/insert.
|
|
|
* @return New remote location.
|
|
|
*/
|
|
|
- public PathLocation lookupLocation(final String path) {
|
|
|
+ public PathLocation lookupLocation(final String path) throws IOException {
|
|
|
PathLocation ret = null;
|
|
|
MountTable entry = findDeepest(path);
|
|
|
if (entry != null) {
|
|
|
ret = buildLocation(path, entry);
|
|
|
} else {
|
|
|
// Not found, use default location
|
|
|
+ if (!defaultNSEnable) {
|
|
|
+ throw new IOException("Cannot find locations for " + path + ", " +
|
|
|
+ "because the default nameservice is disabled to read or write");
|
|
|
+ }
|
|
|
RemoteLocation remoteLocation =
|
|
|
new RemoteLocation(defaultNameService, path, path);
|
|
|
List<RemoteLocation> locations =
|
|
@@ -623,4 +638,24 @@ public class MountTableResolver
|
|
|
}
|
|
|
throw new IOException("localCache is null");
|
|
|
}
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ public String getDefaultNameService() {
|
|
|
+ return defaultNameService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ public void setDefaultNameService(String defaultNameService) {
|
|
|
+ this.defaultNameService = defaultNameService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ public boolean isDefaultNSEnable() {
|
|
|
+ return defaultNSEnable;
|
|
|
+ }
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ public void setDefaultNSEnable(boolean defaultNSRWEnable) {
|
|
|
+ this.defaultNSEnable = defaultNSRWEnable;
|
|
|
+ }
|
|
|
}
|