@@ -695,20 +695,18 @@ MtmCreateTransState(MtmCurrentTrans* x)
695695{
696696 bool found ;
697697 MtmTransState * ts = hash_search (MtmXid2State , & x -> xid , HASH_ENTER , & found );
698- if (!found ) {
699- ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
700- ts -> snapshot = x -> snapshot ;
701- ts -> isLocal = true;
702- if (TransactionIdIsValid (x -> gtid .xid )) {
703- Assert (x -> gtid .node != MtmNodeId );
704- ts -> gtid = x -> gtid ;
705- strcpy (ts -> gid , x -> gid );
706- } else {
707- /* I am coordinator of transaction */
708- ts -> gtid .xid = x -> xid ;
709- ts -> gtid .node = MtmNodeId ;
710- ts -> gid [0 ] = '\0' ;
711- }
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' ;
712710 }
713711 return ts ;
714712}
@@ -854,11 +852,11 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
854852 if (!ts -> votingCompleted ) {
855853 if (ts -> status != TRANSACTION_STATUS_ABORTED ) {
856854 MtmAbortTransaction (ts );
857- 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 ));
855+ 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 ));
858856 }
859857 } else if (nConfigChanges != Mtm -> nConfigChanges ) {
860858 MtmAbortTransaction (ts );
861- elog (WARNING , "Transaction is aborted because cluster configuration is changed during commit" );
859+ elog (WARNING , "Transaction %d is aborted because cluster configuration is changed during commit" , x -> xid );
862860 }
863861 x -> status = ts -> status ;
864862 MTM_LOG3 ("%d: Result of vote: %d" , MyProcPid , ts -> status );
@@ -880,9 +878,12 @@ MtmAbortPreparedTransaction(MtmCurrentTrans* x)
880878 MtmLock (LW_EXCLUSIVE );
881879 tm = (MtmTransMap * )hash_search (MtmGid2State , x -> gid , HASH_REMOVE , NULL );
882880 Assert (tm != NULL );
881+ MTM_LOG1 ("Abort prepared transaction %d with gid='%s' is already aborted" , x -> xid , x -> gid );
883882 MtmAbortTransaction (tm -> state );
884883 MtmUnlock ();
885884 x -> status = TRANSACTION_STATUS_ABORTED ;
885+ } else {
886+ MTM_LOG1 ("Transaction %d with gid='%s' is already aborted" , x -> xid , x -> gid );
886887 }
887888}
888889
@@ -918,6 +919,7 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
918919 Assert (Mtm -> nActiveTransactions != 0 );
919920 Mtm -> nActiveTransactions -= 1 ;
920921 } else {
922+ MTM_LOG1 ("%d: abort transaction %d gid='%s' is called from MtmEndTransaction" , MyProcPid , x -> xid , x -> gid );
921923 MtmAbortTransaction (ts );
922924 }
923925 }
@@ -998,7 +1000,7 @@ void MtmJoinTransaction(GlobalTransactionId* gtid, csn_t globalSnapshot)
9981000
9991001void MtmSetCurrentTransactionGID (char const * gid )
10001002{
1001- MTM_LOG3 ("Set current transaction GID %s" , gid );
1003+ MTM_LOG3 ("Set current transaction xid=%d GID %s" , MtmTx . xid , gid );
10021004 strcpy (MtmTx .gid , gid );
10031005 MtmTx .isDistributed = true;
10041006 MtmTx .isReplicated = true;
@@ -1383,15 +1385,21 @@ bool MtmRefreshClusterStatus(bool nowait)
13831385 MtmCheckQuorum ();
13841386 /* Interrupt voting for active transaction and abort them */
13851387 for (ts = Mtm -> transListHead ; ts != NULL ; ts = ts -> next ) {
1388+ MTM_LOG3 ("Active transaction gid='%s', coordinator=%d, xid=%d, status=%d, gtid.xid=%d" ,
1389+ ts -> gid , ts -> gtid .node , ts -> xid , ts -> status , ts -> gtid .xid );
13861390 if (MtmIsCoordinator (ts )) {
13871391 if (!ts -> votingCompleted && ts -> status != TRANSACTION_STATUS_ABORTED ) {
13881392 MtmAbortTransaction (ts );
13891393 MtmWakeUpBackend (ts );
13901394 }
13911395 } else if (TransactionIdIsValid (ts -> gtid .xid ) && BIT_CHECK (disabled , ts -> gtid .node - 1 )) { // coordinator of transaction is on disabled node
1392- if (ts -> gid [0 ] && ts -> status != TRANSACTION_STATUS_ABORTED ) {
1393- MtmAbortTransaction (ts );
1394- FinishPreparedTransaction (ts -> gid , false);
1396+ if (ts -> gid [0 ]) {
1397+ if (ts -> status == TRANSACTION_STATUS_UNKNOWN || ts -> status == TRANSACTION_STATUS_IN_PROGRESS ) {
1398+ MTM_LOG1 ("%d: Abort trasaction %s because its coordinator is at disabled node %d" , MyProcPid , ts -> gid , ts -> gtid .node );
1399+ MtmAbortTransaction (ts );
1400+ MtmTx .status = TRANSACTION_STATUS_ABORTED ; /* prevent recursive invocation of MtmAbortPreparedTransaction */
1401+ FinishPreparedTransaction (ts -> gid , false);
1402+ }
13951403 }
13961404 }
13971405 }
@@ -1461,6 +1469,7 @@ void MtmOnNodeDisconnect(int nodeId)
14611469 } else if (TransactionIdIsValid (ts -> gtid .xid ) && ts -> gtid .node == nodeId ) { //coordinator of transaction is on disabled node
14621470 if (ts -> gid [0 ] && ts -> status != TRANSACTION_STATUS_ABORTED ) {
14631471 MtmAbortTransaction (ts );
1472+ MtmTx .status = TRANSACTION_STATUS_ABORTED ; /* prevent recursive invocation of MtmAbortPreparedTransaction */
14641473 FinishPreparedTransaction (ts -> gid , false);
14651474 }
14661475 }
0 commit comments