/// <summary>Add a child inode to the directory.</summary> /// <param name="node">INode to insert</param> /// <param name="setModTime"> /// set modification time for the parent node /// not needed when replaying the addition and /// the parent already has the proper mod time /// </param> /// <returns> /// false if the child with this name already exists; /// otherwise, return true; /// </returns> /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/> public virtual bool AddChild(INode node, bool setModTime, int latestSnapshotId) { int low = SearchChildren(node.GetLocalNameBytes()); if (low >= 0) { return(false); } if (IsInLatestSnapshot(latestSnapshotId)) { // create snapshot feature if necessary DirectoryWithSnapshotFeature sf = this.GetDirectoryWithSnapshotFeature(); if (sf == null) { sf = this.AddSnapshotFeature(null); } return(sf.AddChild(this, node, setModTime, latestSnapshotId)); } AddChild(node, low); if (setModTime) { // update modification time of the parent directory UpdateModificationTime(node.GetModificationTime(), latestSnapshotId); } return(true); }
/// <summary>Replace the given child with a new child.</summary> /// <remarks> /// Replace the given child with a new child. Note that we no longer need to /// replace an normal INodeDirectory or INodeFile into an /// INodeDirectoryWithSnapshot or INodeFileUnderConstruction. The only cases /// for child replacement is for reference nodes. /// </remarks> public virtual void ReplaceChild(INode oldChild, INode newChild, INodeMap inodeMap ) { Preconditions.CheckNotNull(children); int i = SearchChildren(newChild.GetLocalNameBytes()); Preconditions.CheckState(i >= 0); Preconditions.CheckState(oldChild == children[i] || oldChild == children[i].AsReference ().GetReferredINode().AsReference().GetReferredINode()); oldChild = children[i]; if (oldChild.IsReference() && newChild.IsReference()) { // both are reference nodes, e.g., DstReference -> WithName INodeReference.WithCount withCount = (INodeReference.WithCount)oldChild.AsReference ().GetReferredINode(); withCount.RemoveReference(oldChild.AsReference()); } children.Set(i, newChild); // replace the instance in the created list of the diff list DirectoryWithSnapshotFeature sf = this.GetDirectoryWithSnapshotFeature(); if (sf != null) { sf.GetDiffs().ReplaceChild(Diff.ListType.Created, oldChild, newChild); } // update the inodeMap if (inodeMap != null) { inodeMap.Put(newChild); } }
public virtual bool AddChild(INode node) { int low = SearchChildren(node.GetLocalNameBytes()); if (low >= 0) { return(false); } AddChild(node, low); return(true); }
/// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/> internal RenameOperation(FSDirectory fsd, string src, string dst, INodesInPath srcIIP , INodesInPath dstIIP) { this.fsd = fsd; this.src = src; this.dst = dst; this.srcIIP = srcIIP; this.dstIIP = dstIIP; this.srcParentIIP = srcIIP.GetParentINodesInPath(); this.dstParentIIP = dstIIP.GetParentINodesInPath(); BlockStoragePolicySuite bsps = fsd.GetBlockStoragePolicySuite(); srcChild = this.srcIIP.GetLastINode(); srcChildName = srcChild.GetLocalNameBytes(); int srcLatestSnapshotId = srcIIP.GetLatestSnapshotId(); isSrcInSnapshot = srcChild.IsInLatestSnapshot(srcLatestSnapshotId); srcChildIsReference = srcChild.IsReference(); srcParent = this.srcIIP.GetINode(-2).AsDirectory(); // Record the snapshot on srcChild. After the rename, before any new // snapshot is taken on the dst tree, changes will be recorded in the // latest snapshot of the src tree. if (isSrcInSnapshot) { srcChild.RecordModification(srcLatestSnapshotId); } // check srcChild for reference srcRefDstSnapshot = srcChildIsReference ? srcChild.AsReference().GetDstSnapshotId () : Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId; oldSrcCounts = new QuotaCounts.Builder().Build(); if (isSrcInSnapshot) { INodeReference.WithName withName = srcParent.ReplaceChild4ReferenceWithName(srcChild , srcLatestSnapshotId); withCount = (INodeReference.WithCount)withName.GetReferredINode(); srcChild = withName; this.srcIIP = INodesInPath.Replace(srcIIP, srcIIP.Length() - 1, srcChild); // get the counts before rename withCount.GetReferredINode().ComputeQuotaUsage(bsps, oldSrcCounts, true); } else { if (srcChildIsReference) { // srcChild is reference but srcChild is not in latest snapshot withCount = (INodeReference.WithCount)srcChild.AsReference().GetReferredINode(); } else { withCount = null; } } }
/// <summary>Remove the specified child from this directory.</summary> /// <remarks> /// Remove the specified child from this directory. /// The basic remove method which actually calls children.remove(..). /// </remarks> /// <param name="child">the child inode to be removed</param> /// <returns>true if the child is removed; false if the child is not found.</returns> public virtual bool RemoveChild(INode child) { int i = SearchChildren(child.GetLocalNameBytes()); if (i < 0) { return(false); } INode removed = children.Remove(i); Preconditions.CheckState(removed == child); return(true); }
internal SnapshotCopy(INode inode) { this.name = inode.GetLocalNameBytes(); this.permission = inode.GetPermissionLong(); if (inode.GetAclFeature() != null) { aclFeature = AclStorage.AddAclFeature(inode.GetAclFeature()); } else { aclFeature = null; } this.modificationTime = inode.GetModificationTime(); this.accessTime = inode.GetAccessTime(); this.xAttrFeature = inode.GetXAttrFeature(); }
/// <exception cref="System.IO.IOException"/> private static IList <XAttr> GetXAttrs(FSDirectory fsd, string src) { string srcs = FSDirectory.NormalizePath(src); fsd.ReadLock(); try { INodesInPath iip = fsd.GetINodesInPath(srcs, true); INode inode = FSDirectory.ResolveLastINode(iip); int snapshotId = iip.GetPathSnapshotId(); return(XAttrStorage.ReadINodeXAttrs(fsd.GetAttributes(src, inode.GetLocalNameBytes (), inode, snapshotId))); } finally { fsd.ReadUnlock(); } }
/// <summary> /// Search for the given INode in the children list and the deleted lists of /// snapshots. /// </summary> /// <returns> /// /// <see cref="Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId /// "/> /// if the inode is in the children /// list; /// <see cref="Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId" /// /> /// if the inode is neither in the /// children list nor in any snapshot; otherwise the snapshot id of the /// corresponding snapshot diff list. /// </returns> public virtual int SearchChild(INode inode) { INode child = GetChild(inode.GetLocalNameBytes(), Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .CurrentStateId); if (child != inode) { // inode is not in parent's children list, thus inode must be in // snapshot. identify the snapshot id and later add it into the path DirectoryWithSnapshotFeature.DirectoryDiffList diffs = GetDiffs(); if (diffs == null) { return(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId); } return(diffs.FindSnapshotDeleted(inode)); } else { return(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId); } }
protected internal virtual ContentSummaryComputationContext ComputeDirectoryContentSummary (ContentSummaryComputationContext summary, int snapshotId) { ReadOnlyList <INode> childrenList = GetChildrenList(snapshotId); // Explicit traversing is done to enable repositioning after relinquishing // and reacquiring locks. for (int i = 0; i < childrenList.Size(); i++) { INode child = childrenList.Get(i); byte[] childName = child.GetLocalNameBytes(); long lastYieldCount = summary.GetYieldCount(); child.ComputeContentSummary(summary); // Check whether the computation was paused in the subtree. // The counts may be off, but traversing the rest of children // should be made safe. if (lastYieldCount == summary.GetYieldCount()) { continue; } // The locks were released and reacquired. Check parent first. if (GetParent() == null) { // Stop further counting and return whatever we have so far. break; } // Obtain the children list again since it may have been modified. childrenList = GetChildrenList(snapshotId); // Reposition in case the children list is changed. Decrement by 1 // since it will be incremented when loops. i = NextChild(childrenList, childName) - 1; } // Increment the directory count for this directory. summary.GetCounts().AddContent(Content.Directory, 1); // Relinquish and reacquire locks if necessary. summary.Yield(); return(summary); }
/// <exception cref="System.IO.IOException"/> internal static AclStatus GetAclStatus(FSDirectory fsd, string src) { CheckAclsConfigFlag(fsd); FSPermissionChecker pc = fsd.GetPermissionChecker(); byte[][] pathComponents = FSDirectory.GetPathComponentsForReservedPath(src); src = fsd.ResolvePath(pc, src, pathComponents); string srcs = FSDirectory.NormalizePath(src); fsd.ReadLock(); try { // There is no real inode for the path ending in ".snapshot", so return a // non-null, unpopulated AclStatus. This is similar to getFileInfo. if (srcs.EndsWith(HdfsConstants.SeparatorDotSnapshotDir) && fsd.GetINode4DotSnapshot (srcs) != null) { return(new AclStatus.Builder().Owner(string.Empty).Group(string.Empty).Build()); } INodesInPath iip = fsd.GetINodesInPath(srcs, true); if (fsd.IsPermissionEnabled()) { fsd.CheckTraverse(pc, iip); } INode inode = FSDirectory.ResolveLastINode(iip); int snapshotId = iip.GetPathSnapshotId(); IList <AclEntry> acl = AclStorage.ReadINodeAcl(fsd.GetAttributes(src, inode.GetLocalNameBytes (), inode, snapshotId)); FsPermission fsPermission = inode.GetFsPermission(snapshotId); return(new AclStatus.Builder().Owner(inode.GetUserName()).Group(inode.GetGroupName ()).StickyBit(fsPermission.GetStickyBit()).SetPermission(fsPermission).AddEntries (acl).Build()); } finally { fsd.ReadUnlock(); } }
private FsImageProto.INodeSection.INode.Builder BuildINodeCommon(INode n) { return(FsImageProto.INodeSection.INode.NewBuilder().SetId(n.GetId()).SetName(ByteString .CopyFrom(n.GetLocalNameBytes()))); }
/// <summary> /// Get a partial listing of the indicated directory /// We will stop when any of the following conditions is met: /// 1) this.lsLimit files have been added /// 2) needLocation is true AND enough files have been added such /// that at least this.lsLimit block locations are in the response /// </summary> /// <param name="fsd">FSDirectory</param> /// <param name="iip"> /// the INodesInPath instance containing all the INodes along the /// path /// </param> /// <param name="src">the directory name</param> /// <param name="startAfter">the name to start listing after</param> /// <param name="needLocation">if block locations are returned</param> /// <returns>a partial listing starting after startAfter</returns> /// <exception cref="System.IO.IOException"/> private static DirectoryListing GetListing(FSDirectory fsd, INodesInPath iip, string src, byte[] startAfter, bool needLocation, bool isSuperUser) { string srcs = FSDirectory.NormalizePath(src); bool isRawPath = FSDirectory.IsReservedRawName(src); fsd.ReadLock(); try { if (srcs.EndsWith(HdfsConstants.SeparatorDotSnapshotDir)) { return(GetSnapshotsListing(fsd, srcs, startAfter)); } int snapshot = iip.GetPathSnapshotId(); INode targetNode = iip.GetLastINode(); if (targetNode == null) { return(null); } byte parentStoragePolicy = isSuperUser ? targetNode.GetStoragePolicyID() : BlockStoragePolicySuite .IdUnspecified; if (!targetNode.IsDirectory()) { return(new DirectoryListing(new HdfsFileStatus[] { CreateFileStatus(fsd, src, HdfsFileStatus .EmptyName, targetNode, needLocation, parentStoragePolicy, snapshot, isRawPath, iip) }, 0)); } INodeDirectory dirInode = targetNode.AsDirectory(); ReadOnlyList <INode> contents = dirInode.GetChildrenList(snapshot); int startChild = INodeDirectory.NextChild(contents, startAfter); int totalNumChildren = contents.Size(); int numOfListing = Math.Min(totalNumChildren - startChild, fsd.GetLsLimit()); int locationBudget = fsd.GetLsLimit(); int listingCnt = 0; HdfsFileStatus[] listing = new HdfsFileStatus[numOfListing]; for (int i = 0; i < numOfListing && locationBudget > 0; i++) { INode cur = contents.Get(startChild + i); byte curPolicy = isSuperUser && !cur.IsSymlink() ? cur.GetLocalStoragePolicyID() : BlockStoragePolicySuite.IdUnspecified; listing[i] = CreateFileStatus(fsd, src, cur.GetLocalNameBytes(), cur, needLocation , GetStoragePolicyID(curPolicy, parentStoragePolicy), snapshot, isRawPath, iip); listingCnt++; if (needLocation) { // Once we hit lsLimit locations, stop. // This helps to prevent excessively large response payloads. // Approximate #locations with locatedBlockCount() * repl_factor LocatedBlocks blks = ((HdfsLocatedFileStatus)listing[i]).GetBlockLocations(); locationBudget -= (blks == null) ? 0 : blks.LocatedBlockCount() * listing[i].GetReplication (); } } // truncate return array if necessary if (listingCnt < numOfListing) { listing = Arrays.CopyOf(listing, listingCnt); } return(new DirectoryListing(listing, totalNumChildren - startChild - listingCnt)); } finally { fsd.ReadUnlock(); } }
internal virtual INodeReference.WithName ReplaceChild4ReferenceWithName(INode oldChild , int latestSnapshotId) { Preconditions.CheckArgument(latestSnapshotId != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .CurrentStateId); if (oldChild is INodeReference.WithName) { return((INodeReference.WithName)oldChild); } INodeReference.WithCount withCount; if (oldChild.IsReference()) { Preconditions.CheckState(oldChild is INodeReference.DstReference); withCount = (INodeReference.WithCount)oldChild.AsReference().GetReferredINode(); } else { withCount = new INodeReference.WithCount(null, oldChild); } INodeReference.WithName @ref = new INodeReference.WithName(this, withCount, oldChild .GetLocalNameBytes(), latestSnapshotId); ReplaceChild(oldChild, @ref, null); return(@ref); }