From 93595febaa6673eea369911c3f7fcd75d4915dbc Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Wed, 21 Aug 2019 09:39:57 -0700 Subject: [PATCH] HDFS-14756. RBF: getQuotaUsage may ignore some folders. Contributed by Chen Zhang. --- .../hadoop/hdfs/server/federation/router/Quota.java | 3 +-- .../hdfs/server/federation/router/TestRouterQuota.java | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java index 0ac64a11378..48f0b96a8c6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.fs.QuotaUsage; import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.hdfs.protocol.ClientProtocol; @@ -138,7 +137,7 @@ public class Quota { boolean isChildPath = false; for (RemoteLocation d : dests) { - if (StringUtils.startsWith(loc.getDest(), d.getDest())) { + if (FederationUtil.isParentEntry(loc.getDest(), d.getDest())) { isChildPath = true; break; } diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java index 075e529be4b..c3a5c17da63 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterQuota.java @@ -332,9 +332,11 @@ public class TestRouterQuota { // /getquota --> ns0---/testdir7 // /getquota/subdir1 --> ns0---/testdir7/subdir // /getquota/subdir2 --> ns1---/testdir8 + // /getquota/subdir3 --> ns1---/testdir8-ext nnFs1.mkdirs(new Path("/testdir7")); nnFs1.mkdirs(new Path("/testdir7/subdir")); nnFs2.mkdirs(new Path("/testdir8")); + nnFs2.mkdirs(new Path("/testdir8-ext")); MountTable mountTable1 = MountTable.newInstance("/getquota", Collections.singletonMap("ns0", "/testdir7")); mountTable1 @@ -350,11 +352,16 @@ public class TestRouterQuota { Collections.singletonMap("ns1", "/testdir8")); addMountTable(mountTable3); + MountTable mountTable4 = MountTable.newInstance("/getquota/subdir3", + Collections.singletonMap("ns1", "/testdir8-ext")); + addMountTable(mountTable4); + // use router client to create new files DFSClient routerClient = routerContext.getClient(); routerClient.create("/getquota/file", true).close(); routerClient.create("/getquota/subdir1/file", true).close(); routerClient.create("/getquota/subdir2/file", true).close(); + routerClient.create("/getquota/subdir3/file", true).close(); ClientProtocol clientProtocol = routerContext.getClient().getNamenode(); RouterQuotaUpdateService updateService = routerContext.getRouter() @@ -362,7 +369,7 @@ public class TestRouterQuota { updateService.periodicInvoke(); final QuotaUsage quota = clientProtocol.getQuotaUsage("/getquota"); // the quota should be aggregated - assertEquals(6, quota.getFileAndDirectoryCount()); + assertEquals(8, quota.getFileAndDirectoryCount()); } @Test