Package com.linkedin.venice.message
Class KafkaKey
java.lang.Object
com.linkedin.venice.message.KafkaKey
- All Implemented Interfaces:
Measurable
Class which stores the components of a Kafka Key, and is the format specified in the
KafkaKeySerializer.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionKafkaKey(byte keyHeaderByte, byte[] key) KafkaKey(MessageType messageType, byte[] key) -
Method Summary
-
Field Details
-
CONTROL_MESSAGE_KAFKA_KEY_LENGTH
public static final int CONTROL_MESSAGE_KAFKA_KEY_LENGTHFor control messages, the Key part of theKafkaKeyincludes 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
-
DOL_STAMP
Special key for Declaration of Leadership (DoL) control messages.Used during leader handover to confirm the new leader can write to and consume from the local VT. This is distinct from HEART_BEAT to clearly separate leadership declaration from heartbeat semantics.
The DoL mechanism provides deterministic confirmation that a new leader has successfully:
- Produced a message to the local version topic (VT)
- Consumed that message back from VT (loopback confirmation)
This eliminates the need for time-based waits during leader handover and provides strong guarantees that the leader is ready to switch to consuming from the leader source topic (remote VT or RT topic).
-
-
Constructor Details
-
KafkaKey
-
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. ForMessageType.PUTandMessageType.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.
-
isGlobalRtDiv
public boolean isGlobalRtDiv()- Returns:
- true if this key corresponds to a GlobalRtDiv message, and false otherwise.
-
getKey
public byte[] getKey()- Returns:
- the content of the key (everything beyond the first byte)
-
getKeyLength
public int getKeyLength() -
toString
-
getHeapSize
public int getHeapSize()- Specified by:
getHeapSizein interfaceMeasurable
-