Skip to content
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

KAFKA-13448: Align behaviour for producer callbacks with documented behaviour #11482

Closed
wants to merge 2 commits into from
Closed

KAFKA-13448: Align behaviour for producer callbacks with documented behaviour #11482

wants to merge 2 commits into from

Conversation

soceanainn
Copy link

@soceanainn soceanainn commented Nov 10, 2021

DO NOT MERGE Awaiting discussion and acceptance of KIP-799 first

Originally, Callback would return a null metadata value when an error occurred.

This was partially changed by KAFKA-3303, where in some cases Callback would return an 'empty' metadata. In this empty metadata TopicPartition is set correctly but all other fields are set as -1.

The docs were later updated by KAFKA-7412, but it incorrectly states that Callback will always return this 'empty' metadata when an error occurs. However in the case of any exceptions that are a subclass of ApiException, Callback will still return a null value (see here).

This change fixes the behaviour when an ApiException is thrown, to align that behaviour with other exceptions and with the currently documented behaviour.

Changes

  • In the one case where KafkaProducer was calling Callback.onCompletion directly, update the call to pass a placeholder value for metadata (in a manner consistent with the Javadoc) instead of a null value. Add unit tests around this change.
  • Move the private nested InterceptorCallback class out of KafkaProducer, and create a dedicated public class for InterceptorCallback within 'clients.producer.internal' instead.
  • Where KafkaProducer was passing InterceptorCallback to methods within 'clients.producer.internal' classes, update those methods to expect InterceptorCallback as input instead of Callback. Update unit tests as appropriate.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@soceanainn soceanainn changed the title Align behaviour for producer callbacks with documented behaviour MINOR: Align behaviour for producer callbacks with documented behaviour Nov 10, 2021
@soceanainn
Copy link
Author

@junrao can you grant permission for me to create a KIP for this change?

@junrao
Copy link
Contributor

junrao commented Nov 10, 2021

@soceanainn : What's your wiki ID? Thanks.

@soceanainn
Copy link
Author

@junrao it is seamus.oceanainn

@soceanainn soceanainn changed the title MINOR: Align behaviour for producer callbacks with documented behaviour KAFKA-13448: Align behaviour for producer callbacks with documented behaviour Nov 10, 2021
@junrao
Copy link
Contributor

junrao commented Nov 11, 2021

@soceanainn : Just gave you the wiki permission.

@soceanainn
Copy link
Author

@junrao thanks, I'll try to create a KIP tomorrow.

I've added a test for the ApiException case, however for the other case (using InterceptorCallback), I can't find a way to test it from the KafkaProducer class.

It's easier to test from the 'ProducerBatch' side of things, but this leads to complications since it is testing that metadata is correctly set to null (e.g. here).

The easiest fix is to make InterceptorCallback accessible at the package level, and update the ProducerBatch method to accept InterceptorCallback as input instead of Callback. That way it would make this implicit conversion from null metadata to an 'empty' record more obvious, and allow us to write proper unit tests around this. What do you think?

@soceanainn soceanainn marked this pull request as draft November 11, 2021 13:11
@junrao
Copy link
Contributor

junrao commented Nov 15, 2021

@soceanainn : Thanks for the KIP. Making ProducerBatch accept InterceptorCallback seems fine since it's an internal class.

@soceanainn
Copy link
Author

An equivalent change was implemented and merged in #11689

@soceanainn soceanainn closed this Feb 8, 2022
@soceanainn soceanainn deleted the fix-producer-callback-behaviour branch February 8, 2022 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants