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


##########
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,
+                        "Failed to change the outcome of a finished 
transaction"
+                                + " [txId=" + txId + ", txState=" + 
txMeta.txState() + "].");
+            }
+            // The transaction has already been finished, but the locks are 
not released.

Review Comment:
   It was related to a different task, 
[IGNITE-20779](https://issues.apache.org/jira/browse/IGNITE-20779)



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