sanpwc commented on code in PR #2751:
URL: https://github.com/apache/ignite-3/pull/2751#discussion_r1382912610


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -1437,6 +1450,49 @@ private CompletableFuture<Void> finishAndCleanup(
             UUID txId,
             String txCoordinatorId
     ) {
+        TxMeta txMeta = txStateStorage.get(txId);
+
+        // Check that a transaction has already been finished.
+        boolean transactionAlreadyFinished = txMeta != null && 
isFinalState(txMeta.txState());
+
+        // Check locksReleased flag. If it is already set, do nothing and 
return a successful result.
+        // Even if the outcome is different (the transaction was aborted, but 
we want to commit it),
+        // we return 'success' to be in alignment with common transaction 
handling.
+        if (transactionAlreadyFinished) {
+            if (txMeta.locksReleased()) {
+                return completedFuture(null);
+            }
+
+            assert !(txMeta.txState() == COMMITED && !commit) : "Not allowed 
to abort an already committed transaction.";
+            // If the locks were not released, we are likely to be in a 
recovery mode and retrying the finish request.
+            // In this case we want to check the expected outcome and the 
actual one.
+            if (commit && txMeta.txState() == ABORTED) {
+                LOG.error("Failed to commit a transaction that is already 
aborted [txId={}].", txId);
+
+                throw new TransactionException(TX_WAS_ABORTED_ERR,

Review Comment:
   Because it's not possible from our logics point of view to send rollback 
over finished transaction.
   
   - First of all txCoordinator calls use same tx state over retries, both 
abort and commit are possible.
   - Server side recovery (which is not implemented yet) may only change tx 
state to aborted.
   - TxCoordinator itself should prevent user calls with different proposed 
state to the one, that was already triggered. Here I'm talking about client -> 
txCoordinator.commitAsync(); txCoordinator.rollbackAsync()
   
   All in all, that means that with commit it's valid to see:
   
   - null (if it's the first change state attempt)
   - commit (if it was already updated by the prior iteration)
   - abort (if it was rolled back by initiate recover logic, this is very 
unlikely case because initiate recover will only roll back the tx if 
coordinator is dead)
   
   And within roll back it's possible to see: 
   
   - null,
   - abort



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