jolshan commented on code in PR #15968:
URL: https://github.com/apache/kafka/pull/15968#discussion_r1607367455


##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java:
##########
@@ -891,11 +897,15 @@ private void sendProduceRequest(long now, int 
destination, short acks, int timeo
             // which is supporting the new magic version to one which doesn't, 
then we will need to convert.
             if (!records.hasMatchingMagic(minUsedMagic))
                 records = batch.records().downConvert(minUsedMagic, 0, 
time).records();
-            ProduceRequestData.TopicProduceData tpData = tpd.find(tp.topic());
-            if (tpData == null) {
-                tpData = new 
ProduceRequestData.TopicProduceData().setName(tp.topic());
-                tpd.add(tpData);
+            Optional<ProduceRequestData.TopicProduceData> topicProduceData = 
canUseTopicId ?
+                    Optional.ofNullable(tpd.find(tp.topic(), 
topicIds.get(tp.topic()))) :
+                    tpd.stream().filter(data -> 
data.name().equals(tp.topic())).findFirst();
+
+            ProduceRequestData.TopicProduceData tpData = 
topicProduceData.orElse(new 
ProduceRequestData.TopicProduceData().setName(tp.topic()));
+            if (canUseTopicId) {
+                tpData.setTopicId(topicIds.get(tp.topic()));
             }
+            tpd.add(tpData);

Review Comment:
   Hmm -- we don't need to add if we already added this right? I also wonder if 
we can cache by topic name so we don't have to findFirst



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