chia7712 commented on code in PR #19820:
URL: https://github.com/apache/kafka/pull/19820#discussion_r2164565204


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -3772,7 +3772,19 @@ class KafkaApis(val requestChannel: RequestChannel,
           case Some(error) =>
             topic.partitions().forEach(partition => 
responseBuilder.addPartition(topic.topicName(), partition.partitionIndex(), 
metadataCache.topicNamesToIds(), error.error))
           case None =>
-            authorizedTopicPartitions.add(topic)

Review Comment:
   Excuse me, why to make this change? it makes a copy of `topic`



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorService.java:
##########
@@ -682,15 +682,43 @@ CompletableFuture<AlterShareGroupOffsetsResponseData> 
persisterInitialize(
                         
handlePersisterInitializeResponse(request.groupTopicPartitionData().groupId(), 
result, new ShareGroupHeartbeatResponseData());
                         return response;
                     } else {
-                        //TODO build new AlterShareGroupOffsetsResponseData 
for error response
-                        return response;
+                        return buildErrorResponse(response, result);
                     }
                 } else {
                     return buildErrorResponse(request, response, exp);
                 }
 
             });
     }
+    
+    private AlterShareGroupOffsetsResponseData 
buildErrorResponse(AlterShareGroupOffsetsResponseData response, 
InitializeShareGroupStateResult result) {
+        AlterShareGroupOffsetsResponseData data = new 
AlterShareGroupOffsetsResponseData();
+        data.setResponses(
+            new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopicCollection(response.responses().stream()
+                .map(topic -> {
+                    
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic 
topicData = new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic()
+                        .setTopicName(topic.topicName());
+                    topic.partitions().forEach(partition -> {
+                        
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponsePartition 
partitionData;
+                        PartitionErrorData error = 
result.getErrors().get(topic.topicId()).get(partition.partitionIndex());

Review Comment:
   Furthermore, how do we ensure that the topic from 
`AlterShareGroupOffsetsResponseData` must exist in 
`InitializeShareGroupStateResult`?
   
   If users attempt  to alter the nonexistent partitions within an existing 
topic, the `AlterShareGroupOffsetsResponseData` will contain the topic but 
`InitializeShareGroupStateResult` will not. Is this correct?



##########
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupCoordinatorService.java:
##########
@@ -682,15 +682,43 @@ CompletableFuture<AlterShareGroupOffsetsResponseData> 
persisterInitialize(
                         
handlePersisterInitializeResponse(request.groupTopicPartitionData().groupId(), 
result, new ShareGroupHeartbeatResponseData());
                         return response;
                     } else {
-                        //TODO build new AlterShareGroupOffsetsResponseData 
for error response
-                        return response;
+                        return buildErrorResponse(response, result);
                     }
                 } else {
                     return buildErrorResponse(request, response, exp);
                 }
 
             });
     }
+    
+    private AlterShareGroupOffsetsResponseData 
buildErrorResponse(AlterShareGroupOffsetsResponseData response, 
InitializeShareGroupStateResult result) {
+        AlterShareGroupOffsetsResponseData data = new 
AlterShareGroupOffsetsResponseData();
+        data.setResponses(
+            new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopicCollection(response.responses().stream()
+                .map(topic -> {
+                    
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic 
topicData = new 
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponseTopic()
+                        .setTopicName(topic.topicName());
+                    topic.partitions().forEach(partition -> {
+                        
AlterShareGroupOffsetsResponseData.AlterShareGroupOffsetsResponsePartition 
partitionData;
+                        PartitionErrorData error = 
result.getErrors().get(topic.topicId()).get(partition.partitionIndex());

Review Comment:
   `result.getErrors()` will create a new collection by grouping data. Perhaps 
it should be moved out of loop.



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

Reply via email to