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 9d84559212..ee938657d2 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 @@ -80,6 +80,9 @@ public Quota(Router router, RouterRpcServer server) { */ public void setQuota(String path, long namespaceQuota, long storagespaceQuota, StorageType type, boolean checkMountEntry) throws IOException { + if (!router.isQuotaEnabled()) { + throw new IOException("The quota system is disabled in Router."); + } if (checkMountEntry && isMountEntry(path)) { throw new AccessControlException( "Permission denied: " + RouterRpcServer.getRemoteUser() @@ -101,9 +104,6 @@ void setQuotaInternal(String path, List locations, long namespaceQuota, long storagespaceQuota, StorageType type) throws IOException { rpcServer.checkOperation(OperationCategory.WRITE); - if (!router.isQuotaEnabled()) { - throw new IOException("The quota system is disabled in Router."); - } // Set quota for current path and its children mount table path. if (locations == null) { diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java index 192c8078d4..bd3b60ba91 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java @@ -70,15 +70,21 @@ public void checkDisableQuota() { public void testSetQuota() throws Exception { long nsQuota = 1024; long ssQuota = 1024; + Quota quotaModule = router.getRpcServer().getQuotaModule(); - try { - Quota quotaModule = router.getRpcServer().getQuotaModule(); - quotaModule.setQuota("/test", nsQuota, ssQuota, null, false); - fail("The setQuota call should fail."); - } catch (IOException ioe) { - GenericTestUtils.assertExceptionContains( - "The quota system is disabled in Router.", ioe); - } + // don't checkMountEntry called by RouterAdminServer#synchronizeQuota + LambdaTestUtils.intercept( + IOException.class, + "The quota system is disabled in Router.", + "The setQuota call should fail.", + () -> quotaModule.setQuota("/test", nsQuota, ssQuota, null, false)); + + // do checkMountEntry called by RouterClientProtocol#setQuota + LambdaTestUtils.intercept( + IOException.class, + "The quota system is disabled in Router.", + "The setQuota call should fail.", + () -> quotaModule.setQuota("/test", nsQuota, ssQuota, null, true)); } @Test