chia7712 commented on a change in pull request #10269:
URL: https://github.com/apache/kafka/pull/10269#discussion_r588094923



##########
File path: core/src/main/scala/kafka/server/KafkaApis.scala
##########
@@ -811,31 +821,40 @@ class KafkaApis(val requestChannel: RequestChannel,
           .setRecords(data.records)
           
.setPreferredReadReplica(data.preferredReadReplica.getOrElse(FetchResponse.INVALID_PREFERRED_REPLICA_ID))
         data.divergingEpoch.foreach(partitionData.setDivergingEpoch)
-        partitions.put(tp, partitionData)
+        addPartition(tp.topic, partitionData)
       }
-      erroneous.foreach { case (tp, data) => partitions.put(tp, data) }
-
-      var unconvertedFetchResponse: FetchResponse = null
+      erroneous.foreach { case (tp, data) => addPartition(tp.topic, data) }
 
-      def createResponse(throttleTimeMs: Int): FetchResponse = {
+      def createResponse(unconvertedFetchResponse: FetchResponse, 
throttleTimeMs: Int): FetchResponse = {
         // Down-convert messages for each partition if required
-        val convertedData = new util.LinkedHashMap[TopicPartition, 
FetchResponseData.PartitionData]
-        unconvertedFetchResponse.responseData.forEach { (tp, 
unconvertedPartitionData) =>
-          val error = Errors.forCode(unconvertedPartitionData.errorCode)
-          if (error != Errors.NONE)
-            debug(s"Fetch request with correlation id 
${request.header.correlationId} from client $clientId " +
-              s"on partition $tp failed due to ${error.exceptionName}")
-          convertedData.put(tp, maybeConvertFetchedData(tp, 
unconvertedPartitionData))
+        val convertedResponse = new FetchResponseData()
+          .setErrorCode(unconvertedFetchResponse.error.code)
+          .setThrottleTimeMs(throttleTimeMs)
+          .setSessionId(unconvertedFetchResponse.sessionId)
+          .setResponses(new 
util.ArrayList[FetchResponseData.FetchableTopicResponse](unconvertedFetchResponse.data.responses.size))
+        unconvertedFetchResponse.data.responses.forEach { unconvertedTopicData 
=>
+          val convertedTopicResponse = new 
FetchResponseData.FetchableTopicResponse()
+            .setTopic(unconvertedTopicData.topic)
+            .setPartitions(new 
util.ArrayList[FetchResponseData.PartitionData](unconvertedTopicData.partitions.size))
+          convertedResponse.responses.add(convertedTopicResponse)
+          unconvertedTopicData.partitions.forEach { unconvertedPartitionData =>
+            val tp = new TopicPartition(unconvertedTopicData.topic, 
unconvertedPartitionData.partitionIndex)

Review comment:
       yep, we made many copies when processing fetch request.
   
   1. merge responsePartitionData with errors
   1. down-convert fetch data 
   1. regroup data
   
   This patch want to fix 3. and others are traced by 
https://issues.apache.org/jira/browse/KAFKA-12387
   
   At any rate, I will take a look at other cases if it does not bring a big 
patch.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to