/// <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); } }
/// <exception cref="System.IO.IOException"/> internal void SerializeINodeSection(OutputStream @out) { INodeMap inodesMap = fsn.dir.GetINodeMap(); FsImageProto.INodeSection.Builder b = FsImageProto.INodeSection.NewBuilder().SetLastInodeId (fsn.dir.GetLastInodeId()).SetNumInodes(inodesMap.Size()); FsImageProto.INodeSection s = ((FsImageProto.INodeSection)b.Build()); s.WriteDelimitedTo(@out); int i = 0; IEnumerator <INodeWithAdditionalFields> iter = inodesMap.GetMapIterator(); while (iter.HasNext()) { INodeWithAdditionalFields n = iter.Next(); Save(@out, n); ++i; if (i % FSImageFormatProtobuf.Saver.CheckCancelInterval == 0) { context.CheckCancelled(); } } parent.CommitSection(summary, FSImageFormatProtobuf.SectionName.Inode); }