HDFS-13233. RBF: MountTableResolver doesn't return the correct mount point of the given path. Contributed by wangzhiyuan.
This commit is contained in:
parent
113f401f41
commit
122805b43a
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue