jolshan commented on code in PR #12845: URL: https://github.com/apache/kafka/pull/12845#discussion_r1023210180
########## core/src/main/scala/kafka/server/KafkaApis.scala: ########## @@ -1646,73 +1649,46 @@ class KafkaApis(val requestChannel: RequestChannel, } } + private def makeGroupCoordinatorRequestContextFrom( + request: RequestChannel.Request, + requestLocal: RequestLocal + ): GroupCoordinatorRequestContext = { + new GroupCoordinatorRequestContext( + request.context.header.data.requestApiVersion, + request.context.header.data.clientId, + request.context.clientAddress, + requestLocal.bufferSupplier + ) + } + def handleJoinGroupRequest(request: RequestChannel.Request, requestLocal: RequestLocal): Unit = { val joinGroupRequest = request.body[JoinGroupRequest] - // the callback for sending a join-group response - def sendResponseCallback(joinResult: JoinGroupResult): Unit = { - def createResponse(requestThrottleMs: Int): AbstractResponse = { - val protocolName = if (request.context.apiVersion() >= 7) - joinResult.protocolName.orNull - else - joinResult.protocolName.getOrElse(GroupCoordinator.NoProtocol) - - val responseBody = new JoinGroupResponse( - new JoinGroupResponseData() - .setThrottleTimeMs(requestThrottleMs) - .setErrorCode(joinResult.error.code) - .setGenerationId(joinResult.generationId) - .setProtocolType(joinResult.protocolType.orNull) - .setProtocolName(protocolName) - .setLeader(joinResult.leaderId) - .setSkipAssignment(joinResult.skipAssignment) - .setMemberId(joinResult.memberId) - .setMembers(joinResult.members.asJava) - ) - - trace("Sending join group response %s for correlation id %d to client %s." - .format(responseBody, request.header.correlationId, request.header.clientId)) - responseBody - } - requestHelper.sendResponseMaybeThrottle(request, createResponse) + def sendResponse(response: AbstractResponse): Unit = { + trace("Sending join group response %s for correlation id %d to client %s." + .format(response, request.header.correlationId, request.header.clientId)) + requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs => { + response.maybeSetThrottleTimeMs(requestThrottleMs) + response + }) } if (joinGroupRequest.data.groupInstanceId != null && config.interBrokerProtocolVersion.isLessThan(IBP_2_3_IV0)) { // Only enable static membership when IBP >= 2.3, because it is not safe for the broker to use the static member logic // until we are sure that all brokers support it. If static group being loaded by an older coordinator, it will discard // the group.instance.id field, so static members could accidentally become "dynamic", which leads to wrong states. - sendResponseCallback(JoinGroupResult(JoinGroupRequest.UNKNOWN_MEMBER_ID, Errors.UNSUPPORTED_VERSION)) + sendResponse(joinGroupRequest.getErrorResponse(Errors.UNSUPPORTED_VERSION.exception)) } else if (!authHelper.authorize(request.context, READ, GROUP, joinGroupRequest.data.groupId)) { - sendResponseCallback(JoinGroupResult(JoinGroupRequest.UNKNOWN_MEMBER_ID, Errors.GROUP_AUTHORIZATION_FAILED)) + sendResponse(joinGroupRequest.getErrorResponse(Errors.GROUP_AUTHORIZATION_FAILED.exception)) } else { - val groupInstanceId = Option(joinGroupRequest.data.groupInstanceId) Review Comment: Did you mean that it is in the adapter? I see it at line 50 -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org