소스 검색

HDFS-14756. RBF: getQuotaUsage may ignore some folders. Contributed by Chen Zhang.

Inigo Goiri 5 년 전
부모
커밋
93595febaa

+ 1 - 2
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;
         }

+ 8 - 1
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