HDFS-14766. RBF: MountTableStoreImpl#getMountTableEntries returns extra entry. Contributed by Chen Zhang.

This commit is contained in:
Inigo Goiri 2019-08-23 14:53:57 -07:00
parent 3f887f3b92
commit 0b796754b9
2 changed files with 37 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import java.util.List;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.hdfs.server.federation.router.FederationUtil;
import org.apache.hadoop.hdfs.server.federation.router.RouterAdminServer;
import org.apache.hadoop.hdfs.server.federation.router.RouterPermissionChecker;
import org.apache.hadoop.hdfs.server.federation.store.MountTableStore;
@ -139,7 +140,7 @@ public class MountTableStoreImpl extends MountTableStore {
while (it.hasNext()) {
MountTable record = it.next();
String srcPath = record.getSourcePath();
if (!srcPath.startsWith(reqSrcPath)) {
if (!FederationUtil.isParentEntry(srcPath, reqSrcPath)) {
it.remove();
} else if (pc != null) {
// do the READ permission check

View File

@ -332,6 +332,39 @@ public class TestRouterAdminCLI {
}
}
@Test
public void testListNestedMountTable() throws Exception {
String dir1 = "/test-ls";
String dir2 = "/test-ls-longger";
String[] nsIdList = {"ns0", "ns1", "ns2", "ns3", "ns3"};
String[] sourceList =
{dir1, dir1 + "/subdir1", dir2, dir2 + "/subdir1", dir2 + "/subdir2"};
String[] destList =
{"/test-ls", "/test-ls/subdir1", "/ls", "/ls/subdir1", "/ls/subdir2"};
for (int i = 0; i < nsIdList.length; i++) {
String[] argv =
new String[] {"-add", sourceList[i], nsIdList[i], destList[i]};
assertEquals(0, ToolRunner.run(admin, argv));
}
// prepare for test
System.setOut(new PrintStream(out));
stateStore.loadCache(MountTableStoreImpl.class, true);
// Test ls dir1
String[] argv = new String[] {"-ls", dir1};
assertEquals(0, ToolRunner.run(admin, argv));
String outStr = out.toString();
assertTrue(out.toString().contains(dir1 + "/subdir1"));
assertFalse(out.toString().contains(dir2));
// Test ls dir2
argv = new String[] {"-ls", dir2};
assertEquals(0, ToolRunner.run(admin, argv));
assertTrue(out.toString().contains(dir2 + "/subdir1"));
assertTrue(out.toString().contains(dir2 + "/subdir2"));
}
@Test
public void testRemoveMountTable() throws Exception {
String nsId = "ns0";
@ -699,6 +732,8 @@ public class TestRouterAdminCLI {
assertEquals(0, ToolRunner.run(admin, argv));
stateStore.loadCache(MountTableStoreImpl.class, true);
getRequest = GetMountTableEntriesRequest.newInstance("/");
getResponse =
client.getMountTableManager().getMountTableEntries(getRequest);