KAFKA-18193 Refactor Kafka Streams CloseOptions to Fluent API Style#19955
KAFKA-18193 Refactor Kafka Streams CloseOptions to Fluent API Style#19955bbejeck merged 19 commits intoapache:trunkfrom
Conversation
|
This patch should wait until the KIP-1153 vote concludes. |
|
This KIP has passed. LINK |
|
A label of 'needs-attention' was automatically added to this PR in order to raise the |
|
A label of 'needs-attention' was automatically added to this PR in order to raise the |
|
A label of 'needs-attention' was automatically added to this PR in order to raise the |
|
A label of 'needs-attention' was automatically added to this PR in order to raise the |
|
A label of 'needs-attention' was automatically added to this PR in order to raise the |
|
@m1a2st can you rebase to fix the merge conflicts? Thanks Apologies for the delay in the reviewing we'll get this in soon. |
# Conflicts: # streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
| * threads to join. | ||
| * @param options contains timeout to specify how long to wait for the threads to shut down, and a flag | ||
| * {@link org.apache.kafka.streams.CloseOptions.GroupMembershipOperation#LEAVE_GROUP} to | ||
| * trigger consumer leave call |
There was a problem hiding this comment.
Shouldn't this just specify that users can provide either option for remaining in the group or leaving vs. explicity showing LEAVE_GROUP
|
|
||
| public class CloseOptions { | ||
| /** | ||
| * Enum to specify the group membership operation upon leaving group. |
There was a problem hiding this comment.
I think this should say "upon closing closing the Kafka Streams application" or something similar
| // further state reports from the thread since we're shutting down | ||
| int numStreamThreads = processStreamThread(streamThread -> streamThread.shutdown(leaveGroup)); | ||
| int numStreamThreads = processStreamThread( | ||
| streamThread -> streamThread.shutdown(operation == org.apache.kafka.streams.CloseOptions.GroupMembershipOperation.LEAVE_GROUP) |
There was a problem hiding this comment.
I'm thinking we could update the StreamThread#shutdown to take a CloseOptions.GroupMembershipOperation parameter, then change the AtomicBoolean to AtomicReference<GroupMembershipOperation> and we can pass the close option directly to the consumer. WDYT?
There was a problem hiding this comment.
I think updating the StreamThread#shutdown parameter makes sense to me, so I will update the PR.
|
Thanks for @bbejeck review, I have updated the PR based on your comments, PTAL |
| private final AtomicLong cacheResizeSize = new AtomicLong(-1L); | ||
| private final AtomicBoolean leaveGroupRequested = new AtomicBoolean(false); | ||
| private final AtomicReference<org.apache.kafka.streams.CloseOptions.GroupMembershipOperation> leaveGroupRequested = | ||
| new AtomicReference<>(org.apache.kafka.streams.CloseOptions.GroupMembershipOperation.LEAVE_GROUP); |
There was a problem hiding this comment.
The default should be REMAIN_IN_GROUP, which corresponds to the default of leaveGroupRequested = false
There was a problem hiding this comment.
Thanks for pointing that out, that was my mistake.
|
Merged #19955 into trunk |
| final String msgPrefix = prepareMillisCheckFailMsgPrefix(options.timeout, "timeout"); | ||
| final long timeoutMs = validateMillisecondDuration(options.timeout, msgPrefix); | ||
| final CloseOptionsInternal optionsInternal = new CloseOptionsInternal(options); | ||
| final String msgPrefix = prepareMillisCheckFailMsgPrefix(optionsInternal.timeout(), "timeout"); |
There was a problem hiding this comment.
Is it safe to pass an Optional<Duration> to prepareMillisCheckFailMsgPrefix? I assume the accepted type is a Duration.
There was a problem hiding this comment.
It’s safe to pass an Optional object, but we shouldn’t change the error message. Therefore, I’ll update it to use Duration instead.
Invalid value for parameter "timeout" (value was: PT1M).
Invalid value for parameter "timeout" (value was: Optional[PT1M]).
| final long timeoutMs = validateMillisecondDuration(options.timeout, msgPrefix); | ||
| final CloseOptionsInternal optionsInternal = new CloseOptionsInternal(options); | ||
| final String msgPrefix = prepareMillisCheckFailMsgPrefix(optionsInternal.timeout(), "timeout"); | ||
| final long timeoutMs = validateMillisecondDuration(optionsInternal.timeout().get(), msgPrefix); |
There was a problem hiding this comment.
the timeout could be empty, right?
| /** | ||
| * Fluent method to set the timeout for the close process. | ||
| * | ||
| * @param timeout the maximum time to wait for the KafkaStreams to close. If {@code null}, the default timeout will be used. |
There was a problem hiding this comment.
If {@code null}, the default timeout will be used.
It looks like the implementation is ignoring the comment 😢
There was a problem hiding this comment.
Yes, I missed this comment. If null values are not allowed, KafkaStreams at L1637 should not be empty.
This PR is a follow-up to KAFKA-18193. It addresses the need for a null check and an improved error message. Please refer to the previous comments and the review of #19955 (review) for more context. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
…pache#19955) In Kafka Streams, configuration classes typically follow a fluent API pattern to ensure a consistent and intuitive developer experience. However, the current implementation of `org.apache.kafka.streams.KafkaStreams$CloseOptions` deviates from this convention by exposing a public constructor, breaking the uniformity expected across the API. To address this inconsistency, we propose introducing a new `CloseOptions` class that adheres to the fluent API style, replacing the existing implementation. The new class will retain the existing `timeout(Duration)` and `leaveGroup(boolean)` methods but will enforce fluent instantiation and configuration. Given the design shift, we will not maintain backward compatibility with the current class. This change aligns with the goal of standardizing configuration objects across Kafka Streams, offering developers a more cohesive and predictable API. Reviewers: Bill Bejeck<bbejeck@apache.org>
…20650) This PR is a follow-up to KAFKA-18193. It addresses the need for a null check and an improved error message. Please refer to the previous comments and the review of apache#19955 (review) for more context. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
…pache#19955) In Kafka Streams, configuration classes typically follow a fluent API pattern to ensure a consistent and intuitive developer experience. However, the current implementation of `org.apache.kafka.streams.KafkaStreams$CloseOptions` deviates from this convention by exposing a public constructor, breaking the uniformity expected across the API. To address this inconsistency, we propose introducing a new `CloseOptions` class that adheres to the fluent API style, replacing the existing implementation. The new class will retain the existing `timeout(Duration)` and `leaveGroup(boolean)` methods but will enforce fluent instantiation and configuration. Given the design shift, we will not maintain backward compatibility with the current class. This change aligns with the goal of standardizing configuration objects across Kafka Streams, offering developers a more cohesive and predictable API. Reviewers: Bill Bejeck<bbejeck@apache.org>
…20650) This PR is a follow-up to KAFKA-18193. It addresses the need for a null check and an improved error message. Please refer to the previous comments and the review of apache#19955 (review) for more context. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
In Kafka Streams, configuration classes typically follow a fluent API
pattern to ensure a consistent and intuitive developer experience.
However, the current implementation of
org.apache.kafka.streams.KafkaStreams$CloseOptionsdeviates from thisconvention by exposing a public constructor, breaking the uniformity
expected across the API.
To address this inconsistency, we propose introducing a new
CloseOptionsclass that adheres to the fluent API style, replacing theexisting implementation. The new class will retain the existing
timeout(Duration)andleaveGroup(boolean)methods but will enforcefluent instantiation and configuration. Given the design shift, we will
not maintain backward compatibility with the current class.
This change aligns with the goal of standardizing configuration objects
across Kafka Streams, offering developers a more cohesive and
predictable API.
Reviewers: Bill Bejeckbbejeck@apache.org