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); } } }
private void loadRootINode(INodeSection.INode p) { INodeDirectory root = loadINodeDirectory(p, parent.getLoaderContext()); final QuotaCounts q = root.getQuotaCounts(); final long nsQuota = q.getNameSpace(); final long dsQuota = q.getStorageSpace(); if (nsQuota != -1 || dsQuota != -1) { dir.rootDir.getDirectoryWithQuotaFeature().setQuota(nsQuota, dsQuota); } final EnumCounters<StorageType> typeQuotas = q.getTypeSpaces(); if (typeQuotas.anyGreaterOrEqual(0)) { dir.rootDir.getDirectoryWithQuotaFeature().setQuota(typeQuotas); } dir.rootDir.cloneModificationTime(root); dir.rootDir.clonePermissionStatus(root); // root dir supports having extended attributes according to POSIX final XAttrFeature f = root.getXAttrFeature(); if (f != null) { dir.rootDir.addXAttrFeature(f); } }
private void loadRootINode(INodeSection.INode p) { INodeDirectory root = loadINodeDirectory(p, parent.getLoaderContext()); final QuotaCounts q = root.getQuotaCounts(); final long nsQuota = q.getNameSpace(); final long dsQuota = q.getStorageSpace(); if (nsQuota != -1 || dsQuota != -1) { dir.rootDir.getDirectoryWithQuotaFeature().setQuota(nsQuota, dsQuota); } final EnumCounters<StorageType> typeQuotas = q.getTypeSpaces(); if (typeQuotas.anyGreaterOrEqual(0)) { dir.rootDir.getDirectoryWithQuotaFeature().setQuota(typeQuotas); } dir.rootDir.cloneModificationTime(root); dir.rootDir.clonePermissionStatus(root); final AclFeature af = root.getFeature(AclFeature.class); if (af != null) { dir.rootDir.addAclFeature(af); } // root dir supports having extended attributes according to POSIX final XAttrFeature f = root.getXAttrFeature(); if (f != null) { dir.rootDir.addXAttrFeature(f); } dir.addRootDirToEncryptionZone(f); }
public CopyWithQuota(byte[] name, PermissionStatus permissions, AclFeature aclFeature, long modificationTime, long nsQuota, long dsQuota, EnumCounters<StorageType> typeQuotas, XAttrFeature xAttrsFeature) { super(name, permissions, aclFeature, modificationTime, xAttrsFeature); this.quota = new QuotaCounts.Builder().nameSpace(nsQuota). storageSpace(dsQuota).typeSpaces(typeQuotas).build(); }
/** * Update usage count without replication factor change */ void updateCount(INodesInPath iip, long nsDelta, long ssDelta, short replication, boolean checkQuota) throws QuotaExceededException { final INodeFile fileINode = iip.getLastINode().asFile(); EnumCounters<StorageType> typeSpaceDeltas = getStorageTypeDeltas(fileINode.getStoragePolicyID(), ssDelta, replication, replication);; updateCount(iip, iip.length() - 1, new QuotaCounts.Builder().nameSpace(nsDelta).storageSpace(ssDelta * replication). typeSpaces(typeSpaceDeltas).build(), checkQuota); }
/** * Update usage count with replication factor change due to setReplication */ void updateCount(INodesInPath iip, long nsDelta, long ssDelta, short oldRep, short newRep, boolean checkQuota) throws QuotaExceededException { final INodeFile fileINode = iip.getLastINode().asFile(); EnumCounters<StorageType> typeSpaceDeltas = getStorageTypeDeltas(fileINode.getStoragePolicyID(), ssDelta, oldRep, newRep); updateCount(iip, iip.length() - 1, new QuotaCounts.Builder().nameSpace(nsDelta). storageSpace(ssDelta * (newRep - oldRep)). typeSpaces(typeSpaceDeltas).build(), checkQuota); }
/** * Update usage count without replication factor change */ void updateCount(INodesInPath iip, long nsDelta, long ssDelta, short replication, boolean checkQuota) throws QuotaExceededException { final INodeFile fileINode = iip.getLastINode().asFile(); EnumCounters<StorageType> typeSpaceDeltas = getStorageTypeDeltas(fileINode.getStoragePolicyID(), ssDelta, replication, replication); updateCount(iip, iip.length() - 1, new QuotaCounts.Builder().nameSpace(nsDelta).storageSpace(ssDelta * replication). typeSpaces(typeSpaceDeltas).build(), checkQuota); }
public Builder() { this.nsSsCounts = new EnumCounters<Quota>(Quota.class); this.tsCounts = new EnumCounters<StorageType>(StorageType.class); }
public Builder typeSpaces(EnumCounters<StorageType> val) { if (val != null) { this.tsCounts.set(val); } return this; }
public EnumCounters<StorageType> getTypeSpaces() { EnumCounters<StorageType> ret = new EnumCounters<StorageType>(StorageType.class); ret.set(tsCounts); return ret; }
void setTypeSpaces(EnumCounters<StorageType> that) { if (that != null) { this.tsCounts.set(that); } }
private static void updateCountForQuotaRecursively(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, INodeDirectory dir, QuotaCounts counts) { final long parentNamespace = counts.getNameSpace(); final long parentStoragespace = counts.getStorageSpace(); final EnumCounters<StorageType> parentTypeSpaces = counts.getTypeSpaces(); dir.computeQuotaUsage4CurrentDirectory(bsps, blockStoragePolicyId, counts); for (INode child : dir.getChildrenList(Snapshot.CURRENT_STATE_ID)) { final byte childPolicyId = child.getStoragePolicyIDForQuota(blockStoragePolicyId); if (child.isDirectory()) { updateCountForQuotaRecursively(bsps, childPolicyId, child.asDirectory(), counts); } else { // file or symlink: count here to reduce recursive calls. child.computeQuotaUsage(bsps, childPolicyId, counts, false, Snapshot.CURRENT_STATE_ID); } } if (dir.isQuotaSet()) { // check if quota is violated. It indicates a software bug. final QuotaCounts q = dir.getQuotaCounts(); final long namespace = counts.getNameSpace() - parentNamespace; final long nsQuota = q.getNameSpace(); if (Quota.isViolated(nsQuota, namespace)) { LOG.warn("Namespace quota violation in image for " + dir.getFullPathName() + " quota = " + nsQuota + " < consumed = " + namespace); } final long ssConsumed = counts.getStorageSpace() - parentStoragespace; final long ssQuota = q.getStorageSpace(); if (Quota.isViolated(ssQuota, ssConsumed)) { LOG.warn("Storagespace quota violation in image for " + dir.getFullPathName() + " quota = " + ssQuota + " < consumed = " + ssConsumed); } final EnumCounters<StorageType> typeSpaces = new EnumCounters<StorageType>(StorageType.class); for (StorageType t : StorageType.getTypesSupportingQuota()) { final long typeSpace = counts.getTypeSpaces().get(t) - parentTypeSpaces.get(t); final long typeQuota = q.getTypeSpaces().get(t); if (Quota.isViolated(typeQuota, typeSpace)) { LOG.warn("Storage type quota violation in image for " + dir.getFullPathName() + " type = " + t.toString() + " quota = " + typeQuota + " < consumed " + typeSpace); } } dir.getDirectoryWithQuotaFeature().setSpaceConsumed(namespace, ssConsumed, typeSpaces); } }
public Builder() { contents = new EnumCounters<Content>(Content.class); types = new EnumCounters<StorageType>(StorageType.class); }
private ContentCounts(EnumCounters<Content> contents, EnumCounters<StorageType> types) { this.contents = contents; this.types = types; }
public void addTypeSpaces(EnumCounters<StorageType> that) { this.types.add(that); }
public void compute() { QuotaCounts myCounts = new QuotaCounts.Builder().build(); dir.computeQuotaUsage4CurrentDirectory(bsps, blockStoragePolicyId, myCounts); ReadOnlyList<INode> children = dir.getChildrenList(CURRENT_STATE_ID); if (children.size() > 0) { List<InitQuotaTask> subtasks = new ArrayList<InitQuotaTask>(); for (INode child : children) { final byte childPolicyId = child.getStoragePolicyIDForQuota(blockStoragePolicyId); if (child.isDirectory()) { subtasks.add(new InitQuotaTask(bsps, childPolicyId, child.asDirectory(), myCounts)); } else { // file or symlink. count using the local counts variable myCounts.add(child.computeQuotaUsage(bsps, childPolicyId, false, CURRENT_STATE_ID)); } } // invoke and wait for completion invokeAll(subtasks); } if (dir.isQuotaSet()) { // check if quota is violated. It indicates a software bug. final QuotaCounts q = dir.getQuotaCounts(); final long nsConsumed = myCounts.getNameSpace(); final long nsQuota = q.getNameSpace(); if (Quota.isViolated(nsQuota, nsConsumed)) { LOG.warn("Namespace quota violation in image for " + dir.getFullPathName() + " quota = " + nsQuota + " < consumed = " + nsConsumed); } final long ssConsumed = myCounts.getStorageSpace(); final long ssQuota = q.getStorageSpace(); if (Quota.isViolated(ssQuota, ssConsumed)) { LOG.warn("Storagespace quota violation in image for " + dir.getFullPathName() + " quota = " + ssQuota + " < consumed = " + ssConsumed); } final EnumCounters<StorageType> tsConsumed = myCounts.getTypeSpaces(); for (StorageType t : StorageType.getTypesSupportingQuota()) { final long typeSpace = tsConsumed.get(t); final long typeQuota = q.getTypeSpaces().get(t); if (Quota.isViolated(typeQuota, typeSpace)) { LOG.warn("Storage type quota violation in image for " + dir.getFullPathName() + " type = " + t.toString() + " quota = " + typeQuota + " < consumed " + typeSpace); } } if (LOG.isDebugEnabled()) { LOG.debug("Setting quota for " + dir + "\n" + myCounts); } dir.getDirectoryWithQuotaFeature().setSpaceConsumed(nsConsumed, ssConsumed, tsConsumed); } synchronized(counts) { counts.add(myCounts); } }
/** * Sets namespace and storagespace take by the directory rooted * at this INode. This should be used carefully. It does not check * for quota violations. * * @param namespace size of the directory to be set * @param storagespace storage space take by all the nodes under this directory * @param typespaces counters of storage type usage */ void setSpaceConsumed(long namespace, long storagespace, EnumCounters<StorageType> typespaces) { usage.setNameSpace(namespace); usage.setStorageSpace(storagespace); usage.setTypeSpaces(typespaces); }