Class KafkaKey

java.lang.Object
com.linkedin.venice.message.KafkaKey
All Implemented Interfaces:
Measurable

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

    • CONTROL_MESSAGE_KAFKA_KEY_LENGTH

      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 Details

    • KafkaKey

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

      public KafkaKey(byte keyHeaderByte, @Nonnull byte[] key)
  • Method Details

    • 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.
      Returns:
      a single byte: '0' for PUT and DELETE, or '2' for CONTROL_MESSAGE
    • isControlMessage

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

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

      public int getKeyLength()
    • toString

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

      public int getHeapSize()
      Specified by:
      getHeapSize in interface Measurable