Don't retain abstract req in response #1
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I picked up ticket 5859 because it was marked with the newbie flag and it seemed like a good opportunity to learn more about about the request and response lifecycle in the Kafka broker.
I removed the parsed
AbstractRequest
that was stored inRequestChannel.Request
in the privatebodyAndSize: RequestAndSize
variable. Ismael points out that theAbstractRequest
is mainly used byKafkaApi
, so we should only need a reference there and nowhere else. However when I investigated I found several other usages withinRequestChannel.Request
itself. I've summarized these usages below:updateRequestMetrics
- Checks to see if the parsed request is aFetchRequest
to access theisFromFollower
value. Ismail mentioned in the ticket 5859 that "it needs theApiKeys
instance", but I don't know what he means by thatupdateRequestMetrics
- Requires the parsed size of the request in bytes to update therequestBytesHist
metricupdateRequestMetrics
- CallsrequestDesc(true)
orrequestDesc(false)
depending on whether trace logging enabled. It looks like it's used when request logging is enabled.Request
constructor has a trace logging line that callsrequestDesc(true)
I made some decisions on my own. Below is a summary for review.
KafkaApi
. Ideally this would be done a higher level and passed into each handler, but I was hesitant about changing all the handler method signatures. Effectively the response is only parsed once since only one handler can be called per request AFAIK.RequestChannel.Request
. I generate a detailed description because the codebase isn't consistent about requiring details or not. For example, there's a usage that's called for every instance ofRequestChannel.Request
(https://github.com/seglo/kafka/blob/trunk/core/src/main/scala/kafka/network/RequestChannel.scala#L107), so I thought it would be acceptable to parse the request once for details and retain it for use in other loggingRequestChannel.Request.requestDesc
.FetchRequest
and cache itsisFromFollower
property for use inupdateRequestMetrics
. I'm not sure how else to gain this information.AbstractRequest
twice, once forKafkaApi
and once for theRequestChannel.Request
constructor. I would be interested in finding a non-invasive way to avoid this, while maintaining immutability as requested by Ismael in the original ticket.