private int GetSelfSnapshot(int prior) { INodeReference.WithCount wc = (INodeReference.WithCount)GetReferredINode().AsReference (); INode referred = wc.GetReferredINode(); int lastSnapshot = Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId; if (referred.IsFile() && referred.AsFile().IsWithSnapshot()) { lastSnapshot = referred.AsFile().GetDiffs().GetLastSnapshotId(); } else { if (referred.IsDirectory()) { DirectoryWithSnapshotFeature sf = referred.AsDirectory().GetDirectoryWithSnapshotFeature (); if (sf != null) { lastSnapshot = sf.GetLastSnapshotId(); } } } if (lastSnapshot != Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId && lastSnapshot != prior) { return(lastSnapshot); } else { return(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.CurrentStateId); } }
internal virtual bool AddSourceToDestination() { INode dstParent = dstParentIIP.GetLastINode(); byte[] dstChildName = dstIIP.GetLastLocalName(); INode toDst; if (withCount == null) { srcChild.SetLocalName(dstChildName); toDst = srcChild; } else { withCount.GetReferredINode().SetLocalName(dstChildName); toDst = new INodeReference.DstReference(dstParent.AsDirectory(), withCount, dstIIP .GetLatestSnapshotId()); } return(fsd.AddLastINodeNoQuotaCheck(dstParentIIP, toDst) != null); }
/// <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> /// When destroying a reference node (WithName or DstReference), we call this /// method to identify the snapshot which is the latest snapshot before the /// reference node's creation. /// </summary> internal static int GetPriorSnapshot(Org.Apache.Hadoop.Hdfs.Server.Namenode.INodeReference @ref) { INodeReference.WithCount wc = (INodeReference.WithCount)@ref.GetReferredINode(); INodeReference.WithName wn = null; if (@ref is INodeReference.DstReference) { wn = wc.GetLastWithName(); } else { if (@ref is INodeReference.WithName) { wn = wc.GetPriorWithName((INodeReference.WithName)@ref); } } if (wn != null) { INode referred = wc.GetReferredINode(); if (referred.IsFile() && referred.AsFile().IsWithSnapshot()) { return(referred.AsFile().GetDiffs().GetPrior(wn.lastSnapshotId)); } else { if (referred.IsDirectory()) { DirectoryWithSnapshotFeature sf = referred.AsDirectory().GetDirectoryWithSnapshotFeature (); if (sf != null) { return(sf.GetDiffs().GetPrior(wn.lastSnapshotId)); } } } } return(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot.NoSnapshotId); }