Package com.linkedin.davinci.consumer
Class VeniceChangeCoordinate
java.lang.Object
com.linkedin.davinci.consumer.VeniceChangeCoordinate
- All Implemented Interfaces:
Externalizable
,Serializable
This class represents a change coordinate in Venice. It contains the topic name, partition number, and
the pubsub position.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
Value for undefined consumer sequence id. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
VeniceChangeCoordinate
(String topic, PubSubPosition pubSubPosition, Integer partition) protected
VeniceChangeCoordinate
(String topic, PubSubPosition pubSubPosition, Integer partition, long consumerSequenceId) -
Method Summary
Modifier and TypeMethodDescriptionint
static String
convertVeniceChangeCoordinateToStringAndEncode
(VeniceChangeCoordinate veniceChangeCoordinate) static VeniceChangeCoordinate
decodeStringAndConvertToVeniceChangeCoordinate
(PubSubPositionDeserializer deserializer, String offsetString) boolean
long
Returns the consumer sequence id for thisVeniceChangeCoordinate
.protected PubSubPosition
protected String
getTopic()
int
hashCode()
void
Deserializes VeniceChangeCoordinate while supporting both legacy (v1) and newer (v2+) formats.protected void
setPubSubPositionDeserializer
(PubSubPositionDeserializer pubSubPositionDeserializer) toString()
void
Serializes the VeniceChangeCoordinate in a backward-compatible format.
-
Field Details
-
UNDEFINED_CONSUMER_SEQUENCE_ID
public static final long UNDEFINED_CONSUMER_SEQUENCE_IDValue for undefined consumer sequence id. This can happen when we decode a serialized VeniceChangeCoordinate before the consumer sequence id field was introduced. This can also happen when the VeniceChangeCoordinate was created without a valid consumer sequence id. e.g. Created not by consuming from the change log but instead from an arbitraryPubSubPosition
.- See Also:
-
-
Constructor Details
-
VeniceChangeCoordinate
public VeniceChangeCoordinate() -
VeniceChangeCoordinate
-
VeniceChangeCoordinate
protected VeniceChangeCoordinate(String topic, PubSubPosition pubSubPosition, Integer partition, long consumerSequenceId)
-
-
Method Details
-
writeExternal
Serializes the VeniceChangeCoordinate in a backward-compatible format.The serialization format is structured as follows:
- Core fields: topic, partition, pubSubPositionWireFormat
- Version tag: a UTF string that identifies the version of the serialized data
- Version-specific fields: additional fields added in newer versions
This format ensures that older readers (pre-v2) can still deserialize the first three fields, while newer readers will detect and parse the version tag and the extra fields.
- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- the output stream to write to- Throws:
IOException
- if writing fails
-
readExternal
Deserializes VeniceChangeCoordinate while supporting both legacy (v1) and newer (v2+) formats.The method first reads the core fields (topic, partition, position wire format), which are common across versions. It then attempts to read a version tag.
- If the version tag is present and recognized, version-specific fields are read accordingly.
- If the tag is missing or reading fails, the method falls back to v1 format.
This approach is robust against partial data and ensures forward and backward compatibility.
- Specified by:
readExternal
in interfaceExternalizable
- Parameters:
in
- the input stream to read from- Throws:
IOException
- if an I/O error occursVeniceException
- if the class of a serialized object cannot be foundClassNotFoundException
-
getPartition
-
getStoreName
-
getConsumerSequenceId
public long getConsumerSequenceId()Returns the consumer sequence id for thisVeniceChangeCoordinate
. The sequence id is unique and monotonically increasing per record polled from the same consumer instance and partition. This can be used to reason about the order of events consumed from the same consumer and partition. The sequence id is mostly contiguous, but it is not guaranteed because there can be messages that are consumed internally (sequence id is already incremented) but not processed by the external consumer yet. In most cases it's good enough to provide some heuristic about the rate of consumption or number of events consumed, but it's not meant for precise measurement.- Returns:
- the consumer sequence id, or
UNDEFINED_CONSUMER_SEQUENCE_ID
if not available.
-
comparePosition
- Parameters:
other
- the other position to compare to- Returns:
- returns 0 if the positions are equal, -1 if this position is less than the other position, and 1 if this position is greater than the other position. You should only compare positions from the same partition and consumer instance.
-
getTopic
-
getPosition
-
setPubSubPositionDeserializer
-
convertVeniceChangeCoordinateToStringAndEncode
public static String convertVeniceChangeCoordinateToStringAndEncode(VeniceChangeCoordinate veniceChangeCoordinate) throws IOException - Throws:
IOException
-
decodeStringAndConvertToVeniceChangeCoordinate
public static VeniceChangeCoordinate decodeStringAndConvertToVeniceChangeCoordinate(PubSubPositionDeserializer deserializer, String offsetString) throws IOException, ClassNotFoundException - Throws:
IOException
ClassNotFoundException
-
toString
-
equals
-
hashCode
public int hashCode()
-