Class PacketHeader

java.lang.Object
org.apache.hadoop.hdfs.protocol.datatransfer.PacketHeader

@Private @Evolving public class PacketHeader extends Object
Header data for each packet that goes through the read/write pipelines. Includes all of the information about the packet, excluding checksums and actual data. This data includes: - the offset in bytes into the HDFS block of the data in this packet - the sequence number of this packet in the pipeline - whether or not this is the last packet in the pipeline - the length of the data in this packet - whether or not this packet should be synced by the DNs. When serialized, this header is written out as a protocol buffer, preceded by a 4-byte integer representing the full packet length, and a 2-byte short representing the header length.
  • Field Details

    • PKT_LENGTHS_LEN

      public static final int PKT_LENGTHS_LEN
      See Also:
    • PKT_MAX_HEADER_LEN

      public static final int PKT_MAX_HEADER_LEN
  • Constructor Details

    • PacketHeader

      public PacketHeader()
    • PacketHeader

      public PacketHeader(int packetLen, long offsetInBlock, long seqno, boolean lastPacketInBlock, int dataLen, boolean syncBlock)
  • Method Details

    • getDataLen

      public int getDataLen()
    • isLastPacketInBlock

      public boolean isLastPacketInBlock()
    • getSeqno

      public long getSeqno()
    • getOffsetInBlock

      public long getOffsetInBlock()
    • getPacketLen

      public int getPacketLen()
    • getSyncBlock

      public boolean getSyncBlock()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setFieldsFromData

      public void setFieldsFromData(int packetLen, byte[] headerData) throws org.apache.hadoop.thirdparty.protobuf.InvalidProtocolBufferException
      Throws:
      org.apache.hadoop.thirdparty.protobuf.InvalidProtocolBufferException
    • readFields

      public void readFields(ByteBuffer buf) throws IOException
      Throws:
      IOException
    • readFields

      public void readFields(DataInputStream in) throws IOException
      Throws:
      IOException
    • getSerializedSize

      public int getSerializedSize()
      Returns:
      the number of bytes necessary to write out this header, including the length-prefixing of the payload and header
    • putInBuffer

      public void putInBuffer(ByteBuffer buf)
      Write the header into the buffer. This requires that PKT_HEADER_LEN bytes are available.
    • write

      public void write(DataOutputStream out) throws IOException
      Throws:
      IOException
    • getBytes

      public byte[] getBytes()
    • sanityCheck

      public boolean sanityCheck(long lastSeqNo)
      Perform a sanity check on the packet, returning true if it is sane.
      Parameters:
      lastSeqNo - the previous sequence number received - we expect the current sequence number to be larger by 1.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object