This is an automated email from the ASF dual-hosted git repository. vinayakumarb pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push: new f4ae00c HDFS-7133. Support clearing namespace quota on '/'. Contributed by Ayush Saxena." f4ae00c is described below commit f4ae00c5301c0dd8923783ac6dca2d296c289254 Author: Vinayakumar B <vinayakum...@apache.org> AuthorDate: Tue Feb 26 00:36:00 2019 +0530 HDFS-7133. Support clearing namespace quota on '/'. Contributed by Ayush Saxena." --- .../hadoop/hdfs/server/namenode/FSDirAttrOp.java | 51 ++++++++++------------ .../java/org/apache/hadoop/hdfs/TestQuota.java | 21 +++++++-- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java index 1dbee96..6da59ed 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirAttrOp.java @@ -332,38 +332,35 @@ public class FSDirAttrOp { INodeDirectory dirNode = INodeDirectory.valueOf(iip.getLastINode(), iip.getPath()); + final QuotaCounts oldQuota = dirNode.getQuotaCounts(); + final long oldNsQuota = oldQuota.getNameSpace(); + final long oldSsQuota = oldQuota.getStorageSpace(); if (dirNode.isRoot() && nsQuota == HdfsConstants.QUOTA_RESET) { - throw new IllegalArgumentException("Cannot clear namespace quota on root."); - } else { // a directory inode - final QuotaCounts oldQuota = dirNode.getQuotaCounts(); - final long oldNsQuota = oldQuota.getNameSpace(); - final long oldSsQuota = oldQuota.getStorageSpace(); - - if (nsQuota == HdfsConstants.QUOTA_DONT_SET) { - nsQuota = oldNsQuota; - } - if (ssQuota == HdfsConstants.QUOTA_DONT_SET) { - ssQuota = oldSsQuota; - } + nsQuota = HdfsConstants.QUOTA_DONT_SET; + } else if (nsQuota == HdfsConstants.QUOTA_DONT_SET) { + nsQuota = oldNsQuota; + } // a directory inode + if (ssQuota == HdfsConstants.QUOTA_DONT_SET) { + ssQuota = oldSsQuota; + } - // unchanged space/namespace quota - if (type == null && oldNsQuota == nsQuota && oldSsQuota == ssQuota) { - return null; - } + // unchanged space/namespace quota + if (type == null && oldNsQuota == nsQuota && oldSsQuota == ssQuota) { + return null; + } - // unchanged type quota - if (type != null) { - EnumCounters<StorageType> oldTypeQuotas = oldQuota.getTypeSpaces(); - if (oldTypeQuotas != null && oldTypeQuotas.get(type) == ssQuota) { - return null; - } + // unchanged type quota + if (type != null) { + EnumCounters<StorageType> oldTypeQuotas = oldQuota.getTypeSpaces(); + if (oldTypeQuotas != null && oldTypeQuotas.get(type) == ssQuota) { + return null; } - - final int latest = iip.getLatestSnapshotId(); - dirNode.recordModification(latest); - dirNode.setQuota(fsd.getBlockStoragePolicySuite(), nsQuota, ssQuota, type); - return dirNode; } + + final int latest = iip.getLatestSnapshotId(); + dirNode.recordModification(latest); + dirNode.setQuota(fsd.getBlockStoragePolicySuite(), nsQuota, ssQuota, type); + return dirNode; } static BlockInfo[] unprotectedSetReplication( diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java index 1c4855f..f5d232c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java @@ -413,13 +413,13 @@ public class TestQuota { } }); - // 19: clrQuota on the root directory ("/") should fail - runCommand(admin, true, "-clrQuota", "/"); + // 19: clrQuota on the root directory ("/") should pass. + runCommand(admin, false, "-clrQuota", "/"); // 20: setQuota on the root directory ("/") should succeed runCommand(admin, false, "-setQuota", "1000000", "/"); - runCommand(admin, true, "-clrQuota", "/"); + runCommand(admin, false, "-clrQuota", "/"); runCommand(admin, false, "-clrSpaceQuota", "/"); runCommand(admin, new String[]{"-clrQuota", parent.toString()}, false); runCommand(admin, false, "-clrSpaceQuota", parent.toString()); @@ -456,7 +456,7 @@ public class TestQuota { final Path childFile4 = new Path(dir, "datafile2"); final Path childFile5 = new Path(dir, "datafile3"); - runCommand(admin, true, "-clrQuota", "/"); + runCommand(admin, false, "-clrQuota", "/"); runCommand(admin, false, "-clrSpaceQuota", "/"); // set space quota to a real low value runCommand(admin, false, "-setSpaceQuota", Long.toString(spaceQuota2), "/"); @@ -1566,6 +1566,19 @@ public class TestQuota { } @Test + public void testClrQuotaOnRoot() throws Exception { + long orignalQuota = dfs.getQuotaUsage(new Path("/")).getQuota(); + DFSAdmin admin = new DFSAdmin(conf); + String[] args; + args = new String[] {"-setQuota", "3K", "/"}; + runCommand(admin, args, false); + assertEquals(3 * 1024, dfs.getQuotaUsage(new Path("/")).getQuota()); + args = new String[] {"-clrQuota", "/"}; + runCommand(admin, args, false); + assertEquals(orignalQuota, dfs.getQuotaUsage(new Path("/")).getQuota()); + } + + @Test public void testSpaceQuotaExceptionOnAppend() throws Exception { GenericTestUtils.setLogLevel(DFSOutputStream.LOG, Level.TRACE); GenericTestUtils.setLogLevel(DataStreamer.LOG, Level.TRACE); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org