/// <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);
            }
        }
Exemple #2
0
        /// <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());
        }
Exemple #3
0
            /// <exception cref="Org.Apache.Hadoop.Hdfs.Protocol.QuotaExceededException"/>
            internal virtual void RestoreSource()
            {
                // Rename failed - restore src
                INode oldSrcChild = srcChild;

                // put it back
                if (withCount == null)
                {
                    srcChild.SetLocalName(srcChildName);
                }
                else
                {
                    if (!srcChildIsReference)
                    {
                        // src must be in snapshot
                        // the withCount node will no longer be used thus no need to update
                        // its reference number here
                        srcChild = withCount.GetReferredINode();
                        srcChild.SetLocalName(srcChildName);
                    }
                    else
                    {
                        withCount.RemoveReference(oldSrcChild.AsReference());
                        srcChild = new INodeReference.DstReference(srcParent, withCount, srcRefDstSnapshot
                                                                   );
                        withCount.GetReferredINode().SetLocalName(srcChildName);
                    }
                }
                if (isSrcInSnapshot)
                {
                    srcParent.UndoRename4ScrParent(oldSrcChild.AsReference(), srcChild);
                }
                else
                {
                    // srcParent is not an INodeDirectoryWithSnapshot, we only need to add
                    // the srcChild back
                    fsd.AddLastINodeNoQuotaCheck(srcParentIIP, srcChild);
                }
            }