@@ -583,7 +583,9 @@ MtmAdjustOldestXid(TransactionId xid)
583
583
584
584
for (ts = Mtm -> transListHead ;
585
585
ts != NULL
586
+ && (ts -> status == TRANSACTION_STATUS_ABORTED || ts -> status == TRANSACTION_STATUS_COMMITTED )
586
587
&& ts -> csn < oldestSnapshot
588
+ && !ts -> isPinned
587
589
&& TransactionIdPrecedes (ts -> xid , xid );
588
590
prev = ts , ts = ts -> next )
589
591
{
@@ -653,6 +655,7 @@ static void MtmAddSubtransactions(MtmTransState* ts, TransactionId* subxids, int
653
655
sts = (MtmTransState * )hash_search (MtmXid2State , & subxids [i ], HASH_ENTER , & found );
654
656
Assert (!found );
655
657
sts -> isActive = false;
658
+ sts -> isPinned = false;
656
659
sts -> status = ts -> status ;
657
660
sts -> csn = ts -> csn ;
658
661
sts -> votingCompleted = true;
@@ -814,6 +817,7 @@ MtmCreateTransState(MtmCurrentTrans* x)
814
817
ts -> isLocal = true;
815
818
ts -> isPrepared = false;
816
819
ts -> isTwoPhase = x -> isTwoPhase ;
820
+ ts -> isPinned = false;
817
821
ts -> votingCompleted = false;
818
822
if (!found ) {
819
823
ts -> isEnqueued = false;
@@ -963,8 +967,13 @@ Mtm2PCVoting(MtmCurrentTrans* x, MtmTransState* ts)
963
967
{
964
968
int result = 0 ;
965
969
int nConfigChanges = Mtm -> nConfigChanges ;
966
- timestamp_t elapsed , start = MtmGetSystemTime ();
967
- timestamp_t deadline = 0 ;
970
+ timestamp_t prepareTime = ts -> csn - ts -> snapshot ;
971
+ timestamp_t timeout = Max (prepareTime + MSEC_TO_USEC (MtmMin2PCTimeout ), prepareTime * MtmMax2PCRatio /100 );
972
+ timestamp_t deadline = MtmGetSystemTime () + timeout ;
973
+ timestamp_t now ;
974
+
975
+ Assert (ts -> csn > ts -> snapshot );
976
+
968
977
/* Wait votes from all nodes until: */
969
978
while (!MtmVotingCompleted (ts )
970
979
&& (ts -> isPrepared || nConfigChanges == Mtm -> nConfigChanges ))
@@ -980,19 +989,16 @@ Mtm2PCVoting(MtmCurrentTrans* x, MtmTransState* ts)
980
989
if (result & WL_LATCH_SET ) {
981
990
ResetLatch (& MyProc -> procLatch );
982
991
}
983
- elapsed = MtmGetSystemTime () - start ;
992
+ now = MtmGetSystemTime ();
984
993
MtmLock (LW_EXCLUSIVE );
985
- if (deadline == 0 && ts -> votedMask != 0 ) {
986
- deadline = Max (MSEC_TO_USEC (MtmMin2PCTimeout ), elapsed * MtmMax2PCRatio /100 );
987
- } else {
994
+ if (now > deadline ) {
988
995
if (ts -> isPrepared ) {
989
996
/* resend precommit message */
990
997
MtmSend2PCMessage (ts , MSG_PRECOMMIT );
991
998
} else {
992
- if (elapsed > deadline ) {
993
- elog (WARNING , "Commit of distributed transaction is canceled because of %ld msec timeout expiration" , USEC_TO_MSEC (elapsed ));
994
- MtmAbortTransaction (ts );
995
- }
999
+ elog (WARNING , "Commit of distributed transaction is canceled because of %ld msec timeout expiration" , USEC_TO_MSEC (timeout ));
1000
+ MtmAbortTransaction (ts );
1001
+ break ;
996
1002
}
997
1003
}
998
1004
}
@@ -1005,7 +1011,7 @@ Mtm2PCVoting(MtmCurrentTrans* x, MtmTransState* ts)
1005
1011
} else {
1006
1012
if (Mtm -> status != MTM_ONLINE ) {
1007
1013
elog (WARNING , "Commit of distributed transaction is canceled because node is switched to %s mode" , MtmNodeStatusMnem [Mtm -> status ]);
1008
- } else if ( nConfigChanges != Mtm -> nConfigChanges ) {
1014
+ } else {
1009
1015
elog (WARNING , "Commit of distributed transaction is canceled because cluster configuration was changed" );
1010
1016
}
1011
1017
MtmAbortTransaction (ts );
@@ -1202,6 +1208,7 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
1202
1208
ts -> status = TRANSACTION_STATUS_ABORTED ;
1203
1209
ts -> isLocal = true;
1204
1210
ts -> isPrepared = false;
1211
+ ts -> isPinned = false;
1205
1212
ts -> snapshot = x -> snapshot ;
1206
1213
ts -> isTwoPhase = x -> isTwoPhase ;
1207
1214
ts -> csn = MtmAssignCSN ();
@@ -1280,7 +1287,7 @@ void MtmSend2PCMessage(MtmTransState* ts, MtmMessageCode cmd)
1280
1287
}
1281
1288
}
1282
1289
1283
- void MtmBroadcastPollMessage (MtmTransState * ts )
1290
+ static void MtmBroadcastPollMessage (MtmTransState * ts )
1284
1291
{
1285
1292
int i ;
1286
1293
MtmArbiterMessage msg ;
@@ -1293,7 +1300,7 @@ void MtmBroadcastPollMessage(MtmTransState* ts)
1293
1300
1294
1301
for (i = 0 ; i < Mtm -> nAllNodes ; i ++ )
1295
1302
{
1296
- if (BIT_CHECK (ts -> participantsMask & ~Mtm -> disabledNodeMask & ~ ts -> votedMask , i ))
1303
+ if (BIT_CHECK (ts -> participantsMask & ~Mtm -> disabledNodeMask , i ))
1297
1304
{
1298
1305
msg .node = i + 1 ;
1299
1306
MTM_LOG3 ("Send request for transaction %s to node %d" , msg .gid , msg .node );
@@ -1480,15 +1487,17 @@ static void MtmPollStatusOfPreparedTransactions(int disabledNodeId)
1480
1487
Assert (ts -> gid [0 ]);
1481
1488
if (ts -> status == TRANSACTION_STATUS_IN_PROGRESS ) {
1482
1489
elog (LOG , "Abort transaction %s because its coordinator is disabled and it is not prepared at node %d" , ts -> gid , MtmNodeId );
1483
- //MtmUnlock();
1490
+ ts -> isPinned = true;
1491
+ MtmUnlock ();
1484
1492
MtmFinishPreparedTransaction (ts , false);
1485
- //MtmLock(LW_EXCLUSIVE);
1493
+ MtmLock (LW_EXCLUSIVE );
1494
+ ts -> isPinned = false;
1486
1495
} else {
1487
1496
MTM_LOG1 ("Poll state of transaction %d (%s)" , ts -> xid , ts -> gid );
1488
1497
MtmBroadcastPollMessage (ts );
1489
1498
}
1490
1499
} else {
1491
- MTM_LOG2 ("Skip transaction %d (%s) with status %d gtid.node=%d gtid.xid=%d votedMask=%lx" ,
1500
+ MTM_LOG1 ("Skip transaction %d (%s) with status %d gtid.node=%d gtid.xid=%d votedMask=%lx" ,
1492
1501
ts -> xid , ts -> gid , ts -> status , ts -> gtid .node , ts -> gtid .xid , ts -> votedMask );
1493
1502
}
1494
1503
}
@@ -3216,8 +3225,13 @@ bool MtmFilterTransaction(char* record, int size)
3216
3225
duplicate = true;
3217
3226
}
3218
3227
3219
- MTM_LOG2 ("%s transaction %s from node %d lsn %lx, flags=%x, origin node %d, original lsn=%lx, current lsn=%lx" ,
3220
- duplicate ? "Ignore" : "Apply" , gid , replication_node , end_lsn , flags , origin_node , origin_lsn , restart_lsn );
3228
+ if (duplicate ) {
3229
+ MTM_LOG1 ("Ignore transaction %s from node %d lsn %lx, flags=%x, origin node %d, original lsn=%lx, current lsn=%lx" ,
3230
+ gid , replication_node , end_lsn , flags , origin_node , origin_lsn , restart_lsn );
3231
+ } else {
3232
+ MTM_LOG2 ("Apply transaction %s from node %d lsn %lx, flags=%x, origin node %d, original lsn=%lx, current lsn=%lx" ,
3233
+ gid , replication_node , end_lsn , flags , origin_node , origin_lsn , restart_lsn );
3234
+ }
3221
3235
return duplicate ;
3222
3236
}
3223
3237
@@ -3831,7 +3845,7 @@ static bool MtmTwoPhaseCommit(MtmCurrentTrans* x)
3831
3845
} else {
3832
3846
CommitTransactionCommand ();
3833
3847
if (x -> isSuspended ) {
3834
- elog (WARNING , "Transaction %s is left in prepared state because coordinator onde is not online" , x -> gid );
3848
+ elog (WARNING , "Transaction %s is left in prepared state because coordinator node is not online" , x -> gid );
3835
3849
} else {
3836
3850
StartTransactionCommand ();
3837
3851
if (x -> status == TRANSACTION_STATUS_ABORTED ) {
0 commit comments