Skip to content

Commit 53f614f

Browse files
committed
pg_prewarm: make autoprewarm leader use standard SIGHUP and SIGTERM handlers.
Commit 1e53fe0 changed background processes so that they use standard SIGHUP handler. Like that, this commit makes autoprewarm leader process also use standard SIGHUP and SIGTERM handlers, to simplify the code. Author: Bharath Rupireddy Reviewed-by: Kyotaro Horiguchi, Fujii Masao Discussion: https://postgr.es/m/CALj2ACXPorUqePswDtOeM_s82v9RW32E1fYmOPZ5NuE+TWKj_A@mail.gmail.com
1 parent 5ee180a commit 53f614f

File tree

1 file changed

+9
-46
lines changed

1 file changed

+9
-46
lines changed

contrib/pg_prewarm/autoprewarm.c

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "miscadmin.h"
3636
#include "pgstat.h"
3737
#include "postmaster/bgworker.h"
38+
#include "postmaster/interrupt.h"
3839
#include "storage/buf_internals.h"
3940
#include "storage/dsm.h"
4041
#include "storage/ipc.h"
@@ -94,12 +95,6 @@ static void apw_start_database_worker(void);
9495
static bool apw_init_shmem(void);
9596
static void apw_detach_shmem(int code, Datum arg);
9697
static int apw_compare_blockinfo(const void *p, const void *q);
97-
static void apw_sigterm_handler(SIGNAL_ARGS);
98-
static void apw_sighup_handler(SIGNAL_ARGS);
99-
100-
/* Flags set by signal handlers */
101-
static volatile sig_atomic_t got_sigterm = false;
102-
static volatile sig_atomic_t got_sighup = false;
10398

10499
/* Pointer to shared-memory state. */
105100
static AutoPrewarmSharedState *apw_state = NULL;
@@ -161,8 +156,8 @@ autoprewarm_main(Datum main_arg)
161156
TimestampTz last_dump_time = 0;
162157

163158
/* Establish signal handlers; once that's done, unblock signals. */
164-
pqsignal(SIGTERM, apw_sigterm_handler);
165-
pqsignal(SIGHUP, apw_sighup_handler);
159+
pqsignal(SIGTERM, SignalHandlerForShutdownRequest);
160+
pqsignal(SIGHUP, SignalHandlerForConfigReload);
166161
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
167162
BackgroundWorkerUnblockSignals();
168163

@@ -206,19 +201,19 @@ autoprewarm_main(Datum main_arg)
206201
}
207202

208203
/* Periodically dump buffers until terminated. */
209-
while (!got_sigterm)
204+
while (!ShutdownRequestPending)
210205
{
211206
/* In case of a SIGHUP, just reload the configuration. */
212-
if (got_sighup)
207+
if (ConfigReloadPending)
213208
{
214-
got_sighup = false;
209+
ConfigReloadPending = false;
215210
ProcessConfigFile(PGC_SIGHUP);
216211
}
217212

218213
if (autoprewarm_interval <= 0)
219214
{
220215
/* We're only dumping at shutdown, so just wait forever. */
221-
(void) WaitLatch(&MyProc->procLatch,
216+
(void) WaitLatch(MyLatch,
222217
WL_LATCH_SET | WL_EXIT_ON_PM_DEATH,
223218
-1L,
224219
PG_WAIT_EXTENSION);
@@ -247,14 +242,14 @@ autoprewarm_main(Datum main_arg)
247242
}
248243

249244
/* Sleep until the next dump time. */
250-
(void) WaitLatch(&MyProc->procLatch,
245+
(void) WaitLatch(MyLatch,
251246
WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
252247
delay_in_ms,
253248
PG_WAIT_EXTENSION);
254249
}
255250

256251
/* Reset the latch, loop. */
257-
ResetLatch(&MyProc->procLatch);
252+
ResetLatch(MyLatch);
258253
}
259254

260255
/*
@@ -895,35 +890,3 @@ apw_compare_blockinfo(const void *p, const void *q)
895890

896891
return 0;
897892
}
898-
899-
/*
900-
* Signal handler for SIGTERM
901-
*/
902-
static void
903-
apw_sigterm_handler(SIGNAL_ARGS)
904-
{
905-
int save_errno = errno;
906-
907-
got_sigterm = true;
908-
909-
if (MyProc)
910-
SetLatch(&MyProc->procLatch);
911-
912-
errno = save_errno;
913-
}
914-
915-
/*
916-
* Signal handler for SIGHUP
917-
*/
918-
static void
919-
apw_sighup_handler(SIGNAL_ARGS)
920-
{
921-
int save_errno = errno;
922-
923-
got_sighup = true;
924-
925-
if (MyProc)
926-
SetLatch(&MyProc->procLatch);
927-
928-
errno = save_errno;
929-
}

0 commit comments

Comments
 (0)