HDFS-13233. RBF: MountTableResolver doesn't return the correct mount point of the given path. Contributed by wangzhiyuan.
(cherry picked from commit f879504fe1
)
This commit is contained in:
parent
6fafaa7b7f
commit
04e18e747b
|
@ -521,6 +521,17 @@ public class MountTableResolver
|
||||||
return this.defaultNameService;
|
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.
|
* Find the deepest mount point for a path.
|
||||||
* @param path Path to look for.
|
* @param path Path to look for.
|
||||||
|
@ -530,7 +541,7 @@ public class MountTableResolver
|
||||||
readLock.lock();
|
readLock.lock();
|
||||||
try {
|
try {
|
||||||
Entry<String, MountTable> entry = this.tree.floorEntry(path);
|
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());
|
entry = this.tree.lowerEntry(entry.getKey());
|
||||||
}
|
}
|
||||||
if (entry == null) {
|
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
|
@Test
|
||||||
public void testGetMountPoints() throws IOException {
|
public void testGetMountPoints() throws IOException {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue