Class BarrierCutReader

java.lang.Object
io.krabka.streams.columnar.barrier.BarrierCutReader

public final class BarrierCutReader extends Object
Reads published cuts from the internal __barrier_state topic.

The reader drives a caller-owned consumer with assign, seek, and poll, so the read needs no consumer group and no new broker RPC. Give it a consumer of its own: the first read replaces the consumer's assignment with every partition of __barrier_state and seeks to the beginning. Later reads continue from the position the last read left, so a read costs one poll of the records the coordinator published since.

The reader keeps complete cuts only. A partial cut names partitions that never received the epoch's marker, so a task that waited for one would wait forever. That is why the coordinator publishes partial cuts at all: a reader can skip the epoch instead of stalling on markers that never arrive.

Example

var reader = new BarrierCutReader(cutConsumer);
Optional<BarrierCut> latest = reader.latestCompleteCut("transactions");
for (var cut : reader.completeCutsAfter("transactions", latest.get().epoch())) {
    System.out.println(cut.epoch());
}
  • Field Details

    • DEFAULT_POLL_TIMEOUT

      public static final Duration DEFAULT_POLL_TIMEOUT
      The poll timeout a reader uses when the caller names none.
  • Constructor Details

    • BarrierCutReader

      public BarrierCutReader(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer)
      Creates a reader over a consumer, with the default poll timeout.
      Parameters:
      consumer - the consumer the reader assigns, seeks, and polls
    • BarrierCutReader

      public BarrierCutReader(org.apache.kafka.clients.consumer.Consumer<byte[],byte[]> consumer, Duration pollTimeout)
      Creates a reader over a consumer.
      Parameters:
      consumer - the consumer the reader assigns, seeks, and polls
      pollTimeout - how long one poll of __barrier_state may block
  • Method Details

    • latestCompleteCut

      public Optional<BarrierCut> latestCompleteCut(String group)
      Returns the newest complete cut of a barrier group.
      Parameters:
      group - the barrier group to read
      Returns:
      the complete cut with the highest epoch, or empty when the group has none
      Throws:
      ColumnarException - if __barrier_state is absent or a record is malformed
    • completeCutsAfter

      public List<BarrierCut> completeCutsAfter(String group, long epoch)
      Returns the complete cuts of a barrier group above an epoch.
      Parameters:
      group - the barrier group to read
      epoch - the exclusive lower bound; pass -1 for every cut
      Returns:
      the matching cuts in ascending epoch order
      Throws:
      ColumnarException - if __barrier_state is absent or a record is malformed