@@ -694,20 +694,18 @@ MtmCreateTransState(MtmCurrentTrans* x)
694
694
{
695
695
bool found ;
696
696
MtmTransState * ts = hash_search (MtmXid2State , & x -> xid , HASH_ENTER , & found );
697
- if (!found ) {
698
- ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
699
- ts -> snapshot = x -> snapshot ;
700
- ts -> isLocal = true;
701
- if (TransactionIdIsValid (x -> gtid .xid )) {
702
- Assert (x -> gtid .node != MtmNodeId );
703
- ts -> gtid = x -> gtid ;
704
- strcpy (ts -> gid , x -> gid );
705
- } else {
706
- /* I am coordinator of transaction */
707
- ts -> gtid .xid = x -> xid ;
708
- ts -> gtid .node = MtmNodeId ;
709
- ts -> gid [0 ] = '\0' ;
710
- }
697
+ ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
698
+ ts -> snapshot = x -> snapshot ;
699
+ ts -> isLocal = true;
700
+ if (TransactionIdIsValid (x -> gtid .xid )) {
701
+ Assert (x -> gtid .node != MtmNodeId );
702
+ ts -> gtid = x -> gtid ;
703
+ strcpy (ts -> gid , x -> gid );
704
+ } else {
705
+ /* I am coordinator of transaction */
706
+ ts -> gtid .xid = x -> xid ;
707
+ ts -> gtid .node = MtmNodeId ;
708
+ ts -> gid [0 ] = '\0' ;
711
709
}
712
710
return ts ;
713
711
}
@@ -853,11 +851,11 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
853
851
if (!ts -> votingCompleted ) {
854
852
if (ts -> status != TRANSACTION_STATUS_ABORTED ) {
855
853
MtmAbortTransaction (ts );
856
- elog (WARNING , "Transaction is aborted because of %d msec timeout expiration, prepare time %d msec" , (int )transTimeout , (int )USEC_TO_MSEC (ts -> csn - x -> snapshot ));
854
+ elog (WARNING , "Transaction %d is aborted because of %d msec timeout expiration, prepare time %d msec" , x -> xid , (int )transTimeout , (int )USEC_TO_MSEC (ts -> csn - x -> snapshot ));
857
855
}
858
856
} else if (nConfigChanges != Mtm -> nConfigChanges ) {
859
857
MtmAbortTransaction (ts );
860
- elog (WARNING , "Transaction is aborted because cluster configuration is changed during commit" );
858
+ elog (WARNING , "Transaction %d is aborted because cluster configuration is changed during commit" , x -> xid );
861
859
}
862
860
x -> status = ts -> status ;
863
861
MTM_LOG3 ("%d: Result of vote: %d" , MyProcPid , ts -> status );
@@ -879,9 +877,12 @@ MtmAbortPreparedTransaction(MtmCurrentTrans* x)
879
877
MtmLock (LW_EXCLUSIVE );
880
878
tm = (MtmTransMap * )hash_search (MtmGid2State , x -> gid , HASH_REMOVE , NULL );
881
879
Assert (tm != NULL );
880
+ MTM_LOG1 ("Abort prepared transaction %d with gid='%s' is already aborted" , x -> xid , x -> gid );
882
881
MtmAbortTransaction (tm -> state );
883
882
MtmUnlock ();
884
883
x -> status = TRANSACTION_STATUS_ABORTED ;
884
+ } else {
885
+ MTM_LOG1 ("Transaction %d with gid='%s' is already aborted" , x -> xid , x -> gid );
885
886
}
886
887
}
887
888
@@ -917,6 +918,7 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
917
918
Assert (Mtm -> nActiveTransactions != 0 );
918
919
Mtm -> nActiveTransactions -= 1 ;
919
920
} else {
921
+ MTM_LOG1 ("%d: abort transaction %d gid='%s' is called from MtmEndTransaction" , MyProcPid , x -> xid , x -> gid );
920
922
MtmAbortTransaction (ts );
921
923
}
922
924
}
@@ -997,7 +999,7 @@ void MtmJoinTransaction(GlobalTransactionId* gtid, csn_t globalSnapshot)
997
999
998
1000
void MtmSetCurrentTransactionGID (char const * gid )
999
1001
{
1000
- MTM_LOG3 ("Set current transaction GID %s" , gid );
1002
+ MTM_LOG3 ("Set current transaction xid=%d GID %s" , MtmTx . xid , gid );
1001
1003
strcpy (MtmTx .gid , gid );
1002
1004
MtmTx .isDistributed = true;
1003
1005
MtmTx .isReplicated = true;
@@ -1382,15 +1384,21 @@ bool MtmRefreshClusterStatus(bool nowait)
1382
1384
MtmCheckQuorum ();
1383
1385
/* Interrupt voting for active transaction and abort them */
1384
1386
for (ts = Mtm -> transListHead ; ts != NULL ; ts = ts -> next ) {
1387
+ MTM_LOG3 ("Active transaction gid='%s', coordinator=%d, xid=%d, status=%d, gtid.xid=%d" ,
1388
+ ts -> gid , ts -> gtid .node , ts -> xid , ts -> status , ts -> gtid .xid );
1385
1389
if (MtmIsCoordinator (ts )) {
1386
1390
if (!ts -> votingCompleted && ts -> status != TRANSACTION_STATUS_ABORTED ) {
1387
1391
MtmAbortTransaction (ts );
1388
1392
MtmWakeUpBackend (ts );
1389
1393
}
1390
1394
} else if (TransactionIdIsValid (ts -> gtid .xid ) && BIT_CHECK (disabled , ts -> gtid .node - 1 )) { // coordinator of transaction is on disabled node
1391
- if (ts -> gid [0 ] && ts -> status != TRANSACTION_STATUS_ABORTED ) {
1392
- MtmAbortTransaction (ts );
1393
- FinishPreparedTransaction (ts -> gid , false);
1395
+ if (ts -> gid [0 ]) {
1396
+ if (ts -> status == TRANSACTION_STATUS_UNKNOWN || ts -> status == TRANSACTION_STATUS_IN_PROGRESS ) {
1397
+ MTM_LOG1 ("%d: Abort trasaction %s because its coordinator is at disabled node %d" , MyProcPid , ts -> gid , ts -> gtid .node );
1398
+ MtmAbortTransaction (ts );
1399
+ MtmTx .status = TRANSACTION_STATUS_ABORTED ; /* prevent recursive invocation of MtmAbortPreparedTransaction */
1400
+ FinishPreparedTransaction (ts -> gid , false);
1401
+ }
1394
1402
}
1395
1403
}
1396
1404
}
@@ -1460,6 +1468,7 @@ void MtmOnNodeDisconnect(int nodeId)
1460
1468
} else if (TransactionIdIsValid (ts -> gtid .xid ) && ts -> gtid .node == nodeId ) { //coordinator of transaction is on disabled node
1461
1469
if (ts -> gid [0 ] && ts -> status != TRANSACTION_STATUS_ABORTED ) {
1462
1470
MtmAbortTransaction (ts );
1471
+ MtmTx .status = TRANSACTION_STATUS_ABORTED ; /* prevent recursive invocation of MtmAbortPreparedTransaction */
1463
1472
FinishPreparedTransaction (ts -> gid , false);
1464
1473
}
1465
1474
}
0 commit comments