Skip to content

Fixed documentation and handles null topicPartition for KAFKA-12841#11689

Merged
cmccabe merged 10 commits intoapache:trunkfrom
philipnee:pnee-12841
Feb 3, 2022
Merged

Fixed documentation and handles null topicPartition for KAFKA-12841#11689
cmccabe merged 10 commits intoapache:trunkfrom
philipnee:pnee-12841

Conversation

@philipnee
Copy link
Copy Markdown
Contributor

Jira: https://issues.apache.org/jira/browse/KAFKA-12841

Using the InterceptorCallback wrapper in the case of ApiException so that we will adhere correctly to the Callback contract for onCompletion specifying a valid (dummy) TopicPartition. Removed some documentation from Callback.java that stated "except topicPartition" as we are assigning -1 to the topicPartition if it doesn't exist. The changes is based on https://issues.apache.org/jira/browse/KAFKA-3303

Committer Checklist (excluded from commit message)

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

Kirk True and others added 5 commits January 18, 2022 10:46
…e of ApiException

Using the InterceptorCallback wrapper in the case of ApiException so
that we will adhere correctly to the Callback contract for onCompletion
specifying a valid (dummy) TopicPartition.
when metadata null, all fields are -1
@philipnee philipnee changed the title KAFKA-12841 patch Fixed documentation and handles null topicPartition for KAFKA-12841 Jan 19, 2022
Comment thread clients/src/main/java/org/apache/kafka/clients/producer/Callback.java Outdated
try {
assertNotNull(recordMetadata.topic());
} catch (NullPointerException e) {
fail("Topic name should be valid even on send failure", e);
Copy link
Copy Markdown
Contributor

@cmccabe cmccabe Jan 20, 2022

Choose a reason for hiding this comment

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

It's not necessary to do this. If you want to display a special error message when the assert fails, there is a three-argument form which lets you specify the error message.

Comment thread clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java Outdated
- specify topicPartition behavior
- method naming
- use 2 params assert to display proper error messages
@cmccabe
Copy link
Copy Markdown
Contributor

cmccabe commented Feb 2, 2022

test failures are not related.

Copy link
Copy Markdown
Contributor

@cmccabe cmccabe left a comment

Choose a reason for hiding this comment

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

LGTM

@cmccabe cmccabe merged commit 319732d into apache:trunk Feb 3, 2022
cmccabe pushed a commit that referenced this pull request Feb 3, 2022
…#11689)

Sometimes, the Kafka producer encounters an error prior to selecting a topic partition. In this case, we
would like to acknowledge the failure in the producer interceptors, if any are configured. We should also
pass a non-null Metadata object to the producer callback, if there is one. This PR implements that
behavior. It also updates the JavaDoc to clarify that if a partition cannot be selected, we will pass
back a partition id of -1 in the metadata. This is in keeping with KAFKA-3303.

Co-authors: Kirk True <kirk@mustardgrain.com>
Reviewers: Colin P. McCabe <cmccabe@apache.org>
cmccabe pushed a commit that referenced this pull request Feb 3, 2022
…#11689)

Sometimes, the Kafka producer encounters an error prior to selecting a topic partition. In this case, we
would like to acknowledge the failure in the producer interceptors, if any are configured. We should also
pass a non-null Metadata object to the producer callback, if there is one. This PR implements that
behavior. It also updates the JavaDoc to clarify that if a partition cannot be selected, we will pass
back a partition id of -1 in the metadata. This is in keeping with KAFKA-3303.

Co-authors: Kirk True <kirk@mustardgrain.com>
Reviewers: Colin P. McCabe <cmccabe@apache.org>
Copy link
Copy Markdown
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@philipnee : Thanks for the PR. Added a comment below.


// The onCompletion callback does expect a non-null metadata, but one will be created inside
// the interceptor's onCompletion implementation before the user's callback is invoked.
interceptCallback.onCompletion(null, e);
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.

@philipnee : It seems that we may have introduced a bug here. interceptors.onAcknowledgement() is now called twice, once through interceptCallback.onCompletion() and another through interceptors.onSendError() in line 1010 below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @junrao - thanks for catching this. Created a PR to address this bug: #12064

junrao pushed a commit that referenced this pull request Apr 25, 2022
The bug was introduced in #11689 that an additional onAcknowledgement was made using the InterceptorCallback class. This is undesirable since onSendError will attempt to call onAcknowledgement once more.

Reviewers: Jun Rao <junrao@gmail.com>
cadonna pushed a commit that referenced this pull request Apr 27, 2022
The bug was introduced in #11689 that an additional onAcknowledgement was made using the InterceptorCallback class. This is undesirable since onSendError will attempt to call onAcknowledgement once more.

Reviewers: Jun Rao <junrao@gmail.com>
jeffkbkim pushed a commit to confluentinc/kafka that referenced this pull request May 12, 2022
…apache#11689)

Sometimes, the Kafka producer encounters an error prior to selecting a topic partition. In this case, we
would like to acknowledge the failure in the producer interceptors, if any are configured. We should also
pass a non-null Metadata object to the producer callback, if there is one. This PR implements that
behavior. It also updates the JavaDoc to clarify that if a partition cannot be selected, we will pass
back a partition id of -1 in the metadata. This is in keeping with KAFKA-3303.

Co-authors: Kirk True <kirk@mustardgrain.com>
Reviewers: Colin P. McCabe <cmccabe@apache.org>
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.

3 participants