HDFS-7133. Support clearing namespace quota on '/'. Contributed by Ayush Saxena."

This commit is contained in:
Vinayakumar B 2019-02-26 00:36:00 +05:30
parent 3e1739d589
commit f4ae00c530
2 changed files with 40 additions and 30 deletions

View File

@ -332,38 +332,35 @@ static INodeDirectory unprotectedSetQuota(
INodeDirectory dirNode = INodeDirectory dirNode =
INodeDirectory.valueOf(iip.getLastINode(), iip.getPath()); 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) { if (dirNode.isRoot() && nsQuota == HdfsConstants.QUOTA_RESET) {
throw new IllegalArgumentException("Cannot clear namespace quota on root."); nsQuota = HdfsConstants.QUOTA_DONT_SET;
} else { // a directory inode } else if (nsQuota == HdfsConstants.QUOTA_DONT_SET) {
final QuotaCounts oldQuota = dirNode.getQuotaCounts(); nsQuota = oldNsQuota;
final long oldNsQuota = oldQuota.getNameSpace(); } // a directory inode
final long oldSsQuota = oldQuota.getStorageSpace(); if (ssQuota == HdfsConstants.QUOTA_DONT_SET) {
ssQuota = oldSsQuota;
}
if (nsQuota == HdfsConstants.QUOTA_DONT_SET) { // unchanged space/namespace quota
nsQuota = oldNsQuota; if (type == null && oldNsQuota == nsQuota && oldSsQuota == ssQuota) {
} return null;
if (ssQuota == HdfsConstants.QUOTA_DONT_SET) { }
ssQuota = oldSsQuota;
}
// unchanged space/namespace quota // unchanged type quota
if (type == null && oldNsQuota == nsQuota && oldSsQuota == ssQuota) { if (type != null) {
EnumCounters<StorageType> oldTypeQuotas = oldQuota.getTypeSpaces();
if (oldTypeQuotas != null && oldTypeQuotas.get(type) == ssQuota) {
return null; 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( static BlockInfo[] unprotectedSetReplication(

View File

@ -413,13 +413,13 @@ public Object run() throws Exception {
} }
}); });
// 19: clrQuota on the root directory ("/") should fail // 19: clrQuota on the root directory ("/") should pass.
runCommand(admin, true, "-clrQuota", "/"); runCommand(admin, false, "-clrQuota", "/");
// 20: setQuota on the root directory ("/") should succeed // 20: setQuota on the root directory ("/") should succeed
runCommand(admin, false, "-setQuota", "1000000", "/"); runCommand(admin, false, "-setQuota", "1000000", "/");
runCommand(admin, true, "-clrQuota", "/"); runCommand(admin, false, "-clrQuota", "/");
runCommand(admin, false, "-clrSpaceQuota", "/"); runCommand(admin, false, "-clrSpaceQuota", "/");
runCommand(admin, new String[]{"-clrQuota", parent.toString()}, false); runCommand(admin, new String[]{"-clrQuota", parent.toString()}, false);
runCommand(admin, false, "-clrSpaceQuota", parent.toString()); runCommand(admin, false, "-clrSpaceQuota", parent.toString());
@ -456,7 +456,7 @@ public Object run() throws Exception {
final Path childFile4 = new Path(dir, "datafile2"); final Path childFile4 = new Path(dir, "datafile2");
final Path childFile5 = new Path(dir, "datafile3"); final Path childFile5 = new Path(dir, "datafile3");
runCommand(admin, true, "-clrQuota", "/"); runCommand(admin, false, "-clrQuota", "/");
runCommand(admin, false, "-clrSpaceQuota", "/"); runCommand(admin, false, "-clrSpaceQuota", "/");
// set space quota to a real low value // set space quota to a real low value
runCommand(admin, false, "-setSpaceQuota", Long.toString(spaceQuota2), "/"); runCommand(admin, false, "-setSpaceQuota", Long.toString(spaceQuota2), "/");
@ -1565,6 +1565,19 @@ public Boolean get() {
assertEquals(0, cluster.getNamesystem().getNumFilesUnderConstruction()); assertEquals(0, cluster.getNamesystem().getNumFilesUnderConstruction());
} }
@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 @Test
public void testSpaceQuotaExceptionOnAppend() throws Exception { public void testSpaceQuotaExceptionOnAppend() throws Exception {
GenericTestUtils.setLogLevel(DFSOutputStream.LOG, Level.TRACE); GenericTestUtils.setLogLevel(DFSOutputStream.LOG, Level.TRACE);