Skip to content

MINOR: improve JavaDocs for consumer CloseOptions#19546

Merged
mjsax merged 6 commits intoapache:trunkfrom
mjsax:minor-close-option
Apr 29, 2025
Merged

MINOR: improve JavaDocs for consumer CloseOptions#19546
mjsax merged 6 commits intoapache:trunkfrom
mjsax:minor-close-option

Conversation

@mjsax
Copy link
Copy Markdown
Member

@mjsax mjsax commented Apr 24, 2025

Reviewers: TengYao Chi frankvicky@apache.org, PoAn Yang
payang@apache.org, Lianet Magrans lmagrans@confluent.io, Anna
Sophie Blee-Goldman ableegoldman@apache.org

Copy link
Copy Markdown
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjsax: Thanks for the significant improvement to the documentation!
Overall LGTM.
I have just two nits for consideration.

* If no thread is blocking in a method which can throw {@link org.apache.kafka.common.errors.WakeupException}, the next call to such a method will raise it instead.
* Close the consumer cleanly. {@link CloseOptions} allows to specify a timeout and a
* {@link CloseOptions.GroupMembershipOperation membership operation}.
* If no timeout is specified, the default timeout of 30 seconds is uses.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* If no timeout is specified, the default timeout of 30 seconds is uses.
* If no timeout is specified, the default timeout of 30 seconds is used.

* This method waits up to the timeout for the consumer to complete pending commits and may leave the group,
* depending on the specified membership operation.
* If auto-commit is enabled, this will commit the current offsets if possible within the
* timeout. If the consumer is unable to complete offset commits and gracefully leave the group (if applicable)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* timeout. If the consumer is unable to complete offset commits and gracefully leave the group (if applicable)
* timeout. If the consumer is unable to complete offset commits and gracefully leaves the group (if applicable)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, a bit confusing, but in this case "leave" is correct, referring to "unable to ...leave"

* @throws InterruptException If the thread is interrupted before or while this function is called
* @throws org.apache.kafka.common.KafkaException for any other error during close
*/
@Deprecated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Deprecated
@Deprecated(since = "4.0")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since 4.1 really (helpful adding the since btw)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, 4.1 :) -- c&p error form the previous PR...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad 😅

* Note that the execution time of callbacks (such as {@link OffsetCommitCallback} and
* {@link ConsumerRebalanceListener}) does not consume time from the close timeout.
*
* @param option see {@link CloseOptions}; cannot be {@code null}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't check whether CloseOptions is null. If users use close((CloseOptions) null), they get NullPointerException. Do we want to return IllegalArgumentException when input is null here? Thanks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah lets add a check and throw an IAException

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok if users get NPE -- we say "cannot be null" so NPE should be expected?

Copy link
Copy Markdown
Member

@lianetm lianetm Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I personally prefer IAE too, but we do have this same NPE behaviour on args in many other consumer APIs too (ex. commit, position, committed,...I think almost all)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so the verdict is we keep NPE. Thanks.

(Btw: also aligns to what KS does.)

Copy link
Copy Markdown
Member

@lianetm lianetm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mjsax !

* <p>
* Close the consumer with {@link CloseOptions.GroupMembershipOperation#DEFAULT default membership operation}
* cleanly within the specified timeout. This method waits up to
* {@code timeout} for the consumer to complete pending commits and may leave the group (if applicable).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about the "and may leave the group (if applicable).", could we be explicit in this case, just to make things clear? (it will leave the group if it's a dynamic member). That's the only case here that the close has the DEFAULT membership behaviour I expect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, "if applicable" is pretty vague and I'd be left wondering if I saw this as a user

* {@code timeout} for the consumer to complete pending commits and leave the group.
* This method has been deprecated since Kafka 4.0 and should use {@link KafkaConsumer#close(CloseOptions)} instead.
* <p>
* Close the consumer with {@link CloseOptions.GroupMembershipOperation#DEFAULT default membership operation}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"membership operation" seems to generic to me really, this is only about "leave group behaviour" or similar. Would that be clearer as java doc?

* Close the consumer cleanly. {@link CloseOptions} allows to specify a timeout and a
* {@link CloseOptions.GroupMembershipOperation membership operation}.
* If no timeout is specified, the default timeout of 30 seconds is uses.
* If no membership operation is specified, the {@link CloseOptions.GroupMembershipOperation#DEFAULT default
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above, would ~"leave group behaviour" be clearer than the generic "membership operation"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, would also be good to specify what the default leave behavior actually is

* If no membership operation is specified, the {@link CloseOptions.GroupMembershipOperation#DEFAULT default
* membership operation} is used.
* <p>
* This method waits up to the timeout for the consumer to complete pending commits and may leave the group,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This method waits up to the timeout for the consumer to complete pending commits and may leave the group,
* This method waits up to the timeout for the consumer to complete pending commits and maybe leave the group,

* @throws InterruptException If the thread is interrupted before or while this function is called
* @throws org.apache.kafka.common.KafkaException for any other error during close
*/
@Deprecated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since 4.1 really (helpful adding the since btw)

* This method waits up to the timeout for the consumer to complete pending commits and may leave the group,
* depending on the specified membership operation.
* If auto-commit is enabled, this will commit the current offsets if possible within the
* timeout. If the consumer is unable to complete offset commits and gracefully leave the group (if applicable)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, a bit confusing, but in this case "leave" is correct, referring to "unable to ...leave"

/**
* Tries to close the consumer cleanly within the specified timeout. This method waits up to
* {@code timeout} for the consumer to complete pending commits and leave the group.
* This method has been deprecated since Kafka 4.0 and should use {@link KafkaConsumer#close(CloseOptions)} instead.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This method has been deprecated since Kafka 4.0 and should use {@link KafkaConsumer#close(CloseOptions)} instead.
* This method has been deprecated since Kafka 4.1 and should use {@link KafkaConsumer#close(CloseOptions)} instead.

* {@code timeout} for the consumer to complete pending commits and may leave the group (if applicable).
* If auto-commit is enabled, this will commit the current offsets if possible within the
* timeout. If the consumer is unable to complete offset commits and gracefully leave the group
* timeout. If the consumer is unable to complete offset commits and gracefully leave the group (if applicable)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(if applicable) is ok to use here as long as we specified when it's applicable earlier in the javadocs

@mjsax
Copy link
Copy Markdown
Member Author

mjsax commented Apr 25, 2025

Updates this PR. Call for review.

Copy link
Copy Markdown
Member

@lianetm lianetm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! Minor comments left, and also, could we fix this log that references the deprecated close?

"KafkaConsumer.close(Duration timeout)", timer.timeoutMs());

I would personally remove the explicit func name from the log and just mention "the close operation/call", but as you prefer.

* <p>
* Close the consumer with {@link CloseOptions.GroupMembershipOperation#DEFAULT default leave group behavior}
* cleanly within the specified timeout. This method waits up to
* {@code timeout} for the consumer to complete pending commits and maybe leaves the group (if the group is dynamic).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* {@code timeout} for the consumer to complete pending commits and maybe leaves the group (if the group is dynamic).
* {@code timeout} for the consumer to complete pending commits and maybe leave the group (if the member is dynamic).

* If no leave group behavior is specified, the {@link CloseOptions.GroupMembershipOperation#DEFAULT default
* leave group behavior} is used.
* <p>
* This method waits up to the timeout for the consumer to complete pending commits and maybe leaves the group,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This method waits up to the timeout for the consumer to complete pending commits and maybe leaves the group,
* This method waits up to the timeout for the consumer to complete pending commits and maybe leave the group,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot follow.

This method wait[s] ... and maybe leave[s] the group. -- Why would we remove the s?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

she's right, no s. English is confusing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know the proper grammar terminology here but essentially it's because the "maybe leave the group" is part of the X in the sentence "this method waits up to the timeout for the consumer to X"

here the "maybe leave the group" comes after an "and" which can be amiguous but in this context I think it makes more sense for it to be part of the X, ie "this method waits up to the timeout for the consumer to (complete pending commits and maybe leave the group)"

so its should be conjugated the same way as the thing before the and, ie the "complete pending commits"

since it's "complete" and not "completes", it should also be "leave" and not "leaves"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically the original sentence is also grammatically correct, however it doesn't mean exactly the same thing.

With the s it's is effectively saying "This method (waits up to the timeout for the consumer to complete pending commits) and maybe leaves the group" which implies leaving the group isn't part of the timeout.

Without the s it's grouped as "this method waits up to the timeout for the consumer to (complete pending commits and maybe leave the group)" which implies leaving the group is part of the timeout

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make matters even more confusing, I noticed we actually do not pass the timeout into the consumer or producer's #close methods...

So technically-technically the original sentence is also correct code-wise, but imo that's kind of a bug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining. "Surprisingly", I could follow and it make sense to me 😂 -- Mr.John (english major) @vvcephei could not have explained it any better.

* This method waits up to the timeout for the consumer to complete pending commits and maybe leaves the group,
* depending on the specified leave group behavior.
* If auto-commit is enabled, this will commit the current offsets if possible within the
* timeout. If the consumer is unable to complete offset commits and gracefully leaves the group (if applicable)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* timeout. If the consumer is unable to complete offset commits and gracefully leaves the group (if applicable)
* timeout. If the consumer is unable to complete offset commits and gracefully leave the group (if applicable)

Copy link
Copy Markdown
Member

@lianetm lianetm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mjsax ! LGTM.

@mjsax mjsax merged commit 3bb15c5 into apache:trunk Apr 29, 2025
22 checks passed
@mjsax mjsax deleted the minor-close-option branch April 29, 2025 23:38
shmily7829 pushed a commit to shmily7829/kafka that referenced this pull request May 7, 2025
Reviewers: TengYao Chi <frankvicky@apache.org>, PoAn Yang <payang@apache.org>, Lianet Magrans <lmagrans@confluent.io>, Anna Sophie Blee-Goldman <ableegoldman@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants