denis-chudov commented on code in PR #2856:
URL: https://github.com/apache/ignite-3/pull/2856#discussion_r1426916350
##########
modules/api/src/main/java/org/apache/ignite/lang/ErrorGroups.java:
##########
@@ -354,6 +354,9 @@ public static class Transactions {
/** Coordinator tries to commit a transaction that has already been
aborted. */
public static final int TX_WAS_ABORTED_ERR =
TX_ERR_GROUP.registerErrorCode((short) 15);
+
+ /** Coordinator tries to abort a transaction that has already been
committed. */
Review Comment:
```suggestion
/** An attempt to abort a transaction that has already been
committed. */
```
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/TxManagerImpl.java:
##########
@@ -375,6 +398,18 @@ public CompletableFuture<Void> finish(
));
}
+ private static CompletableFuture<Void> checkTxOutcome(boolean commit, UUID
txId, TransactionMeta stateMeta) {
+ if ((stateMeta.txState() == COMMITTED) == commit) {
+ return nullCompletedFuture();
+ }
+
+ int result = (stateMeta.txState() == COMMITTED) && !commit ?
TX_WAS_COMMITTED_ERR : TX_WAS_ABORTED_ERR;
+
+ return CompletableFuture.failedFuture(new TransactionException(result,
Review Comment:
```suggestion
int errorCode = (stateMeta.txState() == COMMITTED) && !commit ?
TX_WAS_COMMITTED_ERR : TX_WAS_ABORTED_ERR;
return CompletableFuture.failedFuture(new
TransactionException(errorCode,
```
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -795,28 +813,50 @@ private CompletableFuture<TransactionMeta>
processTxStateCommitPartitionRequest(
* @param txStateMeta Transaction meta.
* @return Tx recovery future, or completed future if the recovery isn't
needed, or failed future if the recovery is not possible.
*/
- private CompletableFuture<TransactionMeta>
triggerTxRecoveryOnTxStateResolutionIfNeeded(UUID txId, @Nullable TxStateMeta
txStateMeta) {
- assert txStateMeta == null || !isFinalState(txStateMeta.txState()) :
"Unexpected transaction state: " + txStateMeta;
+ private CompletableFuture<TransactionMeta>
triggerTxRecoveryOnTxStateResolutionIfNeeded(
+ UUID txId,
+ @Nullable TxStateMeta txStateMeta
+ ) {
+ // The state is either null or PENDING or ABANDONED, other states have
been filtered out previously.
+ assert txStateMeta == null || txStateMeta.txState() == PENDING ||
txStateMeta.txState() == ABANDONED
+ : "Unexpected transaction state: " + txStateMeta;
TxMeta txMeta = txStateStorage.get(txId);
if (txMeta == null) {
// This means the transaction is pending and we should trigger the
recovery if there is no tx coordinator in topology.
if (txStateMeta == null
|| txStateMeta.txState() == ABANDONED
+ || txStateMeta.txCoordinatorId() == null
||
clusterNodeResolver.getById(txStateMeta.txCoordinatorId()) == null) {
// This means that primary replica for commit partition has
changed, since the local node doesn't have the volatile tx
// state; and there is no final tx state in txStateStorage, or
the tx coordinator left the cluster. But we can assume
// that as the coordinator (or information about it) is
missing, there is no need to wait a finish request from
// tx coordinator, the transaction can't be committed at all.
- return triggerTxRecovery(txId);
+ return triggerTxRecovery(txId, localNode.id())
+ .handle((v, ex) -> {
+ TransactionMeta transactionMeta =
txManager.stateMeta(txId);
+
+ assert transactionMeta != null;
+
+ if (transactionMeta.txState() == FINISHING) {
+ return ((TxStateMetaFinishing)
transactionMeta).txFinishFuture();
+ }
+
+ assert transactionMeta.txState() == ABORTED;
Review Comment:
Why only aborted? There could be successful commit from coordinator.
--
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]