Record Class BarrierCut
- Record Components:
group- the barrier group the coordinator injected markers forepoch- the epoch that identifies this cut within the grouptriggeredAt- the time the injection started, in epoch millisecondscompletedAt- the time the coordinator published the cut, in epoch millisecondsstatus- whether every partition received the epoch's markeroffsets- the marker offset of every partition that received onemissing- the partitions that never received the epoch's marker
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
ConstructorsConstructorDescriptionBarrierCut(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 TypeMethodDescriptionbooleancomplete()Reports whether every partition of the group received the epoch's marker.longReturns the value of thecompletedAtrecord component.longepoch()Returns the value of theepochrecord component.final booleanIndicates whether some other object is "equal to" this one.group()Returns the value of thegrouprecord component.final inthashCode()Returns a hash code value for this object.Set<org.apache.kafka.common.TopicPartition> missing()Returns the value of themissingrecord component.offset(org.apache.kafka.common.TopicPartition partition) Returns a partition's marker offset.offsets()Returns the value of theoffsetsrecord component.booleanreached(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.status()Returns the value of thestatusrecord component.final StringtoString()Returns a string representation of this record class.longReturns the value of thetriggeredAtrecord component.
-
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 forepoch- the epoch that identifies this cut within the grouptriggeredAt- the time the injection started, in epoch millisecondscompletedAt- the time the coordinator published the cut, in epoch millisecondsstatus- whether every partition received the epoch's markeroffsets- the marker offset of every partition that received onemissing- 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
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 fromrecords- 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 testposition- the consumer's current position in that partition- Returns:
- true when nothing before the cut is still unread
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
group
-
epoch
-
triggeredAt
public long triggeredAt()Returns the value of thetriggeredAtrecord component.- Returns:
- the value of the
triggeredAtrecord component
-
completedAt
public long completedAt()Returns the value of thecompletedAtrecord component.- Returns:
- the value of the
completedAtrecord component
-
status
-
offsets
-
missing
-