diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java index 374e3ba85f2..dac6f7f424f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java @@ -521,6 +521,17 @@ public class MountTableResolver return this.defaultNameService; } + private boolean isParentEntry(final String path, final String parent) { + if (!path.startsWith(parent)) { + return false; + } + if (path.equals(parent)) { + return true; + } + return path.charAt(parent.length()) == Path.SEPARATOR_CHAR + || parent.equals(Path.SEPARATOR); + } + /** * Find the deepest mount point for a path. * @param path Path to look for. @@ -530,7 +541,7 @@ public class MountTableResolver readLock.lock(); try { Entry entry = this.tree.floorEntry(path); - while (entry != null && !path.startsWith(entry.getKey())) { + while (entry != null && !isParentEntry(path, entry.getKey())) { entry = this.tree.lowerEntry(entry.getKey()); } if (entry == null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java index fa2f89c5d19..a09daf0975b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/resolver/TestMountTableResolver.java @@ -178,6 +178,29 @@ public class TestMountTableResolver { } } + @Test + public void testGetMountPoint() throws IOException { + // Check get the mount table entry for a path + MountTable mtEntry; + mtEntry = mountTable.getMountPoint("/"); + assertTrue(mtEntry.getSourcePath().equals("/")); + + mtEntry = mountTable.getMountPoint("/user"); + assertTrue(mtEntry.getSourcePath().equals("/user")); + + mtEntry = mountTable.getMountPoint("/user/a"); + assertTrue(mtEntry.getSourcePath().equals("/user/a")); + + mtEntry = mountTable.getMountPoint("/user/a/"); + assertTrue(mtEntry.getSourcePath().equals("/user/a")); + + mtEntry = mountTable.getMountPoint("/user/a/11"); + assertTrue(mtEntry.getSourcePath().equals("/user/a")); + + mtEntry = mountTable.getMountPoint("/user/a1"); + assertTrue(mtEntry.getSourcePath().equals("/user")); + } + @Test public void testGetMountPoints() throws IOException { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java index b7c1c631d37..2b40bbd9248 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java @@ -414,7 +414,7 @@ public class TestRouterQuota { // mkdir and write a new file final FileSystem routerFs = routerContext.getFileSystem(); - routerFs.mkdirs(new Path(path + UUID.randomUUID())); + routerFs.mkdirs(new Path(path + "/" + UUID.randomUUID())); DFSClient routerClient = routerContext.getClient(); routerClient.create(path + "/file", true).close(); appendData(path + "/file", routerClient, BLOCK_SIZE);