HDFS-13233. RBF: MountTableResolver doesn't return the correct mount point of the given path. Contributed by wangzhiyuan.

This commit is contained in:
Yiqun Lin 2018-03-09 15:42:57 +08:00
parent 113f401f41
commit 122805b43a
3 changed files with 36 additions and 2 deletions

View File

@ -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<String, MountTable> 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) {

View File

@ -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 {

View File

@ -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);