Kafka Streams runner: add a flush marker payload variant - #40068
Open
junaiddshaukat wants to merge 1 commit into
Open
Kafka Streams runner: add a flush marker payload variant#40068junaiddshaukat wants to merge 1 commit into
junaiddshaukat wants to merge 1 commit into
Conversation
First step toward bundles bounded by time (apache#39633). A bundle cannot be closed from a punctuator, because transactions are committed by the Kafka Streams runtime in the background and are not exposed, so instead a source will emit a marker that travels the topology as an ordinary record and a stage closes its bundle from process(). This adds the marker itself and nothing that emits or consumes one yet. It carries the producing partition and that transform's partition count, which is what will let it be addressed to a slice of the downstream partitions rather than broadcast: broadcasting would deliver one flush per upstream partition, so a downstream partition would see N times more flushes than the configured interval.
Contributor
|
Assigning reviewers: R: @kennknowles added as fallback since no labels match configuration Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First of four PRs toward bundles bounded by time (#39633). This one adds the flush marker to the payload envelope and nothing else: nothing emits a marker and nothing consumes one yet, so there is no behaviour change.
Why a marker rather than a timer
--maxBundleTimeMsis accepted today and has no effect. A bundle must be closed before its output is flushed, so it needs a time bound as well as a size one, otherwise on a sparse stream the elements already fed to it wait for the next watermark.The natural implementation, closing the bundle from a wall-clock punctuator, produces duplicate output against a real broker: a test with two chained GroupByKeys across four partitions emits its single group six times, reproducibly, and the count keeps climbing after input stops.
Asking about this on the Kafka dev list settled why. Matthias J. Sax's answer was that punctuations do not fit the exactly-once pattern of "read records, produce output, atomically commit the output plus the input offsets", that there is no supported way to run work just before a commit, and that transactions are an internal Kafka Streams concept deliberately not exposed at the API level. So the design was wrong rather than the implementation: bundles have to work without being coupled to transaction boundaries the runner does not control and cannot see.
He also corrected a mistaken note in #39633 — there is no
commitOffsetNeededflag, it iscommitNeeded, and it is set after a punctuation runs, so punctuator output is not outside the commit accounting as we had written. The issue has been corrected.The way forward is to make the flush data-driven, the way watermarks already are. A source emits a marker on the punctuator it already runs, the marker travels the topology as an ordinary record, and each stage closes its bundle when it receives one, inside
process(). Bundle boundaries then never touch transaction boundaries.What is here
A third variant alongside data and watermark:
FlushPayload, the narrowed view, mirroring the existingWatermarkPayload.KStreamsPayload.flush(sourcePartition, totalSourcePartitions), with the same range validation the watermark factory has.The marker carries the producing partition and that transform's partition count. Those exist so it can be targeted rather than broadcast. Broadcasting would deliver one flush per upstream partition, so a downstream partition would see N times more flushes than the configured interval asks for. Instead each producing partition will address a slice of the downstream partitions, and the slices tile the whole range, so every downstream partition receives exactly one flush per interval. The rule is
[floor(i*D/U), floor((i+1)*D/U))for upstream partitioni, withUupstream partitions andDdownstream, and it holds for fan-out, fan-in, equal counts and a single partition on either side. That logic lands in the next PR, in the partitioner.Unlike a watermark, a flush needs no aggregation when it arrives. There is nothing to hold and nothing to combine, because exactly one arrives.
The remaining three
GroupByKeyBroadcastPartitionerto something that covers targeting a possibly empty subset, and add the targeting rule.maxBundleTimeMs.ExecutableStageProcessorcloses and flushes its bundle when a marker arrives, then forwards it on.Testing
Both pass. Four new tests cover the serde round trip, the first and last partition as the boundaries of the range check, rejection of a partition outside its range, and that a flush cannot be read as a watermark or as data. Changing one field in the serde fails two of them, so they are testing something.