@@ -538,7 +538,8 @@ MtmBeginTransaction(MtmCurrentTrans* x)
538
538
x -> gtid .xid = InvalidTransactionId ;
539
539
MtmUnlock ();
540
540
541
- MTM_TRACE ("MtmLocalTransaction: %s transaction %u uses local snapshot %lu\n" , x -> isDistributed ? "distributed" : "local" , x -> xid , x -> snapshot );
541
+ MTM_TRACE ("%d: MtmLocalTransaction: %s transaction %u uses local snapshot %lu\n" ,
542
+ MyProcPid , x -> isDistributed ? "distributed" : "local" , x -> xid , x -> snapshot );
542
543
}
543
544
}
544
545
@@ -583,7 +584,7 @@ MtmCheckClusterLock()
583
584
} else {
584
585
/* All lockers are synchronized their logs */
585
586
/* Remove lock and mark them as receovered */
586
- elog (WARNING , "Complete recovery of %d nodes (node mask %llx )" , dtm -> nLockers , dtm -> nodeLockerMask );
587
+ elog (WARNING , "Complete recovery of %d nodes (node mask %lx )" , dtm -> nLockers , dtm -> nodeLockerMask );
587
588
Assert (dtm -> walSenderLockerMask == 0 );
588
589
Assert ((dtm -> nodeLockerMask & dtm -> disabledNodeMask ) == dtm -> nodeLockerMask );
589
590
dtm -> disabledNodeMask &= ~dtm -> nodeLockerMask ;
@@ -606,7 +607,7 @@ static void MtmPrecommitTransaction(MtmCurrentTrans* x)
606
607
MtmTransState * ts ;
607
608
int i ;
608
609
609
- if (!x -> isDistributed ) {
610
+ if (!x -> isDistributed || x -> isPrepared ) {
610
611
return ;
611
612
}
612
613
@@ -657,6 +658,7 @@ static void
657
658
MtmPrepareTransaction (MtmCurrentTrans * x )
658
659
{
659
660
MtmPrecommitTransaction (x );
661
+ MTM_TRACE ("Prepare transaction %d" , x -> xid );
660
662
x -> isPrepared = true;
661
663
}
662
664
@@ -666,6 +668,7 @@ MtmCommitPreparedTransaction(MtmCurrentTrans* x)
666
668
TransactionId * subxids ;
667
669
int nSubxids ;
668
670
nSubxids = xactGetCommittedChildren (& subxids );
671
+ MTM_TRACE ("%d: Commit prepared transaction %d\n" , MyProcPid , x -> xid );
669
672
if (!MtmCommitTransaction (x -> xid , nSubxids , subxids ))
670
673
{
671
674
elog (ERROR , "Commit of transaction %d is rejected by DTM" , x -> xid );
@@ -718,8 +721,12 @@ static int64 MtmGetSlotLag(int nodeId)
718
721
static void
719
722
MtmEndTransaction (MtmCurrentTrans * x , bool commit )
720
723
{
721
- if (x -> isDistributed && commit ) {
724
+ MTM_TRACE ("%d: End transaction %d, prepared=%d, distributed=%d -> %s\n" , MyProcPid , x -> xid , x -> isPrepared , x -> isDistributed , commit ? "commit" : "abort" );
725
+ if (x -> isDistributed && commit ) {
722
726
MtmTransState * ts ;
727
+ if (x -> isPrepared ) {
728
+ return ;
729
+ }
723
730
MtmLock (LW_EXCLUSIVE );
724
731
ts = hash_search (xid2state , & x -> xid , HASH_FIND , NULL );
725
732
Assert (ts != NULL );
@@ -1541,8 +1548,13 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
1541
1548
switch (stmt -> kind )
1542
1549
{
1543
1550
case TRANS_STMT_COMMIT :
1544
- if (MtmUse2PC ) {
1551
+ if (MtmUse2PC && dtmTx . isDistributed && dtmTx . containsDML ) {
1545
1552
char * gid = MtmGenerateGid ();
1553
+ if (!IsTransactionBlock ()) {
1554
+ elog (WARNING , "Start transaction block for %d" , dtmTx .xid );
1555
+ CommitTransactionCommand ();
1556
+ StartTransactionCommand ();
1557
+ }
1546
1558
if (!PrepareTransactionBlock (gid ))
1547
1559
{
1548
1560
elog (WARNING , "Failed to prepare transaction %s" , gid );
@@ -1826,7 +1838,7 @@ void MtmRefreshClusterStatus(bool nowait)
1826
1838
1827
1839
clique = MtmFindMaxClique (matrix , MtmNodes , & clique_size );
1828
1840
if (clique_size >= MtmNodes /2 + 1 ) { /* have quorum */
1829
- elog (WARNING , "Find clique %llx , disabledNodeMask %llx " , clique , dtm -> disabledNodeMask );
1841
+ elog (WARNING , "Find clique %lx , disabledNodeMask %lx " , clique , dtm -> disabledNodeMask );
1830
1842
MtmLock (LW_EXCLUSIVE );
1831
1843
mask = ~clique & (((nodemask_t )1 << MtmNodes )- 1 ) & ~dtm -> disabledNodeMask ; /* new disabled nodes mask */
1832
1844
for (i = 0 ; mask != 0 ; i ++ , mask >>= 1 ) {
@@ -1853,7 +1865,7 @@ void MtmRefreshClusterStatus(bool nowait)
1853
1865
MtmSwitchClusterMode (MTM_RECOVERY );
1854
1866
}
1855
1867
} else {
1856
- elog (WARNING , "Clique %llx has no quorum" , clique );
1868
+ elog (WARNING , "Clique %lx has no quorum" , clique );
1857
1869
}
1858
1870
}
1859
1871
0 commit comments