Class BarrierCutReader
java.lang.Object
io.krabka.streams.columnar.barrier.BarrierCutReader
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe poll timeout a reader uses when the caller names none. -
Constructor Summary
ConstructorsConstructorDescriptionBarrierCutReader(org.apache.kafka.clients.consumer.Consumer<byte[], byte[]> consumer) Creates a reader over a consumer, with the default poll timeout.BarrierCutReader(org.apache.kafka.clients.consumer.Consumer<byte[], byte[]> consumer, Duration pollTimeout) Creates a reader over a consumer. -
Method Summary
Modifier and TypeMethodDescriptioncompleteCutsAfter(String group, long epoch) Returns the complete cuts of a barrier group above an epoch.latestCompleteCut(String group) Returns the newest complete cut of a barrier group.
-
Field Details
-
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 pollspollTimeout- how long one poll of__barrier_statemay block
-
-
Method Details
-
latestCompleteCut
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_stateis absent or a record is malformed
-
completeCutsAfter
Returns the complete cuts of a barrier group above an epoch.- Parameters:
group- the barrier group to readepoch- the exclusive lower bound; pass-1for every cut- Returns:
- the matching cuts in ascending epoch order
- Throws:
ColumnarException- if__barrier_stateis absent or a record is malformed
-