Class VeniceChangeCoordinate

java.lang.Object
com.linkedin.davinci.consumer.VeniceChangeCoordinate
All Implemented Interfaces:
Externalizable, Serializable

public class VeniceChangeCoordinate extends Object implements Externalizable
This class represents a change coordinate in Venice. It contains the topic name, partition number, and the pubsub position.
See Also:
  • Field Details

    • UNDEFINED_CONSUMER_SEQUENCE_ID

      public static final long UNDEFINED_CONSUMER_SEQUENCE_ID
      Value 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 arbitrary PubSubPosition.
      See Also:
  • Constructor Details

    • VeniceChangeCoordinate

      public VeniceChangeCoordinate()
    • VeniceChangeCoordinate

      protected VeniceChangeCoordinate(String topic, PubSubPosition pubSubPosition, Integer partition)
    • VeniceChangeCoordinate

      protected VeniceChangeCoordinate(String topic, PubSubPosition pubSubPosition, Integer partition, long consumerSequenceId)
  • Method Details

    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Serializes the VeniceChangeCoordinate in a backward-compatible format.

      The serialization format is structured as follows:

      1. Core fields: topic, partition, pubSubPositionWireFormat
      2. Version tag: a UTF string that identifies the version of the serialized data
      3. 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 interface Externalizable
      Parameters:
      out - the output stream to write to
      Throws:
      IOException - if writing fails
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      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 interface Externalizable
      Parameters:
      in - the input stream to read from
      Throws:
      IOException - if an I/O error occurs
      VeniceException - if the class of a serialized object cannot be found
      ClassNotFoundException
    • getPartition

      public Integer getPartition()
    • getStoreName

      public String getStoreName()
    • getConsumerSequenceId

      public long getConsumerSequenceId()
      Returns the consumer sequence id for this VeniceChangeCoordinate. 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

      public int comparePosition(VeniceChangeCoordinate other)
      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

      protected String getTopic()
    • getPosition

      protected PubSubPosition getPosition()
    • setPubSubPositionDeserializer

      protected void setPubSubPositionDeserializer(PubSubPositionDeserializer pubSubPositionDeserializer)
    • 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

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object