junrao commented on code in PR #23665:
URL: https://github.com/apache/kafka/pull/23665#discussion_r4394695002
##########
clients/src/main/java/org/apache/kafka/common/requests/RequestContext.java:
##########
@@ -148,17 +174,28 @@ public Send buildResponseSend(AbstractResponse body) {
* so we do not lose the benefit of "zero copy" transfers from disk.
*/
public ByteBuffer buildResponseEnvelopePayload(AbstractResponse body) {
- return body.serializeWithHeader(header.toResponseHeader(),
apiVersion());
+ short version = effectiveApiVersion();
+ return body.serializeWithHeader(responseHeader(version), version);
}
- private boolean isUnsupportedApiVersionsRequest() {
- return header.apiKey() == API_VERSIONS &&
!header.isApiVersionSupported();
+ private ResponseHeader responseHeader(short responseVersion) {
+ return new ResponseHeader(header.correlationId(),
header.apiKey().responseHeaderVersion(responseVersion));
}
- public short apiVersion() {
- // Use v0 when serializing an unhandled ApiVersion response
- if (isUnsupportedApiVersionsRequest())
- return 0;
+ private boolean isApiVersionsFallback() {
+ return header.apiKey().isFallbackVersion(header.apiVersion());
Review Comment:
To me, I think what we had earlier is better.
isUnsupportedApiVersionsRequest is clearer than isApiVersionsFallback. Also,
the way that we handle unsupported API Version is very specific to the server
side logic. So, putting that logic in RequestContext seems better than in
ApiKeys.
What do you think @chia7712 ?
##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -1557,7 +1558,7 @@ class KafkaApis(val requestChannel: RequestChannel,
} else if (clusterIdOrNodeIdIsInvalid(apiVersionRequest)) {
apiVersionRequest.getErrorResponse(requestThrottleMs,
Errors.REBOOTSTRAP_REQUIRED.exception)
} else {
- apiVersionManager.apiVersionResponse(requestThrottleMs,
request.header.apiVersion() < 4)
+ apiVersionManager.apiVersionResponse(requestThrottleMs,
apiVersionRequest.version < 4)
Review Comment:
Could we use apiVersionRequest.version in
ControllerApis.handleApiVersionsRequest() too?
##########
core/src/main/scala/kafka/server/ControllerApis.scala:
##########
@@ -204,7 +204,7 @@ class ControllerApis(
controllerMutationQuotaRecorderFor(controllerMutationQuota))
val future = deleteTopics(context,
deleteTopicsRequest.data,
- request.context.apiVersion,
+ request.context.effectiveApiVersion,
Review Comment:
This can just be deleteTopicsRequest.version.
##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -1405,7 +1406,7 @@ class KafkaApis(val requestChannel: RequestChannel,
if (exception != null) {
requestHelper.sendMaybeThrottle(request,
joinGroupRequest.getErrorResponse(exception))
} else {
- requestHelper.sendMaybeThrottle(request, new
JoinGroupResponse(response, request.context.apiVersion))
+ requestHelper.sendMaybeThrottle(request, new
JoinGroupResponse(response, request.context.effectiveApiVersion))
Review Comment:
This can just be joinGroupRequest.version.
##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -1469,7 +1470,7 @@ class KafkaApis(val requestChannel: RequestChannel,
// clients cannot interpret the new code, so downgrade it to
UNKNOWN_SERVER_ERROR.
// ErrorMessage is "versions": "3+", "ignorable": true and is stripped
at the
// serialization layer for v<3, so only the error code needs gating
here.
- if (request.context.apiVersion < 3) {
+ if (request.context.effectiveApiVersion < 3) {
Review Comment:
This can just be deleteGroupsRequest.version.
##########
core/src/main/scala/kafka/server/ControllerApis.scala:
##########
@@ -966,14 +966,14 @@ class ControllerApis(
if (!allowTokenRequests(request)) {
requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs =>
-
CreateDelegationTokenResponse.prepareResponse(request.context.requestVersion,
requestThrottleMs,
+
CreateDelegationTokenResponse.prepareResponse(request.context.effectiveApiVersion,
requestThrottleMs,
Review Comment:
This can just be createTokenRequest.version. Ditto below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]