Class Segment


  • public class Segment
    extends java.lang.Object
    A segment is a sequence of messages sent by a single producer into a single partition. The same producer will maintain a different segment in each of the partitions it writes into. On the other hand, many distinct producers can maintain their own segment for the same partition, in which case, the messages contained in these various segments will be interleaved. This class keeps track of the state of a segment: - The partition it belongs to. - Its segmentNumber number within its partition. - Whether it has started. - Whether it has ended. - The current sequence number. - The running checksum.
    • Constructor Detail

      • Segment

        public Segment​(int partition,
                       int segmentNumber,
                       int sequenceNumber,
                       CheckSumType checkSumType,
                       java.util.Map<java.lang.CharSequence,​java.lang.CharSequence> debugInfo,
                       java.util.Map<java.lang.CharSequence,​java.lang.Long> aggregates)
      • Segment

        public Segment​(int partition,
                       int segmentNumber,
                       CheckSumType checkSumType)
      • Segment

        public Segment​(int partition,
                       ProducerPartitionState state)
        Build a segment with checkpoint producer state on disk.
      • Segment

        public Segment​(Segment segment)
    • Method Detail

      • getSegmentNumber

        public int getSegmentNumber()
      • getPartition

        public int getPartition()
      • getAndIncrementSequenceNumber

        public int getAndIncrementSequenceNumber()
        N.B. This function is not threadsafe. Locking must be handled by the caller.
      • setSequenceNumber

        public void setSequenceNumber​(int sequenceNum)
        This function should only be used for hybrid store after receiving 'EOP' when skipping a message in the sequence.
        Parameters:
        sequenceNum -
      • getSequenceNumber

        public int getSequenceNumber()
      • getDebugInfo

        public java.util.Map<java.lang.CharSequence,​java.lang.CharSequence> getDebugInfo()
      • getAggregates

        public java.util.Map<java.lang.CharSequence,​java.lang.Long> getAggregates()
      • getCheckSumState

        public byte[] getCheckSumState()
        `synchronized` keyword will guarantee the caller will always get the checksum after processing the full record in function: addToCheckSum(KafkaKey, KafkaMessageEnvelope).
        Returns:
      • isStarted

        public boolean isStarted()
      • isEnded

        public boolean isEnded()
      • isRegistered

        public boolean isRegistered()
      • getLastSuccessfulOffset

        public long getLastSuccessfulOffset()
      • setLastSuccessfulOffset

        public void setLastSuccessfulOffset​(long lastSuccessfulOffset)
      • getLastRecordTimestamp

        public long getLastRecordTimestamp()
      • setLastRecordTimestamp

        public void setLastRecordTimestamp​(long lastRecordTimestamp)
      • getLastRecordProducerTimestamp

        public long getLastRecordProducerTimestamp()
      • setLastRecordProducerTimestamp

        public void setLastRecordProducerTimestamp​(long lastRecordProducerTimestamp)
      • start

        public void start()
      • end

        public void end​(boolean finalSegment)
      • registeredSegment

        public void registeredSegment()
      • isNewSegment

        public boolean isNewSegment()
      • setNewSegment

        public void setNewSegment​(boolean newSegment)
      • getFinalCheckSum

        public byte[] getFinalCheckSum()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • setStarted

        public void setStarted​(boolean started)