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); } }
public DstReference(INodeDirectory parent, INodeReference.WithCount referred, int dstSnapshotId) : base(parent, referred) { this.dstSnapshotId = dstSnapshotId; referred.AddReference(this); }
/// <summary> /// Serialize a /// <see cref="INodeReference"/> /// node /// </summary> /// <exception cref="System.IO.IOException"/> private static void WriteINodeReference(INodeReference @ref, DataOutput @out, bool writeUnderConstruction, SnapshotFSImageFormat.ReferenceMap referenceMap) { WriteLocalName(@ref, @out); @out.WriteLong(@ref.GetId()); @out.WriteShort(0); // replication @out.WriteLong(0); // modification time @out.WriteLong(0); // access time @out.WriteLong(0); // preferred block size @out.WriteInt(-3); // # of blocks bool isWithName = @ref is INodeReference.WithName; @out.WriteBoolean(isWithName); if (!isWithName) { Preconditions.CheckState(@ref is INodeReference.DstReference); // dst snapshot id @out.WriteInt(((INodeReference.DstReference)@ref).GetDstSnapshotId()); } else { @out.WriteInt(((INodeReference.WithName)@ref).GetLastSnapshotId()); } INodeReference.WithCount withCount = (INodeReference.WithCount)@ref.GetReferredINode (); referenceMap.WriteINodeReferenceWithCount(withCount, @out, writeUnderConstruction ); }
/// <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 WithName(INodeDirectory parent, INodeReference.WithCount referred, byte[] name, int lastSnapshotId) : base(parent, referred) { this.name = name; this.lastSnapshotId = lastSnapshotId; referred.AddReference(this); }
/// <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 given reference and then return the reference count.</summary> /// <remarks> /// Remove the given reference and then return the reference count. /// If the referred inode is not a WithCount, return -1; /// </remarks> private static int RemoveReference(Org.Apache.Hadoop.Hdfs.Server.Namenode.INodeReference @ref) { INode referred = @ref.GetReferredINode(); if (!(referred is INodeReference.WithCount)) { return(-1); } INodeReference.WithCount wc = (INodeReference.WithCount)referred; wc.RemoveReference(@ref); return(wc.GetReferenceCount()); }
/// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/> internal virtual void RestoreDst(BlockStoragePolicySuite bsps) { Preconditions.CheckState(oldDstChild != null); INodeDirectory dstParent = dstParentIIP.GetLastINode().AsDirectory(); if (dstParent.IsWithSnapshot()) { dstParent.UndoRename4DstParent(bsps, oldDstChild, dstIIP.GetLatestSnapshotId()); } else { fsd.AddLastINodeNoQuotaCheck(dstParentIIP, oldDstChild); } if (oldDstChild != null && oldDstChild.IsReference()) { INodeReference removedDstRef = oldDstChild.AsReference(); INodeReference.WithCount wc = (INodeReference.WithCount)removedDstRef.GetReferredINode ().AsReference(); wc.AddReference(removedDstRef); } }
/// <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); }
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); }