Package com.linkedin.venice.message
Class KafkaKey
- java.lang.Object
-
- com.linkedin.venice.message.KafkaKey
-
- All Implemented Interfaces:
Measurable
public class KafkaKey extends java.lang.Object implements Measurable
Class which stores the components of a Kafka Key, and is the format specified in theKafkaKeySerializer
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
CONTROL_MESSAGE_KAFKA_KEY_LENGTH
For control messages, the Key part of theKafkaKey
includes the producer GUID, segment and sequence number.static KafkaKey
HEART_BEAT
-
Constructor Summary
Constructors Constructor Description KafkaKey(byte keyHeaderByte, byte[] key)
KafkaKey(MessageType messageType, byte[] key)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getHeapSize()
byte[]
getKey()
byte
getKeyHeaderByte()
The key header byte is the first byte in the content of the Kafka key.int
getKeyLength()
boolean
isControlMessage()
java.lang.String
toString()
-
-
-
Field Detail
-
CONTROL_MESSAGE_KAFKA_KEY_LENGTH
public static final int CONTROL_MESSAGE_KAFKA_KEY_LENGTH
For control messages, the Key part of theKafkaKey
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, @Nonnull byte[] key)
-
KafkaKey
public KafkaKey(byte keyHeaderByte, @Nonnull 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. ForMessageType.PUT
andMessageType.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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getHeapSize
public int getHeapSize()
- Specified by:
getHeapSize
in interfaceMeasurable
-
-