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 String getDefaultNamespace() {
|
|||||||
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 @@ private MountTable findDeepest(final String path) {
|
|||||||
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 @@ private void compareLists(List<String> list1, String[] list2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 {
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ public void testQuotaUpdating() throws Exception {
|
|||||||
|
|
||||||
// mkdir and write a new file
|
// mkdir and write a new file
|
||||||
final FileSystem routerFs = routerContext.getFileSystem();
|
final FileSystem routerFs = routerContext.getFileSystem();
|
||||||
routerFs.mkdirs(new Path(path + UUID.randomUUID()));
|
routerFs.mkdirs(new Path(path + "/" + UUID.randomUUID()));
|
||||||
DFSClient routerClient = routerContext.getClient();
|
DFSClient routerClient = routerContext.getClient();
|
||||||
routerClient.create(path + "/file", true).close();
|
routerClient.create(path + "/file", true).close();
|
||||||
appendData(path + "/file", routerClient, BLOCK_SIZE);
|
appendData(path + "/file", routerClient, BLOCK_SIZE);
|
||||||
|
Loading…
Reference in New Issue
Block a user