jolshan commented on code in PR #13231: URL: https://github.com/apache/kafka/pull/13231#discussion_r1107587497
########## clients/src/main/java/org/apache/kafka/common/requests/AddPartitionsToTxnRequest.java: ########## @@ -101,15 +130,61 @@ public String toString() { public AddPartitionsToTxnRequest(final AddPartitionsToTxnRequestData data, short version) { super(ApiKeys.ADD_PARTITIONS_TO_TXN, version); this.data = data; + this.version = version; } - + + // Only used for versions < 4 public List<TopicPartition> partitions() { if (cachedPartitions != null) { return cachedPartitions; } cachedPartitions = Builder.getPartitions(data); return cachedPartitions; } + + private List<TopicPartition> partitionsForTransaction(String transaction) { + if (cachedPartitionsByTransaction == null) { + cachedPartitionsByTransaction = new HashMap<>(); + } + + return cachedPartitionsByTransaction.computeIfAbsent(transaction, txn -> { + List<TopicPartition> partitions = new ArrayList<>(); + for (AddPartitionsToTxnTopic topicCollection : data.transactions().find(txn).topics()) { + for (Integer partition : topicCollection.partitions()) { + partitions.add(new TopicPartition(topicCollection.name(), partition)); + } + } + return partitions; + }); + } + + public Map<String, List<TopicPartition>> partitionsByTransaction() { + if (cachedPartitionsByTransaction != null && cachedPartitionsByTransaction.size() == data.transactions().size()) { Review Comment: I'm not sure how that would happen -- 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