Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53f614f

Browse files
committed
pg_prewarm: make autoprewarm leader use standard SIGHUP and SIGTERM handlers.
Commit1e53fe0 changed background processes so that they usestandard SIGHUP handler. Like that, this commit makes autoprewarm leaderprocess also use standard SIGHUP and SIGTERM handlers, to simplify the code.Author: Bharath RupireddyReviewed-by: Kyotaro Horiguchi, Fujii MasaoDiscussion:https://postgr.es/m/CALj2ACXPorUqePswDtOeM_s82v9RW32E1fYmOPZ5NuE+TWKj_A@mail.gmail.com
1 parent5ee180a commit53f614f

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
staticboolapw_init_shmem(void);
9596
staticvoidapw_detach_shmem(intcode,Datumarg);
9697
staticintapw_compare_blockinfo(constvoid*p,constvoid*q);
97-
staticvoidapw_sigterm_handler(SIGNAL_ARGS);
98-
staticvoidapw_sighup_handler(SIGNAL_ARGS);
99-
100-
/* Flags set by signal handlers */
101-
staticvolatilesig_atomic_tgot_sigterm= false;
102-
staticvolatilesig_atomic_tgot_sighup= false;
10398

10499
/* Pointer to shared-memory state. */
105100
staticAutoPrewarmSharedState*apw_state=NULL;
@@ -161,8 +156,8 @@ autoprewarm_main(Datum main_arg)
161156
TimestampTzlast_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
return0;
897892
}
898-
899-
/*
900-
* Signal handler for SIGTERM
901-
*/
902-
staticvoid
903-
apw_sigterm_handler(SIGNAL_ARGS)
904-
{
905-
intsave_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-
staticvoid
919-
apw_sighup_handler(SIGNAL_ARGS)
920-
{
921-
intsave_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)

[8]ページ先頭

©2009-2025 Movatter.jp