Skip to content

Commit 26ad194

Browse files
committed
Support configuration reload in logical replication workers
Author: Michael Paquier <michael.paquier@gmail.com> Reviewed-by: Petr Jelinek <petr.jelinek@2ndquadrant.com> Reported-by: Fujii Masao <masao.fujii@gmail.com>
1 parent c0a8ae7 commit 26ad194

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/backend/replication/logical/launcher.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ LogicalRepCtxStruct *LogicalRepCtx;
7575
static void logicalrep_worker_onexit(int code, Datum arg);
7676
static void logicalrep_worker_detach(void);
7777

78-
bool got_SIGTERM = false;
78+
/* Flags set by signal handlers */
79+
volatile sig_atomic_t got_SIGHUP = false;
80+
volatile sig_atomic_t got_SIGTERM = false;
81+
7982
static bool on_commit_launcher_wakeup = false;
8083

8184
Datum pg_stat_get_subscription(PG_FUNCTION_ARGS);
@@ -495,10 +498,28 @@ logicalrep_worker_onexit(int code, Datum arg)
495498
void
496499
logicalrep_worker_sigterm(SIGNAL_ARGS)
497500
{
501+
int save_errno = errno;
502+
498503
got_SIGTERM = true;
499504

500505
/* Waken anything waiting on the process latch */
501506
SetLatch(MyLatch);
507+
508+
errno = save_errno;
509+
}
510+
511+
/* SIGHUP: set flag to reload configuration at next convenient time */
512+
void
513+
logicalrep_worker_sighup(SIGNAL_ARGS)
514+
{
515+
int save_errno = errno;
516+
517+
got_SIGHUP = true;
518+
519+
/* Waken anything waiting on the process latch */
520+
SetLatch(MyLatch);
521+
522+
errno = save_errno;
502523
}
503524

504525
/*
@@ -637,6 +658,7 @@ ApplyLauncherMain(Datum main_arg)
637658
(errmsg("logical replication launcher started")));
638659

639660
/* Establish signal handlers. */
661+
pqsignal(SIGHUP, logicalrep_worker_sighup);
640662
pqsignal(SIGTERM, logicalrep_worker_sigterm);
641663
BackgroundWorkerUnblockSignals();
642664

@@ -728,6 +750,12 @@ ApplyLauncherMain(Datum main_arg)
728750
if (rc & WL_POSTMASTER_DEATH)
729751
proc_exit(1);
730752

753+
if (got_SIGHUP)
754+
{
755+
got_SIGHUP = false;
756+
ProcessConfigFile(PGC_SIGHUP);
757+
}
758+
731759
ResetLatch(&MyProc->procLatch);
732760
}
733761

src/backend/replication/logical/worker.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,12 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
11381138
if (rc & WL_POSTMASTER_DEATH)
11391139
proc_exit(1);
11401140

1141+
if (got_SIGHUP)
1142+
{
1143+
got_SIGHUP = false;
1144+
ProcessConfigFile(PGC_SIGHUP);
1145+
}
1146+
11411147
if (rc & WL_TIMEOUT)
11421148
{
11431149
/*
@@ -1441,6 +1447,7 @@ ApplyWorkerMain(Datum main_arg)
14411447
logicalrep_worker_attach(worker_slot);
14421448

14431449
/* Setup signal handling */
1450+
pqsignal(SIGHUP, logicalrep_worker_sighup);
14441451
pqsignal(SIGTERM, logicalrep_worker_sigterm);
14451452
BackgroundWorkerUnblockSignals();
14461453

src/include/replication/worker_internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ extern Subscription *MySubscription;
5656
extern LogicalRepWorker *MyLogicalRepWorker;
5757

5858
extern bool in_remote_transaction;
59-
extern bool got_SIGTERM;
59+
extern volatile sig_atomic_t got_SIGHUP;
60+
extern volatile sig_atomic_t got_SIGTERM;
6061

6162
extern void logicalrep_worker_attach(int slot);
6263
extern LogicalRepWorker *logicalrep_worker_find(Oid subid, Oid relid,
@@ -69,6 +70,7 @@ extern void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker);
6970

7071
extern int logicalrep_sync_worker_count(Oid subid);
7172

73+
extern void logicalrep_worker_sighup(SIGNAL_ARGS);
7274
extern void logicalrep_worker_sigterm(SIGNAL_ARGS);
7375
extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
7476
void process_syncing_tables(XLogRecPtr current_lsn);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy