@@ -643,33 +643,36 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
643
643
{
644
644
MTM_TRACE ("%d: End transaction %d, prepared=%d, distributed=%d -> %s\n" , MyProcPid , x -> xid , x -> isPrepared , x -> isDistributed , commit ? "commit" : "abort" );
645
645
if (x -> isDistributed && (x -> isPrepared || x -> isReplicated )) {
646
- MtmTransState * ts ;
646
+ MtmTransState * ts = NULL ;
647
647
MtmLock (LW_EXCLUSIVE );
648
648
if (x -> isPrepared ) {
649
649
ts = hash_search (xid2state , & x -> xid , HASH_FIND , NULL );
650
650
Assert (ts != NULL );
651
651
} else {
652
652
MtmTransMap * hm = (MtmTransMap * )hash_search (gid2xid , x -> gid , HASH_REMOVE , NULL );
653
- Assert (hm != NULL );
654
- ts = hm -> state ;
653
+ if (hm != NULL ) {
654
+ ts = hm -> state ;
655
+ }
655
656
}
656
- if (commit ) {
657
- ts -> status = TRANSACTION_STATUS_COMMITTED ;
658
- if (x -> csn > ts -> csn ) {
659
- ts -> csn = x -> csn ;
660
- MtmSyncClock (ts -> csn );
657
+ if (ts != NULL ) {
658
+ if (commit ) {
659
+ ts -> status = TRANSACTION_STATUS_COMMITTED ;
660
+ if (x -> csn > ts -> csn ) {
661
+ ts -> csn = x -> csn ;
662
+ MtmSyncClock (ts -> csn );
663
+ }
664
+ } else {
665
+ ts -> status = TRANSACTION_STATUS_ABORTED ;
666
+ if (x -> isReplicated && TransactionIdIsValid (x -> gtid .xid )) {
667
+ /*
668
+ * Send notification only of ABORT happens during transaction processing at replicas,
669
+ * do not send notification if ABORT is receiver from master
670
+ */
671
+ MtmSendNotificationMessage (ts ); /* send notification to coordinator */
672
+ }
661
673
}
662
- } else {
663
- ts -> status = TRANSACTION_STATUS_ABORTED ;
664
- if (x -> isReplicated && TransactionIdIsValid (x -> gtid .xid )) {
665
- /*
666
- * Send notification only of ABORT happens during transaction processing at replicas,
667
- * do not send notification if ABORT is receiver from master
668
- */
669
- MtmSendNotificationMessage (ts ); /* send notification to coordinator */
670
- }
674
+ MtmAdjustSubtransactions (ts );
671
675
}
672
- MtmAdjustSubtransactions (ts );
673
676
MtmUnlock ();
674
677
}
675
678
x -> snapshot = INVALID_CSN ;
@@ -1691,6 +1694,7 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
1691
1694
DestReceiver * dest , char * completionTag )
1692
1695
{
1693
1696
bool skipCommand ;
1697
+ MTM_TRACE ("%d: Process utility statement %s\n" , MyProcPid , queryString );
1694
1698
switch (nodeTag (parsetree ))
1695
1699
{
1696
1700
case T_TransactionStmt :
@@ -1702,8 +1706,10 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
1702
1706
if (dtmTx .isDistributed && dtmTx .containsDML ) {
1703
1707
char gid [MULTIMASTER_MAX_GID_SIZE ];
1704
1708
MtmGenerateGid (gid );
1709
+ MTM_TRACE ("%d: Start 2PC with GID=%s for %s\n" , MyProcPid , gid , queryString );
1705
1710
if (!IsTransactionBlock ()) {
1706
1711
elog (WARNING , "Start transaction block for %d" , dtmTx .xid );
1712
+ BeginTransactionBlock ();
1707
1713
CommitTransactionCommand ();
1708
1714
StartTransactionCommand ();
1709
1715
}
0 commit comments