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


##########
core/src/test/scala/unit/kafka/coordinator/transaction/TransactionMarkerChannelManagerTest.scala:
##########
@@ -65,10 +65,8 @@ class TransactionMarkerChannelManagerTest {
   private val coordinatorEpoch2 = 1
   private val txnTimeoutMs = 0
   private val txnResult = TransactionResult.COMMIT
-  private val txnMetadata1 = new TransactionMetadata(transactionalId1, 
producerId1, producerId1, RecordBatch.NO_PRODUCER_ID,
-    producerEpoch, lastProducerEpoch, txnTimeoutMs, 
TransactionState.PREPARE_COMMIT, util.Set.of(partition1, partition2), 0L, 0L, 
TransactionVersion.TV_2)
-  private val txnMetadata2 = new TransactionMetadata(transactionalId2, 
producerId2, producerId2, RecordBatch.NO_PRODUCER_ID,
-    producerEpoch, lastProducerEpoch, txnTimeoutMs, 
TransactionState.PREPARE_COMMIT, util.Set.of(partition1), 0L, 0L, 
TransactionVersion.TV_2)
+  private val txnMetadata1 = new TransactionMetadata(transactionalId1, 
producerId1, producerId1, RecordBatch.NO_PRODUCER_ID, producerEpoch, 
lastProducerEpoch, txnTimeoutMs, TransactionState.PREPARE_COMMIT, 0L, 0L, 
TransactionVersion.TV_2)

Review Comment:
   > we always call this add partitions method?
   
   yes
   
https://github.com/apache/kafka/blob/f0c3d93104caa33a2566eff0656de37573a3922a/core/src/main/scala/kafka/coordinator/transaction/TransactionLog.scala#L134
   
   we could remove the usage of `addPartitions` from production code. for 
example:
   ```java
           val state = TransactionState.fromId(value.transactionStatus)
           val tps: util.Set[TopicPartition] = if 
(!state.equals(TransactionState.EMPTY)) value.transactionPartitions
             .stream().flatMap(partitionsSchema => 
partitionsSchema.partitionIds().stream().map(id => new 
TopicPartition(partitionsSchema.topic(), id.intValue())))
             .collect(Collectors.toSet)
           else util.Set.of()
           Some(new TransactionMetadata(
             transactionalId,
             value.producerId,
             value.previousProducerId,
             value.nextProducerId,
             value.producerEpoch,
             RecordBatch.NO_PRODUCER_EPOCH,
             value.transactionTimeoutMs,
             state,
             tps,
             value.transactionStartTimestampMs,
             value.transactionLastUpdateTimestampMs,
             
TransactionVersion.fromFeatureLevel(value.clientTransactionVersion)))
   ```
   
   If the method `removePartition` could adopt copy-on-write policy, the inner 
member `topicPartitions` could be an immutable collection.



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