/// <exception cref="System.IO.IOException"/> internal void SerializeINodeDirectorySection(OutputStream @out) { IEnumerator <INodeWithAdditionalFields> iter = fsn.GetFSDirectory().GetINodeMap(). GetMapIterator(); AList <INodeReference> refList = parent.GetSaverContext().GetRefList(); int i = 0; while (iter.HasNext()) { INodeWithAdditionalFields n = iter.Next(); if (!n.IsDirectory()) { continue; } ReadOnlyList <INode> children = n.AsDirectory().GetChildrenList(Org.Apache.Hadoop.Hdfs.Server.Namenode.Snapshot.Snapshot .CurrentStateId); if (children.Size() > 0) { FsImageProto.INodeDirectorySection.DirEntry.Builder b = FsImageProto.INodeDirectorySection.DirEntry .NewBuilder().SetParent(n.GetId()); foreach (INode inode in children) { if (!inode.IsReference()) { b.AddChildren(inode.GetId()); } else { refList.AddItem(inode.AsReference()); b.AddRefChildren(refList.Count - 1); } } FsImageProto.INodeDirectorySection.DirEntry e = ((FsImageProto.INodeDirectorySection.DirEntry )b.Build()); e.WriteDelimitedTo(@out); } ++i; if (i % FSImageFormatProtobuf.Saver.CheckCancelInterval == 0) { context.CheckCancelled(); } } parent.CommitSection(summary, FSImageFormatProtobuf.SectionName.InodeDir); }
/// <exception cref="System.IO.IOException"/> private void SaveInternal(FileOutputStream fout, FSImageCompression compression, string filePath) { StartupProgress prog = NameNode.GetStartupProgress(); MessageDigest digester = MD5Hash.GetDigester(); underlyingOutputStream = new DigestOutputStream(new BufferedOutputStream(fout), digester ); underlyingOutputStream.Write(FSImageUtil.MagicHeader); fileChannel = fout.GetChannel(); FsImageProto.FileSummary.Builder b = FsImageProto.FileSummary.NewBuilder().SetOndiskVersion (FSImageUtil.FileVersion).SetLayoutVersion(NameNodeLayoutVersion.CurrentLayoutVersion ); codec = compression.GetImageCodec(); if (codec != null) { b.SetCodec(codec.GetType().GetCanonicalName()); sectionOutputStream = codec.CreateOutputStream(underlyingOutputStream); } else { sectionOutputStream = underlyingOutputStream; } SaveNameSystemSection(b); // Check for cancellation right after serializing the name system section. // Some unit tests, such as TestSaveNamespace#testCancelSaveNameSpace // depends on this behavior. context.CheckCancelled(); Step step = new Step(StepType.Inodes, filePath); prog.BeginStep(Phase.SavingCheckpoint, step); SaveInodes(b); SaveSnapshots(b); prog.EndStep(Phase.SavingCheckpoint, step); step = new Step(StepType.DelegationTokens, filePath); prog.BeginStep(Phase.SavingCheckpoint, step); SaveSecretManagerSection(b); prog.EndStep(Phase.SavingCheckpoint, step); step = new Step(StepType.CachePools, filePath); prog.BeginStep(Phase.SavingCheckpoint, step); SaveCacheManagerSection(b); prog.EndStep(Phase.SavingCheckpoint, step); SaveStringTableSection(b); // We use the underlyingOutputStream to write the header. Therefore flush // the buffered stream (which is potentially compressed) first. FlushSectionOutputStream(); FsImageProto.FileSummary summary = ((FsImageProto.FileSummary)b.Build()); SaveFileSummary(underlyingOutputStream, summary); underlyingOutputStream.Close(); savedDigest = new MD5Hash(digester.Digest()); }