@@ -110,6 +110,7 @@ static void MtmXactCallback(XactEvent event, void *arg);
110
110
static void MtmBeginTransaction (MtmCurrentTrans * x );
111
111
static void MtmPrePrepareTransaction (MtmCurrentTrans * x );
112
112
static void MtmPostPrepareTransaction (MtmCurrentTrans * x );
113
+ static void MtmAbortPreparedTransaction (MtmCurrentTrans * x );
113
114
static void MtmEndTransaction (MtmCurrentTrans * x , bool commit );
114
115
static TransactionId MtmGetOldestXmin (Relation rel , bool ignoreVacuum );
115
116
static bool MtmXidInMVCCSnapshot (TransactionId xid , Snapshot snapshot );
@@ -496,6 +497,9 @@ MtmXactCallback(XactEvent event, void *arg)
496
497
case XACT_EVENT_POST_PREPARE :
497
498
MtmPostPrepareTransaction (& dtmTx );
498
499
break ;
500
+ case XACT_EVENT_ABORT_PREPARED :
501
+ MtmAbortPreparedTransaction (& dtmTx );
502
+ break ;
499
503
case XACT_EVENT_COMMIT :
500
504
MtmEndTransaction (& dtmTx , true);
501
505
break ;
@@ -522,6 +526,7 @@ MtmResetTransaction(MtmCurrentTrans* x)
522
526
x -> snapshot = INVALID_CSN ;
523
527
x -> xid = InvalidTransactionId ;
524
528
x -> gtid .xid = InvalidTransactionId ;
529
+ x -> isDistributed = false;
525
530
}
526
531
527
532
static void
@@ -620,14 +625,16 @@ static void
620
625
MtmPostPrepareTransaction (MtmCurrentTrans * x )
621
626
{
622
627
MtmTransState * ts ;
628
+ MtmTransMap * tm ;
623
629
624
630
MtmLock (LW_EXCLUSIVE );
625
631
ts = hash_search (MtmXid2State , & x -> xid , HASH_FIND , NULL );
626
632
Assert (ts != NULL );
633
+ tm = (MtmTransMap * )hash_search (MtmGid2State , x -> gid , HASH_ENTER , NULL );
634
+ Assert (x -> gid [0 ]);
635
+ tm -> state = ts ;
636
+
627
637
if (!MtmIsCoordinator (ts )) {
628
- MtmTransMap * tm = (MtmTransMap * )hash_search (MtmGid2State , x -> gid , HASH_ENTER , NULL );
629
- Assert (x -> gid [0 ]);
630
- tm -> state = ts ;
631
638
MtmSendNotificationMessage (ts , MSG_READY ); /* send notification to coordinator */
632
639
MtmUnlock ();
633
640
MtmResetTransaction (x );
@@ -646,6 +653,20 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
646
653
}
647
654
648
655
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
+
649
670
static void
650
671
MtmEndTransaction (MtmCurrentTrans * x , bool commit )
651
672
{
@@ -695,9 +716,7 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
695
716
}
696
717
MtmUnlock ();
697
718
}
698
- x -> snapshot = INVALID_CSN ;
699
- x -> xid = InvalidTransactionId ;
700
- x -> gtid .xid = InvalidTransactionId ;
719
+ MtmResetTransaction (x );
701
720
MtmCheckSlots ();
702
721
}
703
722
@@ -1735,17 +1754,16 @@ MtmGenerateGid(char* gid)
1735
1754
1736
1755
static void MtmTwoPhaseCommit (char * completionTag )
1737
1756
{
1738
- char gid [MULTIMASTER_MAX_GID_SIZE ];
1739
- MtmGenerateGid (gid );
1757
+ MtmGenerateGid (dtmTx .gid );
1740
1758
if (!IsTransactionBlock ()) {
1741
1759
elog (WARNING , "Start transaction block for %d" , dtmTx .xid );
1742
1760
BeginTransactionBlock ();
1743
1761
CommitTransactionCommand ();
1744
1762
StartTransactionCommand ();
1745
1763
}
1746
- if (!PrepareTransactionBlock (gid ))
1764
+ if (!PrepareTransactionBlock (dtmTx . gid ))
1747
1765
{
1748
- elog (WARNING , "Failed to prepare transaction %s" , gid );
1766
+ elog (WARNING , "Failed to prepare transaction %s" , dtmTx . gid );
1749
1767
/* report unsuccessful commit in completionTag */
1750
1768
if (completionTag ) {
1751
1769
strcpy (completionTag , "ROLLBACK" );
@@ -1755,10 +1773,10 @@ static void MtmTwoPhaseCommit(char *completionTag)
1755
1773
CommitTransactionCommand ();
1756
1774
StartTransactionCommand ();
1757
1775
if (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 );
1760
1778
} else {
1761
- FinishPreparedTransaction (gid , true);
1779
+ FinishPreparedTransaction (dtmTx . gid , true);
1762
1780
}
1763
1781
}
1764
1782
}
0 commit comments