Skip to content

Commit 280c53e

Browse files
committed
A collection of small fixes for logical replication.
* Be sure to reset the launcher's pid (LogicalRepCtx->launcher_pid) to 0 even when the launcher emits an error. * Declare ApplyLauncherWakeup() as a static function because it's called only in launcher.c. * Previously IsBackendPId() was used to check whether the launcher's pid was valid. IsBackendPid() was necessary because there was the bug where the launcher's pid was not reset to 0. But now it's fixed, so IsBackendPid() is not necessary and this patch removes it. Author: Masahiko Sawada Reviewed-by: Kyotaro Horiguchi Reported-by: Fujii Masao Discussion: http://postgr.es/m/CAHGQGwFDWh_Qr-q_GEMpD+qH=vYPMdVqw=ZOSY3kX_Pna9R9SA@mail.gmail.com
1 parent 39a6772 commit 280c53e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/backend/replication/logical/launcher.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ typedef struct LogicalRepCtxStruct
7272

7373
LogicalRepCtxStruct *LogicalRepCtx;
7474

75+
static void ApplyLauncherWakeup(void);
76+
static void logicalrep_launcher_onexit(int code, Datum arg);
7577
static void logicalrep_worker_onexit(int code, Datum arg);
7678
static void logicalrep_worker_detach(void);
7779

@@ -480,6 +482,17 @@ logicalrep_worker_detach(void)
480482
LWLockRelease(LogicalRepWorkerLock);
481483
}
482484

485+
/*
486+
* Cleanup function for logical replication launcher.
487+
*
488+
* Called on logical replication launcher exit.
489+
*/
490+
static void
491+
logicalrep_launcher_onexit(int code, Datum arg)
492+
{
493+
LogicalRepCtx->launcher_pid = 0;
494+
}
495+
483496
/*
484497
* Cleanup function.
485498
*
@@ -643,10 +656,10 @@ ApplyLauncherWakeupAtCommit(void)
643656
on_commit_launcher_wakeup = true;
644657
}
645658

646-
void
659+
static void
647660
ApplyLauncherWakeup(void)
648661
{
649-
if (IsBackendPid(LogicalRepCtx->launcher_pid))
662+
if (LogicalRepCtx->launcher_pid != 0)
650663
kill(LogicalRepCtx->launcher_pid, SIGUSR1);
651664
}
652665

@@ -659,6 +672,8 @@ ApplyLauncherMain(Datum main_arg)
659672
ereport(DEBUG1,
660673
(errmsg("logical replication launcher started")));
661674

675+
before_shmem_exit(logicalrep_launcher_onexit, (Datum) 0);
676+
662677
/* Establish signal handlers. */
663678
pqsignal(SIGHUP, logicalrep_worker_sighup);
664679
pqsignal(SIGTERM, logicalrep_worker_sigterm);

src/include/replication/logicallauncher.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ extern void ApplyLauncherMain(Datum main_arg);
2121
extern Size ApplyLauncherShmemSize(void);
2222
extern void ApplyLauncherShmemInit(void);
2323

24-
extern void ApplyLauncherWakeup(void);
2524
extern void ApplyLauncherWakeupAtCommit(void);
2625
extern void AtCommit_ApplyLauncher(void);
2726

0 commit comments

Comments
 (0)