@@ -637,7 +637,7 @@ MtmBeginTransaction(MtmCurrentTrans* x)
637637 x -> isPrepared = false;
638638 x -> isTransactionBlock = IsTransactionBlock ();
639639 /* Application name can be cahnged usnig PGAPPNAME environment variable */
640- if (x -> isDistributed && Mtm -> status != MTM_ONLINE && strcmp (application_name , MULTIMASTER_ADMIN ) != 0 ) {
640+ if (! IsBackgroundWorker && x -> isDistributed && Mtm -> status != MTM_ONLINE && strcmp (application_name , MULTIMASTER_ADMIN ) != 0 ) {
641641 /* reject all user's transactions at offline cluster */
642642 MtmUnlock ();
643643 elog (ERROR , "Multimaster node is not online: current status %s" , MtmNodeStatusMnem [Mtm -> status ]);
@@ -673,7 +673,7 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
673673
674674 if (Mtm -> disabledNodeMask != 0 ) {
675675 MtmRefreshClusterStatus (true);
676- if (Mtm -> status != MTM_ONLINE ) {
676+ if (! IsBackgroundWorker && Mtm -> status != MTM_ONLINE ) {
677677 elog (ERROR , "Abort current transaction because this cluster node is not online" );
678678 }
679679 }
@@ -683,7 +683,9 @@ MtmPrePrepareTransaction(MtmCurrentTrans* x)
683683 /*
684684 * Check if there is global multimaster lock preventing new transaction from commit to make a chance to wal-senders to catch-up
685685 */
686- MtmCheckClusterLock ();
686+ if (!x -> isReplicated ) {
687+ MtmCheckClusterLock ();
688+ }
687689
688690 ts = hash_search (MtmXid2State , & x -> xid , HASH_ENTER , NULL );
689691 ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
@@ -998,16 +1000,15 @@ bool MtmRecoveryCaughtUp(int nodeId, XLogRecPtr slotLSN)
9981000 if (slotLSN == walLSN ) {
9991001 if (BIT_CHECK (Mtm -> nodeLockerMask , nodeId - 1 )) {
10001002 elog (WARNING ,"Node %d is caught-up" , nodeId );
1001- BIT_CLEAR (Mtm -> disabledNodeMask , nodeId - 1 );
10021003 BIT_CLEAR (Mtm -> walSenderLockerMask , MyWalSnd - WalSndCtl -> walsnds );
10031004 BIT_CLEAR (Mtm -> nodeLockerMask , nodeId - 1 );
10041005 Mtm -> nLockers -= 1 ;
10051006 } else {
10061007 elog (WARNING ,"Node %d is caugth-up without locking cluster" , nodeId );
10071008 /* We are lucky: caugth-up without locking cluster! */
1008- Mtm -> nNodes += 1 ;
1009- BIT_CLEAR (Mtm -> disabledNodeMask , nodeId - 1 );
10101009 }
1010+ BIT_CLEAR (Mtm -> disabledNodeMask , nodeId - 1 );
1011+ Mtm -> nNodes += 1 ;
10111012 caughtUp = true;
10121013 } else if (!BIT_CHECK (Mtm -> nodeLockerMask , nodeId - 1 )
10131014 && slotLSN + MtmMinRecoveryLag > walLSN )
@@ -2250,7 +2251,12 @@ MtmExecutorFinish(QueryDesc *queryDesc)
22502251
22512252void MtmExecute (void * work , int size )
22522253{
2253- BgwPoolExecute (& Mtm -> pool , work , size );
2254+ if (Mtm -> status == MTM_RECOVERY ) {
2255+ /* During recovery apply changes sequentially to preserve commit order */
2256+ MtmExecutor (0 , work , size );
2257+ } else {
2258+ BgwPoolExecute (& Mtm -> pool , work , size );
2259+ }
22542260}
22552261
22562262static BgwPool *
0 commit comments