@@ -110,6 +110,7 @@ static void MtmXactCallback(XactEvent event, void *arg);
110110static void MtmBeginTransaction (MtmCurrentTrans * x );
111111static void MtmPrePrepareTransaction (MtmCurrentTrans * x );
112112static void MtmPostPrepareTransaction (MtmCurrentTrans * x );
113+ static void MtmAbortPreparedTransaction (MtmCurrentTrans * x );
113114static void MtmEndTransaction (MtmCurrentTrans * x ,bool commit );
114115static TransactionId MtmGetOldestXmin (Relation rel ,bool ignoreVacuum );
115116static bool MtmXidInMVCCSnapshot (TransactionId xid ,Snapshot snapshot );
@@ -496,6 +497,9 @@ MtmXactCallback(XactEvent event, void *arg)
496497case XACT_EVENT_POST_PREPARE :
497498MtmPostPrepareTransaction (& dtmTx );
498499break ;
500+ case XACT_EVENT_ABORT_PREPARED :
501+ MtmAbortPreparedTransaction (& dtmTx );
502+ break ;
499503case XACT_EVENT_COMMIT :
500504MtmEndTransaction (& dtmTx , true);
501505break ;
@@ -522,6 +526,7 @@ MtmResetTransaction(MtmCurrentTrans* x)
522526x -> snapshot = INVALID_CSN ;
523527x -> xid = InvalidTransactionId ;
524528x -> gtid .xid = InvalidTransactionId ;
529+ x -> isDistributed = false;
525530}
526531
527532static void
@@ -620,14 +625,16 @@ static void
620625MtmPostPrepareTransaction (MtmCurrentTrans * x )
621626{
622627MtmTransState * ts ;
628+ MtmTransMap * tm ;
623629
624630MtmLock (LW_EXCLUSIVE );
625631ts = hash_search (MtmXid2State ,& x -> xid ,HASH_FIND ,NULL );
626632Assert (ts != NULL );
633+ tm = (MtmTransMap * )hash_search (MtmGid2State ,x -> gid ,HASH_ENTER ,NULL );
634+ Assert (x -> gid [0 ]);
635+ tm -> state = ts ;
636+
627637if (!MtmIsCoordinator (ts )) {
628- MtmTransMap * tm = (MtmTransMap * )hash_search (MtmGid2State ,x -> gid ,HASH_ENTER ,NULL );
629- Assert (x -> gid [0 ]);
630- tm -> state = ts ;
631638MtmSendNotificationMessage (ts ,MSG_READY );/* send notification to coordinator */
632639MtmUnlock ();
633640MtmResetTransaction (x );
@@ -646,6 +653,20 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
646653}
647654
648655
656+ static void
657+ MtmAbortPreparedTransaction (MtmCurrentTrans * x )
658+ {
659+ MtmTransMap * tm ;
660+
661+ MtmLock (LW_EXCLUSIVE );
662+ tm = (MtmTransMap * )hash_search (MtmGid2State ,x -> gid ,HASH_REMOVE ,NULL );
663+ Assert (tm != NULL );
664+ tm -> state -> status = TRANSACTION_STATUS_ABORTED ;
665+ MtmAdjustSubtransactions (tm -> state );
666+ MtmUnlock ();
667+ MtmResetTransaction (x );
668+ }
669+
649670static void
650671MtmEndTransaction (MtmCurrentTrans * x ,bool commit )
651672{
@@ -695,9 +716,7 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
695716}
696717MtmUnlock ();
697718}
698- x -> snapshot = INVALID_CSN ;
699- x -> xid = InvalidTransactionId ;
700- x -> gtid .xid = InvalidTransactionId ;
719+ MtmResetTransaction (x );
701720MtmCheckSlots ();
702721}
703722
@@ -1735,17 +1754,16 @@ MtmGenerateGid(char* gid)
17351754
17361755static void MtmTwoPhaseCommit (char * completionTag )
17371756{
1738- char gid [MULTIMASTER_MAX_GID_SIZE ];
1739- MtmGenerateGid (gid );
1757+ MtmGenerateGid (dtmTx .gid );
17401758if (!IsTransactionBlock ()) {
17411759elog (WARNING ,"Start transaction block for %d" ,dtmTx .xid );
17421760BeginTransactionBlock ();
17431761CommitTransactionCommand ();
17441762StartTransactionCommand ();
17451763}
1746- if (!PrepareTransactionBlock (gid ))
1764+ if (!PrepareTransactionBlock (dtmTx . gid ))
17471765{
1748- elog (WARNING ,"Failed to prepare transaction %s" ,gid );
1766+ elog (WARNING ,"Failed to prepare transaction %s" ,dtmTx . gid );
17491767/* report unsuccessful commit in completionTag */
17501768if (completionTag ) {
17511769strcpy (completionTag ,"ROLLBACK" );
@@ -1755,10 +1773,10 @@ static void MtmTwoPhaseCommit(char *completionTag)
17551773CommitTransactionCommand ();
17561774StartTransactionCommand ();
17571775if (MtmGetCurrentTransactionStatus ()== TRANSACTION_STATUS_ABORTED ) {
1758- FinishPreparedTransaction (gid , false);
1759- elog (ERROR ,"Transaction %s is aborted by DTM" ,gid );
1776+ FinishPreparedTransaction (dtmTx . gid , false);
1777+ elog (ERROR ,"Transaction %s is aborted by DTM" ,dtmTx . gid );
17601778}else {
1761- FinishPreparedTransaction (gid , true);
1779+ FinishPreparedTransaction (dtmTx . gid , true);
17621780}
17631781}
17641782}