OmniaGM commented on code in PR #19964:
URL: https://github.com/apache/kafka/pull/19964#discussion_r2160224238


##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java:
##########
@@ -609,7 +607,18 @@ private void handleProduceResponse(ClientResponse 
response, Map<TopicPartition,
                                 .collect(Collectors.toList()),
                             p.errorMessage(),
                             p.currentLeader());
-                    ProducerBatch batch = batches.get(tp);
+                    // Version 13 drop topic name and add support to topic id.
+                    // We need to find batch based on topic id and partition 
index only as
+                    // topic name in the response might be empty.
+                    TopicIdPartition tpId = new TopicIdPartition(r.topicId(), 
p.index(), r.name());
+                    ProducerBatch batch = batches.entrySet().stream()
+                            .filter(entry -> entry.getKey().same(tpId))
+                            .map(Map.Entry::getValue).findFirst().orElse(null);
+
+                    if (batch == null) {
+                        throw new IllegalStateException("batch created for " + 
tpId + " can't be found, " +
+                                "topic might be recreated after the batch 
creation.");

Review Comment:
   No, I was just thinking that this should be IllegalStateException in 
generally instead of leaving the NPE from the get in the future for any reason. 



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