final INodeDirectory rootDir = sourceNamesystem.dir.rootDir; final long numINodes = rootDir.getDirectoryWithQuotaFeature() .getSpaceConsumed().getNameSpace(); String sdPath = newFile.getParentFile().getParentFile().getAbsolutePath(); Step step = new Step(StepType.INODES, sdPath);
public DirectoryWithQuotaFeature build() { return new DirectoryWithQuotaFeature(this); } }
if (useCache && q != null && q.isQuotaSet()) { // use the cached quota return q.AddCurrentSpaceUsage(counts); } else { useCache = q != null && !q.isQuotaSet() ? false : useCache; return computeDirectoryQuotaUsage(bsps, blockStoragePolicyId, counts, useCache, lastSnapshotId);
@Override public String toString() { return "Quota[" + namespaceString() + ", " + storagespaceString() + ", " + typeSpaceString() + "]"; } }
private static QuotaUsage getQuotaUsageInt(FSDirectory fsd, INodesInPath iip) throws IOException { fsd.readLock(); try { INode targetNode = iip.getLastINode(); QuotaUsage usage = null; if (targetNode.isDirectory()) { DirectoryWithQuotaFeature feature = targetNode.asDirectory().getDirectoryWithQuotaFeature(); if (feature != null) { QuotaCounts counts = feature.getSpaceConsumed(); QuotaCounts quotas = feature.getQuota(); usage = new QuotaUsage.Builder(). fileAndDirectoryCount(counts.getNameSpace()). quota(quotas.getNameSpace()). spaceConsumed(counts.getStorageSpace()). spaceQuota(quotas.getStorageSpace()). typeConsumed(counts.getTypeSpaces().asArray()). typeQuota(quotas.getTypeSpaces().asArray()).build(); } } return usage; } finally { fsd.readUnlock(); } }
@Override public void addSpaceConsumed(QuotaCounts counts) { super.addSpaceConsumed(counts); final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature(); if (q != null && isQuotaSet()) { q.addSpaceConsumed2Cache(counts); } }
void addSpaceConsumed(final INodeDirectory dir, final QuotaCounts counts, boolean verify) throws QuotaExceededException { if (dir.isQuotaSet()) { // The following steps are important: // check quotas in this inode and all ancestors before changing counts // so that no change is made if there is any quota violation. // (1) verify quota in this inode if (verify) { verifyQuota(counts); } // (2) verify quota and then add count in ancestors dir.addSpaceConsumed2Parent(counts, verify); // (3) add count in this inode addSpaceConsumed2Cache(counts); } else { dir.addSpaceConsumed2Parent(counts, verify); } }
ContentSummaryComputationContext computeContentSummary(final INodeDirectory dir, final ContentSummaryComputationContext summary) throws AccessControlException { final long original = summary.getCounts().getStoragespace(); long oldYieldCount = summary.getYieldCount(); dir.computeDirectoryContentSummary(summary, Snapshot.CURRENT_STATE_ID); // Check only when the content has not changed in the middle. if (oldYieldCount == summary.getYieldCount()) { checkStoragespace(dir, summary.getCounts().getStoragespace() - original); } return summary; }
@Override public QuotaCounts getQuotaCounts() { final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature(); return q != null? q.getQuota(): super.getQuotaCounts(); }
private void verifyQuotaByStorageType(EnumCounters<StorageType> typeDelta) throws QuotaByStorageTypeExceededException { if (!isQuotaByStorageTypeSet()) { return; } for (StorageType t: StorageType.getTypesSupportingQuota()) { if (!isQuotaByStorageTypeSet(t)) { 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); } } }
@Override public ContentSummaryComputationContext computeContentSummary(int snapshotId, ContentSummaryComputationContext summary) throws AccessControlException { final DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature(); if (sf != null && snapshotId == Snapshot.CURRENT_STATE_ID) { final ContentCounts counts = new ContentCounts.Builder().build(); // if the getContentSummary call is against a non-snapshot path, the // computation should include all the deleted files/directories sf.computeContentSummary4Snapshot(summary.getBlockStoragePolicySuite(), counts); summary.getCounts().addContents(counts); // Also add ContentSummary to snapshotCounts (So we can extract it // later from the ContentSummary of all). summary.getSnapshotCounts().addContents(counts); } final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature(); if (q != null && snapshotId == Snapshot.CURRENT_STATE_ID) { return q.computeContentSummary(this, summary); } else { return computeDirectoryContentSummary(summary, snapshotId); } }
@Override public String toString() { return "Quota[" + namespaceString() + ", " + storagespaceString() + ", " + typeSpaceString() + "]"; } }
public void updateCount(INodesInPath iip, INode.QuotaDelta quotaDelta, boolean check) throws QuotaExceededException { QuotaCounts counts = quotaDelta.getCountsCopy(); updateCount(iip, iip.length() - 1, counts.negation(), check); Map<INode, QuotaCounts> deltaInOtherPaths = quotaDelta.getUpdateMap(); for (Map.Entry<INode, QuotaCounts> entry : deltaInOtherPaths.entrySet()) { INodesInPath path = INodesInPath.fromINode(entry.getKey()); updateCount(path, path.length() - 1, entry.getValue().negation(), check); } for (Map.Entry<INodeDirectory, QuotaCounts> entry : quotaDelta.getQuotaDirMap().entrySet()) { INodeDirectory quotaDir = entry.getKey(); quotaDir.getDirectoryWithQuotaFeature().addSpaceConsumed2Cache( entry.getValue().negation()); } }
void addSpaceConsumed(final INodeDirectory dir, final QuotaCounts counts, boolean verify) throws QuotaExceededException { if (dir.isQuotaSet()) { // The following steps are important: // check quotas in this inode and all ancestors before changing counts // so that no change is made if there is any quota violation. // (1) verify quota in this inode if (verify) { verifyQuota(counts); } // (2) verify quota and then add count in ancestors dir.addSpaceConsumed2Parent(counts, verify); // (3) add count in this inode addSpaceConsumed2Cache(counts); } else { dir.addSpaceConsumed2Parent(counts, verify); } }
ContentSummaryComputationContext computeContentSummary(final INodeDirectory dir, final ContentSummaryComputationContext summary) { final long original = summary.getCounts().getStoragespace(); long oldYieldCount = summary.getYieldCount(); dir.computeDirectoryContentSummary(summary, Snapshot.CURRENT_STATE_ID); // Check only when the content has not changed in the middle. if (oldYieldCount == summary.getYieldCount()) { checkStoragespace(dir, summary.getCounts().getStoragespace() - original); } return summary; }
@Override public QuotaCounts getQuotaCounts() { final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature(); return q != null? q.getQuota(): super.getQuotaCounts(); }
private void verifyQuotaByStorageType(EnumCounters<StorageType> typeDelta) throws QuotaByStorageTypeExceededException { if (!isQuotaByStorageTypeSet()) { return; } for (StorageType t: StorageType.getTypesSupportingQuota()) { if (!isQuotaByStorageTypeSet(t)) { 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); } } }
@Override public ContentSummaryComputationContext computeContentSummary( ContentSummaryComputationContext summary) { final DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature(); if (sf != null) { sf.computeContentSummary4Snapshot(summary.getBlockStoragePolicySuite(), summary.getCounts()); } final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature(); if (q != null) { return q.computeContentSummary(this, summary); } else { return computeDirectoryContentSummary(summary, Snapshot.CURRENT_STATE_ID); } }
long totalInodes() { readLock(); try { return rootDir.getDirectoryWithQuotaFeature().getSpaceConsumed() .getNameSpace(); } finally { readUnlock(); } }
@Override public String toString() { return "Quota[" + namespaceString() + ", " + storagespaceString() + ", " + typeSpaceString() + "]"; } }