HDFS-16271. RBF: NullPointerException when setQuota through routers with quota disabled. Contributed by Chengwei Wang.

This commit is contained in:
Ayush Saxena 2021-10-16 14:25:00 +05:30
parent d72e2cb786
commit 263e4b595d
No known key found for this signature in database
GPG Key ID: D09AE71061AB564D
2 changed files with 17 additions and 11 deletions

View File

@ -80,6 +80,9 @@ public class Quota {
*/
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 @@ public class Quota {
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) {

View File

@ -70,15 +70,21 @@ public class TestDisableRouterQuota {
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