@@ -242,6 +242,7 @@ void MtmLock(LWLockMode mode)
242
242
#else
243
243
LWLockAcquire ((LWLockId )& Mtm -> locks [MTM_STATE_LOCK_ID ], mode );
244
244
#endif
245
+ Mtm -> lastLockHolder = MyProcPid ;
245
246
}
246
247
247
248
void MtmUnlock (void )
@@ -251,6 +252,7 @@ void MtmUnlock(void)
251
252
#else
252
253
LWLockRelease ((LWLockId )& Mtm -> locks [MTM_STATE_LOCK_ID ]);
253
254
#endif
255
+ Mtm -> lastLockHolder = 0 ;
254
256
}
255
257
256
258
void MtmLockNode (int nodeId )
@@ -549,16 +551,20 @@ MtmAdjustOldestXid(TransactionId xid)
549
551
550
552
static void MtmTransactionListAppend (MtmTransState * ts )
551
553
{
552
- ts -> next = NULL ;
553
- ts -> nSubxids = 0 ;
554
- * Mtm -> transListTail = ts ;
555
- Mtm -> transListTail = & ts -> next ;
554
+ if (!ts -> isEnqueued ) {
555
+ ts -> isEnqueued = true;
556
+ ts -> next = NULL ;
557
+ ts -> nSubxids = 0 ;
558
+ * Mtm -> transListTail = ts ;
559
+ Mtm -> transListTail = & ts -> next ;
560
+ }
556
561
}
557
562
558
563
static void MtmTransactionListInsertAfter (MtmTransState * after , MtmTransState * ts )
559
564
{
560
565
ts -> next = after -> next ;
561
566
after -> next = ts ;
567
+ ts -> isEnqueued = true;
562
568
if (Mtm -> transListTail == & after -> next ) {
563
569
Mtm -> transListTail = & ts -> next ;
564
570
}
@@ -699,6 +705,9 @@ MtmCreateTransState(MtmCurrentTrans* x)
699
705
ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
700
706
ts -> snapshot = x -> snapshot ;
701
707
ts -> isLocal = true;
708
+ if (!found ) {
709
+ ts -> isEnqueued = false;
710
+ }
702
711
if (TransactionIdIsValid (x -> gtid .xid )) {
703
712
Assert (x -> gtid .node != MtmNodeId );
704
713
ts -> gtid = x -> gtid ;
@@ -832,6 +841,9 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
832
841
Assert (x -> gid [0 ]);
833
842
tm -> state = ts ;
834
843
ts -> votingCompleted = true;
844
+ if (!found ) {
845
+ ts -> isEnqueued = false;
846
+ }
835
847
if (Mtm -> status != MTM_RECOVERY ) {
836
848
MtmSendNotificationMessage (ts , MSG_READY ); /* send notification to coordinator */
837
849
if (!MtmUseDtm ) {
@@ -944,8 +956,12 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
944
956
*/
945
957
MTM_LOG1 ("%d: send ABORT notification abort transaction %d to coordinator %d" , MyProcPid , x -> gtid .xid , x -> gtid .node );
946
958
if (ts == NULL ) {
959
+ bool found ;
947
960
Assert (TransactionIdIsValid (x -> xid ));
948
- ts = hash_search (MtmXid2State , & x -> xid , HASH_ENTER , NULL );
961
+ ts = hash_search (MtmXid2State , & x -> xid , HASH_ENTER , & found );
962
+ if (!found ) {
963
+ ts -> isEnqueued = false;
964
+ }
949
965
ts -> status = TRANSACTION_STATUS_ABORTED ;
950
966
ts -> isLocal = true;
951
967
ts -> snapshot = x -> snapshot ;
@@ -1363,7 +1379,7 @@ MtmBuildConnectivityMatrix(nodemask_t* matrix, bool nowait)
1363
1379
*/
1364
1380
bool MtmRefreshClusterStatus (bool nowait )
1365
1381
{
1366
- nodemask_t mask , clique , disabled , enabled ;
1382
+ nodemask_t mask , clique , disabled ;
1367
1383
nodemask_t matrix [MAX_NODES ];
1368
1384
MtmTransState * ts ;
1369
1385
int clique_size ;
@@ -1390,28 +1406,29 @@ bool MtmRefreshClusterStatus(bool nowait)
1390
1406
MTM_LOG1 ("Find clique %lx, disabledNodeMask %lx" , (long ) clique , (long ) Mtm -> disabledNodeMask );
1391
1407
MtmLock (LW_EXCLUSIVE );
1392
1408
disabled = ~clique & (((nodemask_t )1 << Mtm -> nAllNodes )- 1 ) & ~Mtm -> disabledNodeMask ; /* new disabled nodes mask */
1393
- enabled = clique & Mtm -> disabledNodeMask ; /* new enabled nodes mask */
1394
1409
1395
1410
for (i = 0 , mask = disabled ; mask != 0 ; i ++ , mask >>= 1 ) {
1396
1411
if (mask & 1 ) {
1397
1412
MtmDisableNode (i + 1 );
1398
1413
}
1399
- }
1400
-
1414
+ }
1415
+ #if 0 /* Do not enable nodes here: them will be enabled after completion of recovery */
1416
+ enabled = clique & Mtm -> disabledNodeMask ; /* new enabled nodes mask */
1401
1417
for (i = 0 , mask = enabled ; mask != 0 ; i ++ , mask >>= 1 ) {
1402
1418
if (mask & 1 ) {
1403
1419
MtmEnableNode (i + 1 );
1404
1420
}
1405
1421
}
1406
- if (disabled |enabled ) {
1422
+ #endif
1423
+ if (disabled ) {
1407
1424
MtmCheckQuorum ();
1408
1425
}
1409
1426
/* Interrupt voting for active transaction and abort them */
1410
1427
for (ts = Mtm -> transListHead ; ts != NULL ; ts = ts -> next ) {
1411
1428
MTM_LOG3 ("Active transaction gid='%s', coordinator=%d, xid=%d, status=%d, gtid.xid=%d" ,
1412
1429
ts -> gid , ts -> gtid .node , ts -> xid , ts -> status , ts -> gtid .xid );
1413
1430
if (MtmIsCoordinator (ts )) {
1414
- if (!ts -> votingCompleted && ( disabled | enabled ) != 0 && ts -> status != TRANSACTION_STATUS_ABORTED ) {
1431
+ if (!ts -> votingCompleted && disabled != 0 && ts -> status != TRANSACTION_STATUS_ABORTED ) {
1415
1432
MtmAbortTransaction (ts );
1416
1433
MtmWakeUpBackend (ts );
1417
1434
}
@@ -2221,6 +2238,7 @@ void MtmDropNode(int nodeId, bool dropSlot)
2221
2238
{
2222
2239
if (nodeId <= 0 || nodeId > Mtm -> nLiveNodes )
2223
2240
{
2241
+ MtmUnlock ();
2224
2242
elog (ERROR , "NodeID %d is out of range [1,%d]" , nodeId , Mtm -> nLiveNodes );
2225
2243
}
2226
2244
MtmDisableNode (nodeId );
@@ -2286,6 +2304,7 @@ MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
2286
2304
MtmEnableNode (MtmReplicationNodeId );
2287
2305
MtmCheckQuorum ();
2288
2306
} else {
2307
+ MtmUnlock ();
2289
2308
elog (ERROR , "Disabled node %d tries to reconnect without recovery" , MtmReplicationNodeId );
2290
2309
}
2291
2310
} else {
0 commit comments