-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Adds triggerring configuration to KafkaIO eos. #37648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -648,6 +648,8 @@ public static <K, V> WriteRecords<K, V> writeRecords() { | |
| return new AutoValue_KafkaIO_WriteRecords.Builder<K, V>() | ||
| .setProducerConfig(WriteRecords.DEFAULT_PRODUCER_PROPERTIES) | ||
| .setEOS(false) | ||
| .setEosTriggerNumElements(1) // keep default numElements | ||
| .setEosTriggerTimeout(null) // keep default trigger (timeout) | ||
| .setNumShards(0) | ||
| .setConsumerFactoryFn(KafkaIOUtils.KAFKA_CONSUMER_FACTORY_FN) | ||
| .setBadRecordRouter(BadRecordRouter.THROWING_ROUTER) | ||
|
|
@@ -3185,6 +3187,10 @@ public abstract static class WriteRecords<K, V> | |
| @Pure | ||
| public abstract boolean isEOS(); | ||
|
|
||
| public abstract int getEosTriggerNumElements(); | ||
|
|
||
| public abstract @Nullable Duration getEosTriggerTimeout(); | ||
|
|
||
| @Pure | ||
| public abstract @Nullable String getSinkGroupId(); | ||
|
|
||
|
|
@@ -3221,6 +3227,10 @@ abstract Builder<K, V> setPublishTimestampFunction( | |
|
|
||
| abstract Builder<K, V> setEOS(boolean eosEnabled); | ||
|
|
||
| abstract Builder<K, V> setEosTriggerNumElements(int numElements); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would name these more narrowly. Theres lots of potential numElements and timeouts in the scope of KafkaIO |
||
| abstract Builder<K, V> setEosTriggerTimeout(@Nullable Duration timeout); | ||
|
|
||
| abstract Builder<K, V> setSinkGroupId(String sinkGroupId); | ||
|
|
||
| abstract Builder<K, V> setNumShards(int numShards); | ||
|
|
@@ -3368,6 +3378,15 @@ public WriteRecords<K, V> withEOS(int numShards, String sinkGroupId) { | |
| return toBuilder().setEOS(true).setNumShards(numShards).setSinkGroupId(sinkGroupId).build(); | ||
| } | ||
|
|
||
| public WriteRecords<K, V> withEOSTriggerConfig(int numElements, Duration timeout) { | ||
| checkArgument(numElements >= 1, "numElements should be >= 1"); | ||
| checkArgument(timeout != null, "timeout is required for exactly-once sink"); | ||
| return toBuilder() | ||
| .setEosTriggerNumElements(numElements) | ||
| .setEosTriggerTimeout(timeout) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * When exactly-once semantics are enabled (see {@link #withEOS(int, String)}), the sink needs | ||
| * to fetch previously stored state with Kafka topic. Fetching the metadata requires a consumer. | ||
|
|
@@ -3653,6 +3672,19 @@ public Write<K, V> withEOS(int numShards, String sinkGroupId) { | |
| return withWriteRecordsTransform(getWriteRecordsTransform().withEOS(numShards, sinkGroupId)); | ||
| } | ||
|
|
||
| /** | ||
| * Set the frequency and numElements threshold at which messages are triggered. | ||
| * | ||
| * <p>This is only applicable when the write method is set to EOS. | ||
| * | ||
| * <p>Every timeout duration, or numElements (repeated, after first condition is met) collection | ||
| * of elements written. | ||
| */ | ||
| public Write<K, V> withEOSTriggerConfig(int numElements, Duration timeout) { | ||
| return withWriteRecordsTransform( | ||
| getWriteRecordsTransform().withEOSTriggerConfig(numElements, timeout)); | ||
| } | ||
|
|
||
| /** | ||
| * Wrapper method over {@link WriteRecords#withConsumerFactoryFn(SerializableFunction)}, used to | ||
| * keep the compatibility with old API based on KV type of element. | ||
|
|
||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed or is the the windowing inherited from above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't work without repeating triggering definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we discussed, it looks like this is because the continuation trigger changes it to aftercount(1)
can you add a comment here
// Reapply the windowing configuration as the continuation trigger doesn't maintain the desired batching.