diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java index a48107228f..e1a83d0b41 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java @@ -2214,7 +2214,7 @@ private List> getListingInt( .invokeConcurrent(locations, method, false, -1, DirectoryListing.class); return listings; - } catch (RouterResolveException e) { + } catch (NoLocationException | RouterResolveException e) { LOG.debug("Cannot get locations for {}, {}.", src, e.getMessage()); return new ArrayList<>(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java index 76fb399983..fc761934bc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java @@ -1764,6 +1764,9 @@ protected List getLocationsForPath(String path, locs.add(loc); } } + if (locs.isEmpty()) { + throw new NoLocationException(path, this.subclusterResolver.getClass()); + } return locs; } catch (IOException ioe) { if (this.rpcMonitor != null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/MockResolver.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/MockResolver.java index 1519bad74b..f8f6ccef36 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/MockResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/MockResolver.java @@ -59,6 +59,7 @@ public class MockResolver private String defaultNamespace = null; private boolean disableDefaultNamespace = false; private volatile boolean disableRegistration = false; + private TreeSet disableNamespaces = new TreeSet<>(); public MockResolver() { this.cleanRegistrations(); @@ -300,9 +301,17 @@ public synchronized Set getNamespaces() return Collections.unmodifiableSet(this.namespaces); } + public void clearDisableNamespaces() { + this.disableNamespaces.clear(); + } + + public void disableNamespace(String nsId) { + this.disableNamespaces.add(nsId); + } + @Override public Set getDisabledNamespaces() throws IOException { - return new TreeSet<>(); + return this.disableNamespaces; } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java index 11417ef144..35b640d406 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java @@ -1548,6 +1548,24 @@ public void testRenewLeaseWithMultiStream() throws Exception { } } + @Test + public void testMkdirWithDisableNameService() throws Exception { + MockResolver resolver = (MockResolver)router.getRouter().getSubclusterResolver(); + String ns0 = cluster.getNameservices().get(0); + resolver.addLocation("/mnt", ns0, "/"); + MockResolver activeNamenodeResolver = (MockResolver)router.getRouter().getNamenodeResolver(); + activeNamenodeResolver.disableNamespace(ns0); + + try { + FsPermission permission = new FsPermission("777"); + RouterRpcServer rpcServer = router.getRouter().getRpcServer(); + LambdaTestUtils.intercept(NoLocationException.class, + () -> rpcServer.mkdirs("/mnt/folder0/folder1", permission, true)); + } finally { + activeNamenodeResolver.clearDisableNamespaces(); + } + } + @Test public void testProxyExceptionMessages() throws IOException {