Skip to content

MINOR: Factor out common response parsing logic#9617

Merged
hachikuji merged 4 commits intoapache:trunkfrom
hachikuji:minor-parse-response-cleanup
Nov 20, 2020
Merged

MINOR: Factor out common response parsing logic#9617
hachikuji merged 4 commits intoapache:trunkfrom
hachikuji:minor-parse-response-cleanup

Conversation

@hachikuji
Copy link
Copy Markdown
Contributor

This patch factors out some common parsing logic from NetworkClient.parseResponse and AbstractResponse.parseResponse. As a result of this refactor, we are now verifying the correlationId in forwarded requests. This patch also adds a test case to verify handling in this case.

Committer Checklist (excluded from commit message)

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

@hachikuji
Copy link
Copy Markdown
Contributor Author

This is a follow-up from #9563. cc @chia7712 @abbccdda

While I was working on this patch, I noticed this: https://issues.apache.org/jira/browse/KAFKA-10743. In this patch, I have just removed the metric.

Copy link
Copy Markdown

@abbccdda abbccdda left a comment

Choose a reason for hiding this comment

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

Overall LGTM, just some minor comments

* Raised if the correlationId in a response header does not match
* the expected value from the request header.
*/
public class CorrelationIdMismatchException extends IllegalStateException {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: we could put this exception into common/internals to indicate that we don't plan to let external user catch it.

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.

Yeah, I was debating the location. I decided to put it in common/requests since it is not a public package and the error is specific to the request protocol.

}

public int requestCorrelationId() {
return requestCorrelationId;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This field is not used.

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.

Yeah, I added it for completeness. It is a little odd if the mismatch exception only tells you what the response correlationId was.

/**
* Validate that the response corresponds to the request we expect or else explode
*/
private static void correlate(RequestHeader requestHeader, ResponseHeader responseHeader) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: I don't think we need to remove this helper

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.

Why do you want to keep it if it is not used?

Comment thread core/src/main/scala/kafka/server/ForwardingManager.scala
@hachikuji hachikuji merged commit 438749b into apache:trunk Nov 20, 2020
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