diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/impl/MountTableStoreImpl.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/impl/MountTableStoreImpl.java index 87610385d8..8682a3d5e4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/impl/MountTableStoreImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/impl/MountTableStoreImpl.java @@ -25,6 +25,7 @@ import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.fs.permission.FsAction; +import org.apache.hadoop.hdfs.server.federation.router.FederationUtil; import org.apache.hadoop.hdfs.server.federation.router.RouterAdminServer; import org.apache.hadoop.hdfs.server.federation.router.RouterPermissionChecker; import org.apache.hadoop.hdfs.server.federation.store.MountTableStore; @@ -139,7 +140,7 @@ public GetMountTableEntriesResponse getMountTableEntries( while (it.hasNext()) { MountTable record = it.next(); String srcPath = record.getSourcePath(); - if (!srcPath.startsWith(reqSrcPath)) { + if (!FederationUtil.isParentEntry(srcPath, reqSrcPath)) { it.remove(); } else if (pc != null) { // do the READ permission check diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java index 731d5d4560..6de74c26c2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java @@ -332,6 +332,39 @@ public void testListMountTable() throws Exception { } } + @Test + public void testListNestedMountTable() throws Exception { + String dir1 = "/test-ls"; + String dir2 = "/test-ls-longger"; + String[] nsIdList = {"ns0", "ns1", "ns2", "ns3", "ns3"}; + String[] sourceList = + {dir1, dir1 + "/subdir1", dir2, dir2 + "/subdir1", dir2 + "/subdir2"}; + String[] destList = + {"/test-ls", "/test-ls/subdir1", "/ls", "/ls/subdir1", "/ls/subdir2"}; + for (int i = 0; i < nsIdList.length; i++) { + String[] argv = + new String[] {"-add", sourceList[i], nsIdList[i], destList[i]}; + assertEquals(0, ToolRunner.run(admin, argv)); + } + + // prepare for test + System.setOut(new PrintStream(out)); + stateStore.loadCache(MountTableStoreImpl.class, true); + + // Test ls dir1 + String[] argv = new String[] {"-ls", dir1}; + assertEquals(0, ToolRunner.run(admin, argv)); + String outStr = out.toString(); + assertTrue(out.toString().contains(dir1 + "/subdir1")); + assertFalse(out.toString().contains(dir2)); + + // Test ls dir2 + argv = new String[] {"-ls", dir2}; + assertEquals(0, ToolRunner.run(admin, argv)); + assertTrue(out.toString().contains(dir2 + "/subdir1")); + assertTrue(out.toString().contains(dir2 + "/subdir2")); + } + @Test public void testRemoveMountTable() throws Exception { String nsId = "ns0"; @@ -699,6 +732,8 @@ public void testSetAndClearQuota() throws Exception { assertEquals(0, ToolRunner.run(admin, argv)); stateStore.loadCache(MountTableStoreImpl.class, true); + + getRequest = GetMountTableEntriesRequest.newInstance("/"); getResponse = client.getMountTableManager().getMountTableEntries(getRequest);