private static INodeDirectory createRoot(FSNamesystem namesystem) { final INodeDirectory r = new INodeDirectory( INodeId.ROOT_INODE_ID, INodeDirectory.ROOT_NAME, namesystem.createFsOwnerPermissions(new FsPermission((short) 0755)), 0L); r.addDirectoryWithQuotaFeature( new DirectoryWithQuotaFeature.Builder(). nameSpaceQuota(DirectoryWithQuotaFeature.DEFAULT_NAMESPACE_QUOTA). storageSpaceQuota(DirectoryWithQuotaFeature.DEFAULT_STORAGE_SPACE_QUOTA). build()); r.addSnapshottableFeature(); r.setSnapshotQuota(0); return r; }
final int low = searchChildren(node.getLocalNameBytes()); if (low >= 0) { return false; if (isInLatestSnapshot(latestSnapshotId)) { DirectoryWithSnapshotFeature sf = this.getDirectoryWithSnapshotFeature(); if (sf == null) { sf = this.addSnapshotFeature(null); addChild(node, low); if (setModTime) { updateModificationTime(node.getModificationTime(), latestSnapshotId);
public void compute() { QuotaCounts myCounts = new QuotaCounts.Builder().build(); dir.computeQuotaUsage4CurrentDirectory(bsps, blockStoragePolicyId, myCounts); dir.getChildrenList(CURRENT_STATE_ID); if (dir.isQuotaSet()) { final QuotaCounts q = dir.getQuotaCounts(); if (Quota.isViolated(nsQuota, nsConsumed)) { LOG.warn("Namespace quota violation in image for " + dir.getFullPathName() + " quota = " + nsQuota + " < consumed = " + nsConsumed); if (Quota.isViolated(ssQuota, ssConsumed)) { LOG.warn("Storagespace quota violation in image for " + dir.getFullPathName() + " quota = " + ssQuota + " < consumed = " + ssConsumed); 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(nsConsumed, ssConsumed, tsConsumed);
@Override public byte getStoragePolicyID() { byte id = getLocalStoragePolicyID(); if (id != BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) { return id; } // if it is unspecified, check its parent return getParent() != null ? getParent().getStoragePolicyID() : BLOCK_STORAGE_POLICY_ID_UNSPECIFIED; }
/** * Remove the specified child from this directory. */ public boolean removeChild(INode child, int latestSnapshotId) { if (isInLatestSnapshot(latestSnapshotId)) { // create snapshot feature if necessary DirectoryWithSnapshotFeature sf = this.getDirectoryWithSnapshotFeature(); if (sf == null) { sf = this.addSnapshotFeature(null); } return sf.removeChild(this, child, latestSnapshotId); } return removeChild(child); }
/** * Check if this directory is a descendant directory * of a snapshot root directory. * @param snapshotRootDir the snapshot root directory * @return true if this directory is a descendant of snapshot root */ public boolean isDescendantOfSnapshotRoot(INodeDirectory snapshotRootDir) { Preconditions.checkArgument(snapshotRootDir.isSnapshottable()); INodeDirectory dir = this; while(dir != null) { if (dir.equals(snapshotRootDir)) { return true; } dir = dir.getParent(); } return false; }
new ArrayList<SnapshottableDirectoryStatus>(); for (INodeDirectory dir : snapshottables.values()) { if (userName == null || userName.equals(dir.getUserName())) { SnapshottableDirectoryStatus status = new SnapshottableDirectoryStatus( dir.getModificationTime(), dir.getAccessTime(), dir.getFsPermission(), EnumSet.noneOf(HdfsFileStatus.Flags.class), dir.getUserName(), dir.getGroupName(), dir.getLocalNameBytes(), dir.getId(), dir.getChildrenNum(Snapshot.CURRENT_STATE_ID), dir.getDirectorySnapshottableFeature().getNumSnapshots(), dir.getDirectorySnapshottableFeature().getSnapshotQuota(), dir.getParent() == null ? DFSUtilClient.EMPTY_BYTES : DFSUtil.string2Bytes(dir.getParent().getFullPathName())); statusList.add(status);
doReturn(false).when(mockDir2).addChild((INode) anyObject(), anyBoolean(), Mockito.anyInt()); INodeDirectory root = fsdir.getINode4Write("/").asDirectory(); root.replaceChild(dir2, mockDir2, fsdir.getINodeMap()); Snapshot s1 = dir1Node.getSnapshot(DFSUtil.string2Bytes("s1")); ReadOnlyList<INode> dir1Children = dir1Node .getChildrenList(Snapshot.CURRENT_STATE_ID); assertEquals(1, dir1Children.size()); assertEquals(foo.getName(), dir1Children.get(0).getLocalName()); List<DirectoryDiff> dir1Diffs = dir1Node.getDiffs().asList(); assertEquals(1, dir1Diffs.size()); assertEquals(s1.getId(), dir1Diffs.get(0).getSnapshotId()); assertTrue(fooNode.isDirectory() && fooNode.asDirectory().isWithSnapshot()); List<DirectoryDiff> fooDiffs = fooNode.asDirectory().getDiffs().asList(); assertEquals(1, fooDiffs.size()); assertEquals(s1.getId(), fooDiffs.get(0).getSnapshotId()); INodeDirectory dir2Node = fsdir.getINode4Write(sdir2.toString()) .asDirectory(); assertFalse(dir2Node.isWithSnapshot()); ReadOnlyList<INode> dir2Children = dir2Node .getChildrenList(Snapshot.CURRENT_STATE_ID); assertEquals(1, dir2Children.size()); assertEquals(dir2file.getName(), dir2Children.get(0).getLocalName());
public static SnapshottableDirectoryStatus.Bean toBean(INodeDirectory d) { return new SnapshottableDirectoryStatus.Bean( d.getFullPathName(), d.getDirectorySnapshottableFeature().getNumSnapshots(), d.getDirectorySnapshottableFeature().getSnapshotQuota(), d.getModificationTime(), Short.valueOf(Integer.toOctalString( d.getFsPermissionShort())), d.getUserName(), d.getGroupName()); }
void setQuota(BlockStoragePolicySuite bsps, long nsQuota, long ssQuota, StorageType type) { DirectoryWithQuotaFeature quota = getDirectoryWithQuotaFeature(); if (quota != null) { // already has quota; so set the quota to the new values if (type != null) { quota.setQuota(ssQuota, type); } else { quota.setQuota(nsQuota, ssQuota); } if (!isQuotaSet() && !isRoot()) { removeFeature(quota); } } else { final QuotaCounts c = computeQuotaUsage(bsps); DirectoryWithQuotaFeature.Builder builder = new DirectoryWithQuotaFeature.Builder().nameSpaceQuota(nsQuota); if (type != null) { builder.typeQuota(type, ssQuota); } else { builder.storageSpaceQuota(ssQuota); } addDirectoryWithQuotaFeature(builder.build()).setSpaceConsumed(c); } }
/** * Set the given directory as a snapshottable directory. * If the path is already a snapshottable directory, update the quota. */ public void setSnapshottable(final String path, boolean checkNestedSnapshottable) throws IOException { final INodesInPath iip = fsdir.getINodesInPath(path, DirOp.WRITE); final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path); if (checkNestedSnapshottable) { checkNestedSnapshottable(d, path); } if (d.isSnapshottable()) { //The directory is already a snapshottable directory. d.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT); } else { d.addSnapshottableFeature(); } addSnapshottable(d); }
@Override public QuotaCounts computeQuotaUsage(BlockStoragePolicySuite bsps, byte blockStoragePolicyId, boolean useCache, int lastSnapshotId) { final DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature(); && !(useCache && isQuotaSet())) { ReadOnlyList<INode> childrenList = getChildrenList(lastSnapshotId); for (INode child : childrenList) { final byte childPolicyId = child.getStoragePolicyIDForQuota( final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature(); 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);
counter.increment(); final INodeDirectory dir = new INodeDirectory(inodeId, localName, permissions, modificationTime); if (nsQuota >= 0 || dsQuota >= 0) { dir.addDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder(). nameSpaceQuota(nsQuota).storageSpaceQuota(dsQuota).build()); dir.addSnapshotFeature(null); dir.addSnapshottableFeature();
final INodeDirectory dir = new INodeDirectory(n.getId(), n.getName() .toByteArray(), permissions, d.getModificationTime()); final long nsQuota = d.getNsQuota(), dsQuota = d.getDsQuota(); if (nsQuota >= 0 || dsQuota >= 0) { dir.addDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature.Builder(). nameSpaceQuota(nsQuota).storageSpaceQuota(dsQuota).build()); DirectoryWithQuotaFeature q = dir.getDirectoryWithQuotaFeature(); if (q == null) { dir.addDirectoryWithQuotaFeature(new DirectoryWithQuotaFeature. Builder().typeQuotas(typeQuotas).build()); } else { int[] entries = AclEntryStatusFormat.toInt(loadAclEntries( d.getAcl(), state.getStringTable())); dir.addAclFeature(new AclFeature(entries)); dir.addXAttrFeature(new XAttrFeature( loadXAttrs(d.getXAttrs(), state.getStringTable())));
/** * Load the snapshots section from fsimage. Also add snapshottable feature * to snapshottable directories. */ public void loadSnapshotSection(InputStream in) throws IOException { SnapshotManager sm = fsn.getSnapshotManager(); SnapshotSection section = SnapshotSection.parseDelimitedFrom(in); int snum = section.getNumSnapshots(); sm.setNumSnapshots(snum); sm.setSnapshotCounter(section.getSnapshotCounter()); for (long sdirId : section.getSnapshottableDirList()) { INodeDirectory dir = fsDir.getInode(sdirId).asDirectory(); if (!dir.isSnapshottable()) { dir.addSnapshottableFeature(); } else { // dir is root, and admin set root to snapshottable before dir.setSnapshotQuota( DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT); } sm.addSnapshottable(dir); } loadSnapshots(in, snum); }
FsPermission p = getFsPermission(); children.add(-low - 1, node); setModificationTime(node.getModificationTime()); if (node.getGroupName() == null) { node.setGroup(getGroupName());
@Override public void cleanSubtree(ReclaimContext reclaimContext, final int snapshotId, int priorSnapshotId) { DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature(); // there is snapshot data if (sf != null) { sf.cleanDirectory(reclaimContext, this, snapshotId, priorSnapshotId); } else { // there is no snapshot data if (priorSnapshotId == Snapshot.NO_SNAPSHOT_ID && snapshotId == Snapshot.CURRENT_STATE_ID) { // destroy the whole subtree and collect blocks that should be deleted destroyAndCollectBlocks(reclaimContext); } else { // make a copy the quota delta QuotaCounts old = reclaimContext.quotaDelta().getCountsCopy(); // process recursively down the subtree cleanSubtreeRecursively(reclaimContext, snapshotId, priorSnapshotId, null); QuotaCounts current = reclaimContext.quotaDelta().getCountsCopy(); current.subtract(old); if (isQuotaSet()) { reclaimContext.quotaDelta().addQuotaDirUpdate(this, current); } } } }
ReadOnlyList<INode> childrenList = getChildrenList(snapshotId); if (!isRoot() && getParent() == null) { childrenList = getChildrenList(snapshotId); i = nextChild(childrenList, childName) - 1;
public CopyWithQuota(INodeDirectory dir) { super(dir); Preconditions.checkArgument(dir.isQuotaSet()); final QuotaCounts q = dir.getQuotaCounts(); this.quota = new QuotaCounts.Builder().quotaCount(q).build(); }
/** * create a directory at path specified by parent */ private static INodesInPath unprotectedMkdir(FSDirectory fsd, long inodeId, INodesInPath parent, byte[] name, PermissionStatus permission, List<AclEntry> aclEntries, long timestamp) throws QuotaExceededException, AclException, FileAlreadyExistsException { assert fsd.hasWriteLock(); assert parent.getLastINode() != null; if (!parent.getLastINode().isDirectory()) { throw new FileAlreadyExistsException("Parent path is not a directory: " + parent.getPath() + " " + DFSUtil.bytes2String(name)); } final INodeDirectory dir = new INodeDirectory(inodeId, name, permission, timestamp); INodesInPath iip = fsd.addLastINode(parent, dir, permission.getPermission(), true); if (iip != null && aclEntries != null) { AclStorage.updateINodeAcl(dir, aclEntries, Snapshot.CURRENT_STATE_ID); } return iip; } }