/// <exception cref="System.IO.IOException"/> public static FsImageProto.FileSummary LoadSummary(RandomAccessFile file) { int FileLengthFieldSize = 4; long fileLength = file.Length(); file.Seek(fileLength - FileLengthFieldSize); int summaryLength = file.ReadInt(); if (summaryLength <= 0) { throw new IOException("Negative length of the file"); } file.Seek(fileLength - FileLengthFieldSize - summaryLength); byte[] summaryBytes = new byte[summaryLength]; file.ReadFully(summaryBytes); FsImageProto.FileSummary summary = FsImageProto.FileSummary.ParseDelimitedFrom(new ByteArrayInputStream(summaryBytes)); if (summary.GetOndiskVersion() != FileVersion) { throw new IOException("Unsupported file version " + summary.GetOndiskVersion()); } if (!NameNodeLayoutVersion.Supports(LayoutVersion.Feature.ProtobufFormat, summary .GetLayoutVersion())) { throw new IOException("Unsupported layout version " + summary.GetLayoutVersion()); } return(summary); }
/// <exception cref="Org.Apache.Hadoop.Hdfs.Server.Namenode.EditLogFileInputStream.LogHeaderCorruptException /// "/> /// <exception cref="System.IO.IOException"/> private void Init(bool verifyLayoutVersion) { Preconditions.CheckState(state == EditLogFileInputStream.State.Uninit); BufferedInputStream bin = null; try { fStream = log.GetInputStream(); bin = new BufferedInputStream(fStream); tracker = new FSEditLogLoader.PositionTrackingInputStream(bin); dataIn = new DataInputStream(tracker); try { logVersion = ReadLogVersion(dataIn, verifyLayoutVersion); } catch (EOFException) { throw new EditLogFileInputStream.LogHeaderCorruptException("No header found in log" ); } // We assume future layout will also support ADD_LAYOUT_FLAGS if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddLayoutFlags, logVersion ) || logVersion < NameNodeLayoutVersion.CurrentLayoutVersion) { try { LayoutFlags.Read(dataIn); } catch (EOFException) { throw new EditLogFileInputStream.LogHeaderCorruptException("EOF while reading layout " + "flags from log"); } } reader = new FSEditLogOp.Reader(dataIn, tracker, logVersion); reader.SetMaxOpSize(maxOpSize); state = EditLogFileInputStream.State.Open; } finally { if (reader == null) { IOUtils.Cleanup(Log, dataIn, tracker, bin, fStream); state = EditLogFileInputStream.State.Closed; } } }
// Helper function that reads in an INodeUnderConstruction // from the input stream // /// <exception cref="System.IO.IOException"/> internal static INodeFile ReadINodeUnderConstruction(DataInput @in, FSNamesystem fsNamesys, int imgVersion) { byte[] name = ReadBytes(@in); long inodeId = NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddInodeId, imgVersion ) ? @in.ReadLong() : fsNamesys.dir.AllocateNewInodeId(); short blockReplication = @in.ReadShort(); long modificationTime = @in.ReadLong(); long preferredBlockSize = @in.ReadLong(); int numBlocks = @in.ReadInt(); BlockInfoContiguous[] blocks = new BlockInfoContiguous[numBlocks]; Block blk = new Block(); int i = 0; for (; i < numBlocks - 1; i++) { blk.ReadFields(@in); blocks[i] = new BlockInfoContiguous(blk, blockReplication); } // last block is UNDER_CONSTRUCTION if (numBlocks > 0) { blk.ReadFields(@in); blocks[i] = new BlockInfoContiguousUnderConstruction(blk, blockReplication, HdfsServerConstants.BlockUCState .UnderConstruction, null); } PermissionStatus perm = PermissionStatus.Read(@in); string clientName = ReadString(@in); string clientMachine = ReadString(@in); // We previously stored locations for the last block, now we // just record that there are none int numLocs = @in.ReadInt(); System.Diagnostics.Debug.Assert(numLocs == 0, "Unexpected block locations"); // Images in the pre-protobuf format will not have the lazyPersist flag, // so it is safe to pass false always. INodeFile file = new INodeFile(inodeId, name, perm, modificationTime, modificationTime , blocks, blockReplication, preferredBlockSize, unchecked ((byte)0)); file.ToUnderConstruction(clientName, clientMachine); return(file); }