zhaohaidao commented on a change in pull request #9311:
URL: https://github.com/apache/kafka/pull/9311#discussion_r497217290



##########
File path: 
core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala
##########
@@ -381,24 +385,35 @@ class TransactionCoordinator(brokerId: Int,
             if (txnMetadata.producerId != producerId)
               Left(Errors.INVALID_PRODUCER_ID_MAPPING)
             // Strict equality is enforced on the client side requests, as 
they shouldn't bump the producer epoch.
-            else if ((isFromClient && producerEpoch != 
txnMetadata.producerEpoch) || producerEpoch < txnMetadata.producerEpoch)
+            else if (isFromClient && producerEpoch != 
txnMetadata.producerEpoch) {
+              if (producerEpoch == txnMetadata.lastProducerEpoch) {
+                Left(Errors.TRANSACTION_TIMED_OUT)
+              } else {
+                Left(Errors.PRODUCER_FENCED)
+              }
+            } else if (producerEpoch < txnMetadata.producerEpoch) {
               Left(Errors.PRODUCER_FENCED)
-            else if (txnMetadata.pendingTransitionInProgress && 
txnMetadata.pendingState.get != PrepareEpochFence)
+            } else if (txnMetadata.pendingTransitionInProgress
+              && !txnMetadata.pendingState.contains(PrepareEpochFence)
+              && !txnMetadata.pendingState.contains(PrepareEpochBumpThenAbort))
               Left(Errors.CONCURRENT_TRANSACTIONS)
             else txnMetadata.state match {
               case Ongoing =>
                 val nextState = if (txnMarkerResult == 
TransactionResult.COMMIT)
                   PrepareCommit
-                else
+                else {
                   PrepareAbort
-
-                if (nextState == PrepareAbort && 
txnMetadata.pendingState.contains(PrepareEpochFence)) {
+                }
+                if (nextState == PrepareAbort && (txnMetadata.pendingState.get 
== PrepareEpochFence
+                  || txnMetadata.pendingState.get == 
PrepareEpochBumpThenAbort)) {
                   // We should clear the pending state to make way for the 
transition to PrepareAbort and also bump
                   // the epoch in the transaction metadata we are about to 
append.
-                  isEpochFence = true
+                  isEpochFence = txnMetadata.pendingState.get == 
PrepareEpochFence

Review comment:
       Thanks for your advice. I found a simpler way to set the 
lastProducerEpoch and PrepareEpochBumpThenAbort is removed




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to