Skip to content

KAFKA-7412: onComplete should not reassign metadata variable#5798

Merged
junrao merged 3 commits intoapache:trunkfrom
huxihx:KAFKA-7412
Nov 9, 2018
Merged

KAFKA-7412: onComplete should not reassign metadata variable#5798
junrao merged 3 commits intoapache:trunkfrom
huxihx:KAFKA-7412

Conversation

@huxihx
Copy link
Copy Markdown
Contributor

@huxihx huxihx commented Oct 15, 2018

The Java doc for InterceptorCallback#onComplete says that exactly one of the arguments(metadata and exception) will be non-null. However, the commitment will be broken when TimeoutException is encountered since the code reassigns a new-created RecordMetadata object to variable metadata.

The solution is to leave metadata1 unchanged and pass a new RecordMetadata instance to onAcknowledgement.

More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

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

@huxihx
Copy link
Copy Markdown
Contributor Author

huxihx commented Oct 16, 2018

@hachikuji Please review this minor change. Thanks.

@ijuma
Copy link
Copy Markdown
Member

ijuma commented Oct 16, 2018

I think the change in behaviour was intentional (and several releases back), but the javadoc was not changed. cc @apovzner @junrao who introduced this change as part of the client interceptors work.

@huxihx
Copy link
Copy Markdown
Contributor Author

huxihx commented Oct 17, 2018

Well, if this is intentional, we should refine the doc instead.

@ijuma
Copy link
Copy Markdown
Member

ijuma commented Oct 20, 2018

Yeah, I agree.

@huxihx
Copy link
Copy Markdown
Contributor Author

huxihx commented Oct 29, 2018

@junrao Could you clarify if this is intentional?

@junrao
Copy link
Copy Markdown
Contributor

junrao commented Nov 5, 2018

@huxihx : This does seem to be intentional. The following is the commit message for KAFKA-3303. So, we just want to update the javadoc accordingly, i.e, when exception is not null in the callback, metadata will contain the special -1 value for all fields except for topicParition, which will be valid.

"Currently, If sending the record fails before it gets to the server, ProducerInterceptor.onAcknowledgement() is called with metadata == null, and non-null exception. However, it is useful to pass topic and partition, if known, to ProducerInterceptor.onAcknowledgement() as well. This patch ensures that ProducerInterceptor.onAcknowledgement() gets record metadata with topic and maybe partition. If partition is not set in 'record' and KafkaProducer.send() fails before partition gets assigned, then ProducerInterceptor.onAcknowledgement() gets RecordMetadata with partition == -1. Only time when ProducerInterceptor.onAcknowledgement() gets null record metadata is when the client passes null record to KafkaProducer.send()."

huxihx added 2 commits November 8, 2018 10:53
…ata`.

The Java doc for `InterceptorCallback#onComplete` says that exactly one of the arguments(metadata and exception) will be non-null. However, the commitment will be broken when TimeoutException is encountered since the code reassigns a new-created RecordMetadata object to variable `metadata`.

The solution is to leave `metadata1` unchanged and pass a new RecordMetadata instance to `onAcknowledgement`.
@huxihx
Copy link
Copy Markdown
Contributor Author

huxihx commented Nov 8, 2018

@junrao Please review the updated doc. Thanks.

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.

@huxihx : Thanks for the patch. LGTM. Just a minor comment below.

* metadata will contain the special -1 value for all fields except for topicPartition, which will be valid.
*
* @param metadata The metadata for the record that was sent (i.e. the partition and offset). An empty metadata
* with -1 value for all fields except for topicPartition returned if an error occurred.
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.

returned => will be returned

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.

@huxihx: Thanks for the updated patch. LGTM

@junrao junrao merged commit 895c83f into apache:trunk Nov 9, 2018
pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
The metadata in the callback is not null with non-null exception.

Reviewers: Jun Rao <junrao@gmail.com>
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