From 2da3356428e9a0415ab5304ec9f4bd3e769782fc Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Mon, 28 Sep 2020 23:55:31 +0530 Subject: [PATCH] HDFS-15591. RBF: Fix webHdfs file display error. Contributed by wangzhaohui. (cherry picked from commit fc8a6dd8a92f8e18436d1a73d6e8ef808c583aee) --- .../router/RouterClientProtocol.java | 7 +++-- .../router/TestRouterMountTable.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java index 2a0fe7cbd0e..744d35ded9e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java @@ -1977,7 +1977,8 @@ public class RouterClientProtocol implements ClientProtocol { * @param date Map with the dates. * @return New HDFS file status representing a mount point. */ - private HdfsFileStatus getMountPointStatus( + @VisibleForTesting + HdfsFileStatus getMountPointStatus( String name, int childrenNum, long date) { long modTime = date; long accessTime = date; @@ -2028,6 +2029,8 @@ public class RouterClientProtocol implements ClientProtocol { } } long inodeId = 0; + Path path = new Path(name); + String nameStr = path.getName(); return new HdfsFileStatus.Builder() .isdir(true) .mtime(modTime) @@ -2036,7 +2039,7 @@ public class RouterClientProtocol implements ClientProtocol { .owner(owner) .group(group) .symlink(new byte[0]) - .path(DFSUtil.string2Bytes(name)) + .path(DFSUtil.string2Bytes(nameStr)) .fileId(inodeId) .children(childrenNum) .flags(flags) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterMountTable.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterMountTable.java index 77ec47a7a7f..6df94c0fdd2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterMountTable.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterMountTable.java @@ -290,6 +290,37 @@ public class TestRouterMountTable { } } + /** + * Verify the getMountPointStatus result of passing in different parameters. + */ + @Test + public void testGetMountPointStatus() throws IOException { + MountTable addEntry = MountTable.newInstance("/testA/testB/testC/testD", + Collections.singletonMap("ns0", "/testA/testB/testC/testD")); + assertTrue(addMountTable(addEntry)); + RouterClientProtocol clientProtocol = new RouterClientProtocol( + nnFs0.getConf(), routerContext.getRouter().getRpcServer()); + String src = "/"; + String child = "testA"; + Path childPath = new Path(src, child); + HdfsFileStatus dirStatus = + clientProtocol.getMountPointStatus(childPath.toString(), 0, 0); + assertEquals(child, dirStatus.getLocalName()); + + String src1 = "/testA"; + String child1 = "testB"; + Path childPath1 = new Path(src1, child1); + HdfsFileStatus dirStatus1 = + clientProtocol.getMountPointStatus(childPath1.toString(), 0, 0); + assertEquals(child1, dirStatus1.getLocalName()); + + String src2 = "/testA/testB"; + String child2 = "testC"; + Path childPath2 = new Path(src2, child2); + HdfsFileStatus dirStatus2 = + clientProtocol.getMountPointStatus(childPath2.toString(), 0, 0); + assertEquals(child2, dirStatus2.getLocalName()); + } /** * GetListing of testPath through router. */