chia7712 commented on code in PR #19933:
URL: https://github.com/apache/kafka/pull/19933#discussion_r2145520517
##########
server/src/main/java/org/apache/kafka/server/transaction/AddPartitionsToTxnManager.java:
##########
@@ -243,11 +243,10 @@ public void addOrVerifyTransaction(
Collectors.toMap(Function.identity(), tp ->
Errors.COORDINATOR_NOT_AVAILABLE)));
} else {
AddPartitionsToTxnTopicCollection topicCollection = new
AddPartitionsToTxnTopicCollection();
-
topicPartitions.stream().collect(Collectors.groupingBy(TopicPartition::topic)).forEach((topic,
tps) -> {
- topicCollection.add(new AddPartitionsToTxnTopic()
- .setName(topic)
-
.setPartitions(tps.stream().map(TopicPartition::partition).collect(Collectors.toList())));
- });
+
topicPartitions.stream().collect(Collectors.groupingBy(TopicPartition::topic)).forEach((topic,
tps) ->
Review Comment:
Please consider leveraging the topic name index to avoid regrouping. for
example:
```java
topicPartitions.forEach(tp -> {
var r = topicCollection.find(tp.topic());
if (r == null) {
r = new AddPartitionsToTxnTopic().setName(tp.topic());
topicCollection.add(r);
}
r.partitions().add(tp.partition());
});
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]