@@ -245,6 +245,7 @@ static int MtmMaxRecoveryLag;
245
245
static int MtmGcPeriod ;
246
246
static bool MtmIgnoreTablesWithoutPk ;
247
247
static int MtmLockCount ;
248
+ static int MtmSenderStarted ;
248
249
249
250
static ExecutorStart_hook_type PreviousExecutorStartHook ;
250
251
static ExecutorFinish_hook_type PreviousExecutorFinishHook ;
@@ -1667,8 +1668,8 @@ void MtmRecoveryCompleted(void)
1667
1668
Mtm -> nodes [i ].lastHeartbeat = 0 ; /* defuse watchdog until first heartbeat is received */
1668
1669
}
1669
1670
/* Mode will be changed to online once all logical receiver are connected */
1670
- elog (LOG , "Recovery completed with %d active receivers from %d" , Mtm -> nReceivers , Mtm -> nLiveNodes - 1 );
1671
- MtmSwitchClusterMode (Mtm -> nReceivers == Mtm -> nLiveNodes - 1 ? MTM_ONLINE : MTM_CONNECTED );
1671
+ elog (LOG , "Recovery completed with %d active receivers and %d started senders from %d" , Mtm -> nReceivers , Mtm -> nSenders , Mtm -> nLiveNodes - 1 );
1672
+ MtmSwitchClusterMode (Mtm -> nReceivers == Mtm -> nLiveNodes - 1 && Mtm -> nSenders == Mtm -> nLiveNodes - 1 ? MTM_ONLINE : MTM_CONNECTED );
1672
1673
MtmUnlock ();
1673
1674
}
1674
1675
@@ -2198,6 +2199,7 @@ static void MtmInitialize()
2198
2199
Mtm -> transListHead = NULL ;
2199
2200
Mtm -> transListTail = & Mtm -> transListHead ;
2200
2201
Mtm -> nReceivers = 0 ;
2202
+ Mtm -> nSenders = 0 ;
2201
2203
Mtm -> timeShift = 0 ;
2202
2204
Mtm -> transCount = 0 ;
2203
2205
Mtm -> gcCount = 0 ;
@@ -2906,11 +2908,9 @@ void MtmReceiverStarted(int nodeId)
2906
2908
MtmEnableNode (nodeId );
2907
2909
MtmCheckQuorum ();
2908
2910
}
2909
- elog (LOG , "Start %d receivers from %d cluster status %s" , Mtm -> nReceivers + 1 , Mtm -> nLiveNodes - 1 , MtmNodeStatusMnem [Mtm -> status ]);
2910
- if (++ Mtm -> nReceivers == Mtm -> nLiveNodes - 1 ) {
2911
- if (Mtm -> status == MTM_CONNECTED ) {
2912
- MtmSwitchClusterMode (MTM_ONLINE );
2913
- }
2911
+ elog (LOG , "Start %d receivers and %d senders from %d cluster status %s" , Mtm -> nReceivers + 1 , Mtm -> nSenders , Mtm -> nLiveNodes - 1 , MtmNodeStatusMnem [Mtm -> status ]);
2912
+ if (++ Mtm -> nReceivers == Mtm -> nLiveNodes - 1 && Mtm -> nSenders == Mtm -> nLiveNodes - 1 && Mtm -> status == MTM_CONNECTED ) {
2913
+ MtmSwitchClusterMode (MTM_ONLINE );
2914
2914
}
2915
2915
}
2916
2916
MtmUnlock ();
@@ -2997,6 +2997,7 @@ MtmReplicationMode MtmGetReplicationMode(int nodeId, sig_atomic_t volatile* shut
2997
2997
elog (WARNING , "Process %d starts recovery from node %d" , MyProcPid , nodeId );
2998
2998
Mtm -> recoverySlot = nodeId ;
2999
2999
Mtm -> nReceivers = 0 ;
3000
+ Mtm -> nSenders = 0 ;
3000
3001
Mtm -> recoveryCount += 1 ;
3001
3002
Mtm -> pglogicalNodeMask = 0 ;
3002
3003
MtmUnlock ();
@@ -3076,6 +3077,18 @@ MtmOnProcExit(int code, Datum arg)
3076
3077
}
3077
3078
}
3078
3079
3080
+ static void
3081
+ MtmReplicationStartedHook (struct PGLogicalStartedHookArgs * args )
3082
+ {
3083
+ MtmLock (LW_EXCLUSIVE );
3084
+ MtmSenderStarted = 1 ;
3085
+ if (++ Mtm -> nSenders == Mtm -> nLiveNodes - 1 && Mtm -> nReceivers == Mtm -> nLiveNodes - 1 && Mtm -> status == MTM_CONNECTED ) {
3086
+ MtmSwitchClusterMode (MTM_ONLINE );
3087
+ }
3088
+ MtmUnlock ();
3089
+ }
3090
+
3091
+
3079
3092
static void
3080
3093
MtmReplicationStartupHook (struct PGLogicalStartupHookArgs * args )
3081
3094
{
@@ -3192,6 +3205,9 @@ static void
3192
3205
MtmReplicationShutdownHook (struct PGLogicalShutdownHookArgs * args )
3193
3206
{
3194
3207
if (MtmReplicationNodeId >= 0 ) {
3208
+ MtmLock (LW_EXCLUSIVE );
3209
+ Mtm -> nSenders -= MtmSenderStarted ;
3210
+ MtmUnlock ();
3195
3211
MTM_LOG1 ("Logical replication to node %d is stopped" , MtmReplicationNodeId );
3196
3212
/* MtmOnNodeDisconnect(MtmReplicationNodeId); */
3197
3213
MtmReplicationNodeId = -1 ; /* defuse on_proc_exit hook */
@@ -3303,6 +3319,7 @@ bool MtmFilterTransaction(char* record, int size)
3303
3319
void MtmSetupReplicationHooks (struct PGLogicalHooks * hooks )
3304
3320
{
3305
3321
hooks -> startup_hook = MtmReplicationStartupHook ;
3322
+ hooks -> started_hook = MtmReplicationStartedHook ;
3306
3323
hooks -> shutdown_hook = MtmReplicationShutdownHook ;
3307
3324
hooks -> txn_filter_hook = MtmReplicationTxnFilterHook ;
3308
3325
hooks -> row_filter_hook = MtmReplicationRowFilterHook ;
0 commit comments