CalvinConfluent commented on code in PR #16840:
URL: https://github.com/apache/kafka/pull/16840#discussion_r1747560534


##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java:
##########
@@ -368,15 +370,21 @@ public synchronized TransactionalRequestResult 
sendOffsetsToTransaction(final Ma
                 "(currentState= " + currentState + ")");
         }
 
-        log.debug("Begin adding offsets {} for consumer group {} to 
transaction", offsets, groupMetadata);
-        AddOffsetsToTxnRequest.Builder builder = new 
AddOffsetsToTxnRequest.Builder(
-            new AddOffsetsToTxnRequestData()
-                .setTransactionalId(transactionalId)
-                .setProducerId(producerIdAndEpoch.producerId)
-                .setProducerEpoch(producerIdAndEpoch.epoch)
-                .setGroupId(groupMetadata.groupId())
-        );
-        AddOffsetsToTxnHandler handler = new AddOffsetsToTxnHandler(builder, 
offsets, groupMetadata);
+        TxnRequestHandler handler;
+        if (coordinatorSupportsTransactionV2) {
+            log.debug("Begin adding offsets {} for consumer group {} to 
transaction with transaction protocol V2", offsets, groupMetadata);
+            handler = txnOffsetCommitHandler(null, offsets, groupMetadata, 
ApiKeys.TXN_OFFSET_COMMIT.latestVersion());
+        } else {
+            log.debug("Begin adding offsets {} for consumer group {} to 
transaction", offsets, groupMetadata);
+            AddOffsetsToTxnRequest.Builder builder = new 
AddOffsetsToTxnRequest.Builder(
+                new AddOffsetsToTxnRequestData()
+                    .setTransactionalId(transactionalId)
+                    .setProducerId(producerIdAndEpoch.producerId)
+                    .setProducerEpoch(producerIdAndEpoch.epoch)
+                    .setGroupId(groupMetadata.groupId())
+            );
+            handler = new AddOffsetsToTxnHandler(builder, offsets, 
groupMetadata);

Review Comment:
   The AddOffsetsToTxnHandler is used only when V2 is not enabled. Also, in the 
AddOffsetsToTxnHandler, the 
TxnOffsetCommitRequest.LAST_BEFORE_TRANSACTION_V2_VERSION is always used.



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

Reply via email to