Record Class BarrierCut

java.lang.Object
java.lang.Record
io.krabka.streams.columnar.barrier.BarrierCut
Record Components:
group - the barrier group the coordinator injected markers for
epoch - the epoch that identifies this cut within the group
triggeredAt - the time the injection started, in epoch milliseconds
completedAt - the time the coordinator published the cut, in epoch milliseconds
status - whether every partition received the epoch's marker
offsets - the marker offset of every partition that received one
missing - the partitions that never received the epoch's marker

public record BarrierCut(String group, long epoch, long triggeredAt, long completedAt, BarrierCutStatus status, Map<org.apache.kafka.common.TopicPartition, Long> offsets, Set<org.apache.kafka.common.TopicPartition> missing) extends Record
One epoch's cut across every partition of a barrier group.

A cut names an exact position in every input at once: the offset of the epoch's marker in each partition. Records below that offset are before the cut and records at or above it are after the cut. The marker itself is a Kafka control record, so a KafkaConsumer never delivers it and the cut offset never holds a data record. "Everything before the cut" is exactly offset < cutOffset.

BarrierCutReader decodes cuts from the internal __barrier_state topic. The offsets and the missing partitions are copied on construction, so a decoded cut is immutable and safe to share between threads.

Example

var partition = new TopicPartition("transactions", 0);
List<ConsumedRecord> beforeTheCut = cut.recordsBefore(partition, polled);
boolean waitingOnThisPartition = !cut.reached(partition, consumer.position(partition));
  • Constructor Summary

    Constructors
    Constructor
    Description
    BarrierCut(String group, long epoch, long triggeredAt, long completedAt, BarrierCutStatus status, Map<org.apache.kafka.common.TopicPartition, Long> offsets, Set<org.apache.kafka.common.TopicPartition> missing)
    Copies the mutable components so the cut is immutable.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Reports whether every partition of the group received the epoch's marker.
    long
    Returns the value of the completedAt record component.
    long
    Returns the value of the epoch record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the group record component.
    final int
    Returns a hash code value for this object.
    Set<org.apache.kafka.common.TopicPartition>
    Returns the value of the missing record component.
    offset(org.apache.kafka.common.TopicPartition partition)
    Returns a partition's marker offset.
    Map<org.apache.kafka.common.TopicPartition, Long>
    Returns the value of the offsets record component.
    boolean
    reached(org.apache.kafka.common.TopicPartition partition, long position)
    Reports whether a partition delivered everything below the cut.
    recordsBefore(org.apache.kafka.common.TopicPartition partition, List<ConsumedRecord> records)
    Returns the records of a partition that fall before the cut.
    Returns the value of the status record component.
    final String
    Returns a string representation of this record class.
    long
    Returns the value of the triggeredAt record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BarrierCut

      public BarrierCut(String group, long epoch, long triggeredAt, long completedAt, BarrierCutStatus status, Map<org.apache.kafka.common.TopicPartition, Long> offsets, Set<org.apache.kafka.common.TopicPartition> missing)
      Copies the mutable components so the cut is immutable.
      Parameters:
      group - the barrier group the coordinator injected markers for
      epoch - the epoch that identifies this cut within the group
      triggeredAt - the time the injection started, in epoch milliseconds
      completedAt - the time the coordinator published the cut, in epoch milliseconds
      status - whether every partition received the epoch's marker
      offsets - the marker offset of every partition that received one
      missing - the partitions that never received the epoch's marker
  • Method Details

    • complete

      public boolean complete()
      Reports whether every partition of the group received the epoch's marker.
      Returns:
      true when the status is BarrierCutStatus.COMPLETE
    • offset

      public OptionalLong offset(org.apache.kafka.common.TopicPartition partition)
      Returns a partition's marker offset.
      Parameters:
      partition - the topic partition to look up
      Returns:
      the marker offset, or empty when the partition is not in this cut
    • recordsBefore

      public List<ConsumedRecord> recordsBefore(org.apache.kafka.common.TopicPartition partition, List<ConsumedRecord> records)
      Returns the records of a partition that fall before the cut.

      A partition that this cut does not name is not part of the barrier group, so every record passes through unchanged.

      Parameters:
      partition - the topic partition the records were fetched from
      records - the fetched records, in offset order
      Returns:
      the prefix whose offsets are below the partition's marker offset
    • reached

      public boolean reached(org.apache.kafka.common.TopicPartition partition, long position)
      Reports whether a partition delivered everything below the cut.

      The position is the consumer's next fetch offset. A partition that this cut does not name holds nothing back and always reports true.

      Parameters:
      partition - the topic partition to test
      position - the consumer's current position in that partition
      Returns:
      true when nothing before the cut is still unread
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • group

      public String group()
      Returns the value of the group record component.
      Returns:
      the value of the group record component
    • epoch

      public long epoch()
      Returns the value of the epoch record component.
      Returns:
      the value of the epoch record component
    • triggeredAt

      public long triggeredAt()
      Returns the value of the triggeredAt record component.
      Returns:
      the value of the triggeredAt record component
    • completedAt

      public long completedAt()
      Returns the value of the completedAt record component.
      Returns:
      the value of the completedAt record component
    • status

      public BarrierCutStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • offsets

      public Map<org.apache.kafka.common.TopicPartition, Long> offsets()
      Returns the value of the offsets record component.
      Returns:
      the value of the offsets record component
    • missing

      public Set<org.apache.kafka.common.TopicPartition> missing()
      Returns the value of the missing record component.
      Returns:
      the value of the missing record component