Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dc3e86c

Browse files
knizhnikkelvich
authored andcommitted
Avoid hanging on exit in pglogical_receiver
1 parent f8c7308 commit dc3e86c

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

multimaster.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -2331,10 +2331,16 @@ void MtmReceiverStarted(int nodeId)
23312331
* Druing recovery we need to open only one replication slot from which node should receive all transactions.
23322332
* Slots at other nodes should be removed
23332333
*/
2334-
MtmReplicationMode MtmGetReplicationMode(int nodeId)
2334+
MtmReplicationMode MtmGetReplicationMode(int nodeId, sig_atomic_t volatile* shutdown)
23352335
{
23362336
bool recovery = false;
2337-
if (Mtm->status != MTM_CONNECTED && Mtm->status != MTM_ONLINE) {
2337+
2338+
while (Mtm->status != MTM_CONNECTED && Mtm->status != MTM_ONLINE)
2339+
{
2340+
if (*shutdown)
2341+
{
2342+
return REPLMODE_EXIT;
2343+
}
23382344
MTM_LOG2("%d: receiver slot mode %s", MyProcPid, MtmNodeStatusMnem[Mtm->status]);
23392345
if (Mtm->status == MTM_RECOVERY) {
23402346
recovery = true;
@@ -2351,7 +2357,6 @@ MtmReplicationMode MtmGetReplicationMode(int nodeId)
23512357
}
23522358
/* delay opening of other slots until recovery is completed */
23532359
MtmSleep(STATUS_POLL_DELAY);
2354-
return REPLMODE_UNKNOWN;
23552360
}
23562361
if (recovery) {
23572362
MTM_LOG1("Recreate replication slot for node %d after end of recovery", nodeId);

multimaster.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ typedef enum
117117

118118
typedef enum
119119
{
120-
REPLMODE_UNKNOWN, /* receiver should wait */
120+
REPLMODE_EXIT, /* receiver should exit */
121121
REPLMODE_RECOVERED, /* recovery of node is completed so drop old slot and restart replication from the current position in WAL */
122122
REPLMODE_RECOVERY, /* perform recorvery of the node by applying all data from the slot from specified point */
123123
REPLMODE_NORMAL /* normal mode: use existed slot or create new one and start receiving data from it from the specified position */
@@ -245,7 +245,7 @@ extern csn_t MtmAssignCSN(void);
245245
extern csn_t MtmSyncClock(csn_t csn);
246246
extern void MtmJoinTransaction(GlobalTransactionId* gtid, csn_t snapshot);
247247
extern void MtmReceiverStarted(int nodeId);
248-
extern MtmReplicationMode MtmGetReplicationMode(int nodeId);
248+
extern MtmReplicationMode MtmGetReplicationMode(int nodeId, sig_atomic_t volatile* shutdown);
249249
extern void MtmExecute(void* work, int size);
250250
extern void MtmExecutor(int id, void* work, size_t size);
251251
extern void MtmSendNotificationMessage(MtmTransState* ts, MtmMessageCode cmd);

pglogical_receiver.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ feTimestampDifference(int64 start_time, int64 stop_time,
193193

194194
static char const* const MtmReplicationModeName[] =
195195
{
196+
"exit",
196197
"recovered", /* recovery of node is completed so drop old slot and restart replication from the current position in WAL */
197198
"recovery", /* perform recorvery of the node by applying all data from theslot from specified point */
198199
"normal" /* normal mode: use existed slot or create new one and start receiving data from it from the specified position */
@@ -251,9 +252,10 @@ pglogical_receiver_main(Datum main_arg)
251252
* Druing recovery we need to open only one replication slot from which node should receive all transactions.
252253
* Slots at other nodes should be removed
253254
*/
254-
mode = MtmGetReplicationMode(nodeId);
255-
if (mode == REPLMODE_UNKNOWN) {
256-
continue;
255+
mode = MtmGetReplicationMode(nodeId, &got_sigterm);
256+
if (mode == REPLMODE_EXIT)
257+
{
258+
break;
257259
}
258260
count = Mtm->recoveryCount;
259261

0 commit comments

Comments
 (0)