hachikuji commented on code in PR #13579:
URL: https://github.com/apache/kafka/pull/13579#discussion_r1170696945


##########
core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala:
##########
@@ -332,24 +331,42 @@ class TransactionCoordinator(txnConfig: TransactionConfig,
       debug(s"Returning ${Errors.INVALID_REQUEST} error code to client for 
$transactionalId's AddPartitions request for verification")
       
responseCallback(AddPartitionsToTxnResponse.resultForTransaction(transactionalId,
 partitions.map(_ -> Errors.INVALID_REQUEST).toMap.asJava))
     } else {
-      val result: ApiResult[(Int, TransactionMetadata)] = 
getTransactionMetadata(transactionalId, producerId, producerEpoch, partitions)
-      
+      val result: ApiResult[Map[TopicPartition, Errors]] =
+        txnManager.getTransactionState(transactionalId).flatMap {
+          case None => Left(Errors.INVALID_PRODUCER_ID_MAPPING)
+
+          case Some(epochAndMetadata) =>
+            val txnMetadata = epochAndMetadata.transactionMetadata
+
+            // generate the new transaction metadata with added partitions
+            txnMetadata.inLock {
+              if (txnMetadata.producerId != producerId) {
+                Left(Errors.INVALID_PRODUCER_ID_MAPPING)
+              } else if (txnMetadata.producerEpoch != producerEpoch) {
+                Left(Errors.PRODUCER_FENCED)
+              } else if (txnMetadata.state == PrepareCommit || 
txnMetadata.state == PrepareAbort) {
+                Left(Errors.CONCURRENT_TRANSACTIONS)
+              } else {
+                Right(partitions.map(part => 

Review Comment:
   nit: usually we would write `partitions.map { part =>



##########
core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala:
##########
@@ -332,24 +331,42 @@ class TransactionCoordinator(txnConfig: TransactionConfig,
       debug(s"Returning ${Errors.INVALID_REQUEST} error code to client for 
$transactionalId's AddPartitions request for verification")
       
responseCallback(AddPartitionsToTxnResponse.resultForTransaction(transactionalId,
 partitions.map(_ -> Errors.INVALID_REQUEST).toMap.asJava))
     } else {
-      val result: ApiResult[(Int, TransactionMetadata)] = 
getTransactionMetadata(transactionalId, producerId, producerEpoch, partitions)
-      
+      val result: ApiResult[Map[TopicPartition, Errors]] =
+        txnManager.getTransactionState(transactionalId).flatMap {
+          case None => Left(Errors.INVALID_PRODUCER_ID_MAPPING)
+
+          case Some(epochAndMetadata) =>
+            val txnMetadata = epochAndMetadata.transactionMetadata
+
+            // generate the new transaction metadata with added partitions

Review Comment:
   nit: this comment seems misplaced
   
   Could we have a short comment here that we intentionally do not check 
pending state? We can mention that partitions are removed from the transaction 
metadata as soon as the markers are confirmed written.



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