[
https://issues.apache.org/jira/browse/HDFS-14542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16856312#comment-16856312
]
Jinglun commented on HDFS-14542:
--------------------------------
Hi [~ayushtkn], thanks for your comments, and you miss the fact that if quota
by storage is not set, DirectoryWithQuotaFeature.quota.tsCounts will be an
array[5] filled with -1L(StorageType.class.getEnumConstants() == 5). See
DirectoryWithQuotaFeature.Builder().
{code:java}
class DirectoryWithQuotaFeature$Builder {
public Builder() {
this.quota = new
QuotaCounts.Builder().nameSpace(DEFAULT_NAMESPACE_QUOTA).// new a long array[5]
here.
storageSpace(DEFAULT_STORAGE_SPACE_QUOTA).
typeSpaces(DEFAULT_STORAGE_SPACE_QUOTA).build();// set default value -1.
this.usage = new QuotaCounts.Builder().nameSpace(1).build();
}
public Builder typeSpaces(long val) {// set default value.
this.tsCounts.reset(val);
return this;
}
}
class QuotaCounts$Builder {
public Builder() {
this.nsSsCounts = new EnumCounters<Quota>(Quota.class);
this.tsCounts = new EnumCounters<StorageType>(StorageType.class);
}
}
class EnumCounters {
public EnumCounters(final Class<E> enumClass) {
final E[] enumConstants = enumClass.getEnumConstants();
Preconditions.checkNotNull(enumConstants);
this.enumClass = enumClass;
this.counters = new long[enumConstants.length];// new a long array here.
}
}{code}
So if the quota by storage is not set, we will loop up for all storage types
and return, not just one check.
Correct me if i'm wrong, hope for all comments.:)
> Remove redundant code when verify quota
> ---------------------------------------
>
> Key: HDFS-14542
> URL: https://issues.apache.org/jira/browse/HDFS-14542
> Project: Hadoop HDFS
> Issue Type: Improvement
> Affects Versions: 3.1.1
> Reporter: Jinglun
> Assignee: Jinglun
> Priority: Minor
> Attachments: HDFS-14542.patch
>
>
> DirectoryWithQuotaFeature.verifyQuotaByStorageType() does the job of
> verifying quota. It's redundant to call isQuotaByStorageTypeSet() because the
> for each iterator nextline has done the same job.
> {code:java}
> private void verifyQuotaByStorageType(EnumCounters<StorageType> typeDelta)
> throws QuotaByStorageTypeExceededException {
> if (!isQuotaByStorageTypeSet()) { // REDUNDANT.
> return;
> }
> for (StorageType t: StorageType.getTypesSupportingQuota()) {
> if (!isQuotaByStorageTypeSet(t)) { // CHECK FOR EACH STORAGETYPE.
> continue;
> }
> if (Quota.isViolated(quota.getTypeSpace(t), usage.getTypeSpace(t),
> typeDelta.get(t))) {
> throw new QuotaByStorageTypeExceededException(
> quota.getTypeSpace(t), usage.getTypeSpace(t) + typeDelta.get(t), t);
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]