/// <exception cref="System.IO.IOException"/> private void LoadINodeDirSection(FileInputStream fin, IList <FsImageProto.FileSummary.Section > sections, FsImageProto.FileSummary summary, Configuration conf) { Log.Info("Loading INode directory section."); long startTime = Time.MonotonicNow(); foreach (FsImageProto.FileSummary.Section section in sections) { if (FSImageFormatProtobuf.SectionName.FromString(section.GetName()) == FSImageFormatProtobuf.SectionName .InodeDir) { fin.GetChannel().Position(section.GetOffset()); InputStream @is = FSImageUtil.WrapInputStreamForCompression(conf, summary.GetCodec (), new BufferedInputStream(new LimitInputStream(fin, section.GetLength()))); BuildNamespace(@is); } } long timeTaken = Time.MonotonicNow() - startTime; Log.Info("Finished loading INode directory section in {}ms", timeTaken); }
/// <exception cref="System.IO.IOException"/> private void Output(Configuration conf, FsImageProto.FileSummary summary, FileInputStream fin, AList <FsImageProto.FileSummary.Section> sections) { InputStream @is; long startTime = Time.MonotonicNow(); foreach (FsImageProto.FileSummary.Section section in sections) { if (FSImageFormatProtobuf.SectionName.FromString(section.GetName()) == FSImageFormatProtobuf.SectionName .Inode) { fin.GetChannel().Position(section.GetOffset()); @is = FSImageUtil.WrapInputStreamForCompression(conf, summary.GetCodec(), new BufferedInputStream (new LimitInputStream(fin, section.GetLength()))); OutputINodes(@is); } } long timeTaken = Time.MonotonicNow() - startTime; Log.Debug("Time to output inodes: {}ms", timeTaken); }
/// <exception cref="System.IO.IOException"/> public virtual void Visit(RandomAccessFile file) { Configuration conf = new Configuration(); if (!FSImageUtil.CheckFileFormat(file)) { throw new IOException("Unrecognized FSImage"); } FsImageProto.FileSummary summary = FSImageUtil.LoadSummary(file); using (FileInputStream fin = new FileInputStream(file.GetFD())) { InputStream @is; AList <FsImageProto.FileSummary.Section> sections = Lists.NewArrayList(summary.GetSectionsList ()); sections.Sort(new _IComparer_427()); foreach (FsImageProto.FileSummary.Section section in sections) { fin.GetChannel().Position(section.GetOffset()); @is = FSImageUtil.WrapInputStreamForCompression(conf, summary.GetCodec(), new BufferedInputStream (new LimitInputStream(fin, section.GetLength()))); switch (FSImageFormatProtobuf.SectionName.FromString(section.GetName())) { case FSImageFormatProtobuf.SectionName.StringTable: { stringTable = FSImageLoader.LoadStringTable(@is); break; } default: { break; } } } LoadDirectories(fin, sections, summary, conf); LoadINodeDirSection(fin, sections, summary, conf); metadataMap.Sync(); Output(conf, summary, fin, sections); } }
/// <exception cref="System.IO.IOException"/> internal void Visit(RandomAccessFile file) { if (!FSImageUtil.CheckFileFormat(file)) { throw new IOException("Unrecognized FSImage"); } FsImageProto.FileSummary summary = FSImageUtil.LoadSummary(file); using (FileInputStream @in = new FileInputStream(file.GetFD())) { foreach (FsImageProto.FileSummary.Section s in summary.GetSectionsList()) { if (FSImageFormatProtobuf.SectionName.FromString(s.GetName()) != FSImageFormatProtobuf.SectionName .Inode) { continue; } @in.GetChannel().Position(s.GetOffset()); InputStream @is = FSImageUtil.WrapInputStreamForCompression(conf, summary.GetCodec (), new BufferedInputStream(new LimitInputStream(@in, s.GetLength()))); Run(@is); Output(); } } }
/// <exception cref="System.IO.IOException"/> public void Visit(RandomAccessFile file) { if (!FSImageUtil.CheckFileFormat(file)) { throw new IOException("Unrecognized FSImage"); } FsImageProto.FileSummary summary = FSImageUtil.LoadSummary(file); using (FileInputStream fin = new FileInputStream(file.GetFD())) { @out.Write("<?xml version=\"1.0\"?>\n<fsimage>"); AList <FsImageProto.FileSummary.Section> sections = Lists.NewArrayList(summary.GetSectionsList ()); sections.Sort(new _IComparer_83()); foreach (FsImageProto.FileSummary.Section s in sections) { fin.GetChannel().Position(s.GetOffset()); InputStream @is = FSImageUtil.WrapInputStreamForCompression(conf, summary.GetCodec (), new BufferedInputStream(new LimitInputStream(fin, s.GetLength()))); switch (FSImageFormatProtobuf.SectionName.FromString(s.GetName())) { case FSImageFormatProtobuf.SectionName.NsInfo: { DumpNameSection(@is); break; } case FSImageFormatProtobuf.SectionName.StringTable: { LoadStringTable(@is); break; } case FSImageFormatProtobuf.SectionName.Inode: { DumpINodeSection(@is); break; } case FSImageFormatProtobuf.SectionName.InodeReference: { DumpINodeReferenceSection(@is); break; } case FSImageFormatProtobuf.SectionName.InodeDir: { DumpINodeDirectorySection(@is); break; } case FSImageFormatProtobuf.SectionName.FilesUnderconstruction: { DumpFileUnderConstructionSection(@is); break; } case FSImageFormatProtobuf.SectionName.Snapshot: { DumpSnapshotSection(@is); break; } case FSImageFormatProtobuf.SectionName.SnapshotDiff: { DumpSnapshotDiffSection(@is); break; } case FSImageFormatProtobuf.SectionName.SecretManager: { DumpSecretManagerSection(@is); break; } case FSImageFormatProtobuf.SectionName.CacheManager: { DumpCacheManagerSection(@is); break; } default: { break; } } } @out.Write("</fsimage>\n"); } }
/// <summary>Load fsimage into the memory.</summary> /// <param name="inputFile">the filepath of the fsimage to load.</param> /// <returns>FSImageLoader</returns> /// <exception cref="System.IO.IOException">if failed to load fsimage.</exception> internal static Org.Apache.Hadoop.Hdfs.Tools.OfflineImageViewer.FSImageLoader Load (string inputFile) { Configuration conf = new Configuration(); RandomAccessFile file = new RandomAccessFile(inputFile, "r"); if (!FSImageUtil.CheckFileFormat(file)) { throw new IOException("Unrecognized FSImage"); } FsImageProto.FileSummary summary = FSImageUtil.LoadSummary(file); using (FileInputStream fin = new FileInputStream(file.GetFD())) { // Map to record INodeReference to the referred id ImmutableList <long> refIdList = null; string[] stringTable = null; byte[][] inodes = null; IDictionary <long, long[]> dirmap = null; AList <FsImageProto.FileSummary.Section> sections = Lists.NewArrayList(summary.GetSectionsList ()); sections.Sort(new _IComparer_126()); foreach (FsImageProto.FileSummary.Section s in sections) { fin.GetChannel().Position(s.GetOffset()); InputStream @is = FSImageUtil.WrapInputStreamForCompression(conf, summary.GetCodec (), new BufferedInputStream(new LimitInputStream(fin, s.GetLength()))); Log.Debug("Loading section " + s.GetName() + " length: " + s.GetLength()); switch (FSImageFormatProtobuf.SectionName.FromString(s.GetName())) { case FSImageFormatProtobuf.SectionName.StringTable: { stringTable = LoadStringTable(@is); break; } case FSImageFormatProtobuf.SectionName.Inode: { inodes = LoadINodeSection(@is); break; } case FSImageFormatProtobuf.SectionName.InodeReference: { refIdList = LoadINodeReferenceSection(@is); break; } case FSImageFormatProtobuf.SectionName.InodeDir: { dirmap = LoadINodeDirectorySection(@is, refIdList); break; } default: { break; } } } return(new Org.Apache.Hadoop.Hdfs.Tools.OfflineImageViewer.FSImageLoader(stringTable , inodes, dirmap)); } }