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 825118fed3c3c..8e984d65c33e2 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 @@ -347,7 +347,7 @@ public static boolean orByStorageType(Predicate predicate) { * @return true if bitwise AND by all storage type returns true, false otherwise. */ public static boolean andByStorageType(Predicate predicate) { - boolean res = false; + boolean res = true; for (StorageType type : StorageType.values()) { res &= predicate.test(type); } 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 aa3d547056134..3c5be3cf98de6 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 @@ -31,6 +31,8 @@ import java.util.EnumSet; import java.util.List; import java.util.UUID; +import java.util.Arrays; +import java.util.function.Predicate; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CreateFlag; @@ -1168,6 +1170,34 @@ public void testQuotaUpdateWhenDestinationNotPresent() throws Exception { assertEquals(0, quotaUsage.getSpaceConsumed()); } + @Test + public void testAndByStorageType() { + long[] typeQuota = new long[StorageType.values().length]; + Arrays.fill(typeQuota, HdfsConstants.QUOTA_DONT_SET); + + Predicate predicate = new Predicate() { + @Override + public boolean test(StorageType storageType) { + return typeQuota[storageType.ordinal()] == HdfsConstants.QUOTA_DONT_SET; + } + }; + + assertTrue(Quota.andByStorageType(predicate)); + + // This is a value to test for, + // as long as it is not equal to HdfsConstants.QUOTA_DONT_SET + typeQuota[0] = HdfsConstants.QUOTA_RESET; + assertFalse(Quota.andByStorageType(predicate)); + + Arrays.fill(typeQuota, HdfsConstants.QUOTA_DONT_SET); + typeQuota[1] = HdfsConstants.QUOTA_RESET; + assertFalse(Quota.andByStorageType(predicate)); + + Arrays.fill(typeQuota, HdfsConstants.QUOTA_DONT_SET); + typeQuota[typeQuota.length-1] = HdfsConstants.QUOTA_RESET; + assertFalse(Quota.andByStorageType(predicate)); + } + /** * Add three mount tables. * /dir-1 --> ns0---/dir-1 [nsQuota, ssQuota]