Class KafkaKey

  • public class KafkaKey
    extends java.lang.Object
    Class which stores the components of a Kafka Key, and is the format specified in the KafkaKeySerializer.
    • Field Detail


        public static final int CONTROL_MESSAGE_KAFKA_KEY_LENGTH
        For control messages, the Key part of the KafkaKey includes the producer GUID, segment and sequence number. N.B.: This could be optimized further by defining an Avro record to hold this data, since Avro would use variable length encoding for the two integers, which would be smaller than their regular size.
      • HEART_BEAT

        public static final KafkaKey HEART_BEAT
    • Constructor Detail

      • KafkaKey

        public KafkaKey​(@Nonnull
                        MessageType messageType,
                        byte[] key)
      • KafkaKey

        public KafkaKey​(byte keyHeaderByte,
                        byte[] key)
    • Method Detail

      • getKeyHeaderByte

        public byte getKeyHeaderByte()
        The key header byte is the first byte in the content of the Kafka key. This is significant because it affects Kafka's Log Compaction. For MessageType.PUT and MessageType.DELETE, we want to use the exact same Kafka key, so the header byte needs to be the same. For control messages, however, we want them to be name-spaced on their own, so that they do not collide with the data when Log Compaction runs.
        a single byte: '0' for PUT and DELETE, or '2' for CONTROL_MESSAGE
      • isControlMessage

        public boolean isControlMessage()
        true if this key corresponds to a control message, and false otherwise.
      • getKey

        public byte[] getKey()
        the content of the key (everything beyond the first byte)
      • getKeyLength

        public int getKeyLength()
      • getEstimatedObjectSizeOnHeap

        public int getEstimatedObjectSizeOnHeap()
      • toString

        public java.lang.String toString()
        toString in class java.lang.Object