artemlivshits commented on code in PR #17698:
URL: https://github.com/apache/kafka/pull/17698#discussion_r1857554819


##########
core/src/main/scala/kafka/coordinator/transaction/TransactionMetadata.scala:
##########
@@ -477,23 +484,27 @@ private[transaction] class TransactionMetadata(val 
transactionalId: String,
           }
 
         case PrepareAbort | PrepareCommit => // from endTxn
+          // In V2, we allow state transits from Empty, CompleteCommit and 
CompleteAbort to PrepareAbort. It is possible
+          // their updated start time is not equal to the current start time.
+          val allowedEmptyAbort = toState == PrepareAbort && 
transitMetadata.clientTransactionVersion.supportsEpochBump() &&
+            (state == Empty || state == CompleteCommit || state == 
CompleteAbort)

Review Comment:
   Maybe create a Boolean flag here `validTimestamp` so that inside the 
condition we can check `!validTimestamp`?



##########
core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala:
##########
@@ -498,6 +498,39 @@ class TransactionCoordinator(txnConfig: TransactionConfig,
       requestLocal)
   }
 
+  /*
+    Here is the table to demonstrate the state transition for Empty, 
CompleteAbort, CompleteCommit in Transaction V2.
+    Note:
+    PF = PRODUCER_FENCED
+    ITS = INVALID_TXN_STATE
+    NONE = No error and no epoch bump
+    EB = No error and epoch bump
+
+    Retry => producerEpoch = txnState.ProducerEpoch - 1
+    Current => producerEpoch = txnState.ProducerEpoch
+
+    ------------------------------------------------------
+    With transaction V1, Retry is not allowed, PRODUCER_FENCED will be 
returned if the epoch does not match.
+    Empty does not accept Abort and Commit.
+    CompleteAbort only accepts Abort.
+    CompleteCommit only accepts Commit.
+    For all invalid cases, INVALID_TXN_STATE is returned.
+
+    ------------------------------------------------------
+    With transaction V2.
+    +----------------+-----------------+-----------------+
+    |                | Abort           | Commit          |
+    +----------------+-------+---------+-------+---------+
+    |                | Retry | Current | Retry | Current |
+    +----------------+-------+---------+-------+---------+
+    | Empty          | PF    | EB      | PF   | ITS     |

Review Comment:
   nit: formatting.



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