/// <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 override void Run() { try { Sharpen.Thread.Sleep(1000); TestDeleteRace.Log.Info("Deleting" + this.path); FSDirectory fsdir = this._enclosing.cluster.GetNamesystem().dir; INode fileINode = fsdir.GetINode4Write(this.path.ToString()); INodeMap inodeMap = (INodeMap)Whitebox.GetInternalState(fsdir, "inodeMap"); this.fs.Delete(this.path, false); // after deletion, add the inode back to the inodeMap inodeMap.Put(fileINode); TestDeleteRace.Log.Info("Deleted" + this.path); } catch (Exception e) { TestDeleteRace.Log.Info(e); } }