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

Commit5910d6c

Browse files
committed
Move interrupt-handling code into subroutines.
Some auxiliary processes, as well as the autovacuum launcher,have interrupt handling code directly in their main loops.Try to abstract things a little better by moving it intoseparate functions.This doesn't make any functional difference, and leavesin place relatively large differences among processes in howinterrupts are handled, but hopefully it at least makes iteasier to see the commonalities and differences acrossprocess types.Patch by me, reviewed by Andres Freund and Daniel Gustafsson.Discussion:http://postgr.es/m/CA+TgmoZwDk=BguVDVa+qdA6SBKef=PKbaKDQALTC_9qoz1mJqg@mail.gmail.com
1 parentaf3290f commit5910d6c

File tree

4 files changed

+133
-86
lines changed

4 files changed

+133
-86
lines changed

‎src/backend/postmaster/autovacuum.c

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ NON_EXEC_STATIC void AutoVacWorkerMain(int argc, char *argv[]) pg_attribute_nore
311311
NON_EXEC_STATICvoidAutoVacLauncherMain(intargc,char*argv[])pg_attribute_noreturn();
312312

313313
staticOiddo_start_worker(void);
314+
staticvoidHandleAutoVacLauncherInterrupts(void);
315+
staticvoidAutoVacLauncherShutdown()pg_attribute_noreturn();
314316
staticvoidlauncher_determine_sleep(boolcanlaunch,boolrecursing,
315317
structtimeval*nap);
316318
staticvoidlaunch_worker(TimestampTznow);
@@ -554,7 +556,7 @@ AutoVacLauncherMain(int argc, char *argv[])
554556

555557
/* if in shutdown mode, no need for anything further; just go away */
556558
if (got_SIGTERM)
557-
gotoshutdown;
559+
AutoVacLauncherShutdown();
558560

559561
/*
560562
* Sleep at least 1 second after any error. We don't want to be
@@ -649,30 +651,7 @@ AutoVacLauncherMain(int argc, char *argv[])
649651

650652
ResetLatch(MyLatch);
651653

652-
/* Process sinval catchup interrupts that happened while sleeping */
653-
ProcessCatchupInterrupt();
654-
655-
/* the normal shutdown case */
656-
if (got_SIGTERM)
657-
break;
658-
659-
if (got_SIGHUP)
660-
{
661-
got_SIGHUP= false;
662-
ProcessConfigFile(PGC_SIGHUP);
663-
664-
/* shutdown requested in config file? */
665-
if (!AutoVacuumingActive())
666-
break;
667-
668-
/* rebalance in case the default cost parameters changed */
669-
LWLockAcquire(AutovacuumLock,LW_EXCLUSIVE);
670-
autovac_balance_cost();
671-
LWLockRelease(AutovacuumLock);
672-
673-
/* rebuild the list in case the naptime changed */
674-
rebuild_database_list(InvalidOid);
675-
}
654+
HandleAutoVacLauncherInterrupts();
676655

677656
/*
678657
* a worker finished, or postmaster signalled failure to start a
@@ -813,8 +792,47 @@ AutoVacLauncherMain(int argc, char *argv[])
813792
}
814793
}
815794

816-
/* Normal exit from the autovac launcher is here */
817-
shutdown:
795+
AutoVacLauncherShutdown();
796+
}
797+
798+
/*
799+
* Process any new interrupts.
800+
*/
801+
staticvoid
802+
HandleAutoVacLauncherInterrupts(void)
803+
{
804+
/* the normal shutdown case */
805+
if (got_SIGTERM)
806+
AutoVacLauncherShutdown();
807+
808+
if (got_SIGHUP)
809+
{
810+
got_SIGHUP= false;
811+
ProcessConfigFile(PGC_SIGHUP);
812+
813+
/* shutdown requested in config file? */
814+
if (!AutoVacuumingActive())
815+
AutoVacLauncherShutdown();
816+
817+
/* rebalance in case the default cost parameters changed */
818+
LWLockAcquire(AutovacuumLock,LW_EXCLUSIVE);
819+
autovac_balance_cost();
820+
LWLockRelease(AutovacuumLock);
821+
822+
/* rebuild the list in case the naptime changed */
823+
rebuild_database_list(InvalidOid);
824+
}
825+
826+
/* Process sinval catchup interrupts that happened while sleeping */
827+
ProcessCatchupInterrupt();
828+
}
829+
830+
/*
831+
* Perform a normal exit from the autovac launcher.
832+
*/
833+
staticvoid
834+
AutoVacLauncherShutdown()
835+
{
818836
ereport(DEBUG1,
819837
(errmsg("autovacuum launcher shutting down")));
820838
AutoVacuumShmem->av_launcherpid=0;

‎src/backend/postmaster/bgwriter.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static XLogRecPtr last_snapshot_lsn = InvalidXLogRecPtr;
9292
staticvolatilesig_atomic_tgot_SIGHUP= false;
9393
staticvolatilesig_atomic_tshutdown_requested= false;
9494

95+
staticvoidHandleBackgroundWriterInterrupts(void);
96+
9597
/* Signal handlers */
9698

9799
staticvoidbg_quickdie(SIGNAL_ARGS);
@@ -241,21 +243,7 @@ BackgroundWriterMain(void)
241243
/* Clear any already-pending wakeups */
242244
ResetLatch(MyLatch);
243245

244-
if (got_SIGHUP)
245-
{
246-
got_SIGHUP= false;
247-
ProcessConfigFile(PGC_SIGHUP);
248-
}
249-
if (shutdown_requested)
250-
{
251-
/*
252-
* From here on, elog(ERROR) should end with exit(1), not send
253-
* control back to the sigsetjmp block above
254-
*/
255-
ExitOnAnyError= true;
256-
/* Normal exit from the bgwriter is here */
257-
proc_exit(0);/* done */
258-
}
246+
HandleBackgroundWriterInterrupts();
259247

260248
/*
261249
* Do one cycle of dirty-buffer writing.
@@ -369,6 +357,30 @@ BackgroundWriterMain(void)
369357
}
370358
}
371359

360+
/*
361+
* Process any new interrupts.
362+
*/
363+
staticvoid
364+
HandleBackgroundWriterInterrupts(void)
365+
{
366+
if (got_SIGHUP)
367+
{
368+
got_SIGHUP= false;
369+
ProcessConfigFile(PGC_SIGHUP);
370+
}
371+
372+
if (shutdown_requested)
373+
{
374+
/*
375+
* From here on, elog(ERROR) should end with exit(1), not send
376+
* control back to the sigsetjmp block above
377+
*/
378+
ExitOnAnyError= true;
379+
/* Normal exit from the bgwriter is here */
380+
proc_exit(0);/* done */
381+
}
382+
}
383+
372384

373385
/* --------------------------------
374386
*signal handler routines

‎src/backend/postmaster/checkpointer.c

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static pg_time_t last_xlog_switch_time;
169169

170170
/* Prototypes for private functions */
171171

172+
staticvoidHandleCheckpointerInterrupts();
172173
staticvoidCheckArchiveTimeout(void);
173174
staticboolIsCheckpointOnSchedule(doubleprogress);
174175
staticboolImmediateCheckpointRequested(void);
@@ -350,37 +351,7 @@ CheckpointerMain(void)
350351
* Process any requests or signals received recently.
351352
*/
352353
AbsorbSyncRequests();
353-
354-
if (got_SIGHUP)
355-
{
356-
got_SIGHUP= false;
357-
ProcessConfigFile(PGC_SIGHUP);
358-
359-
/*
360-
* Checkpointer is the last process to shut down, so we ask it to
361-
* hold the keys for a range of other tasks required most of which
362-
* have nothing to do with checkpointing at all.
363-
*
364-
* For various reasons, some config values can change dynamically
365-
* so the primary copy of them is held in shared memory to make
366-
* sure all backends see the same value. We make Checkpointer
367-
* responsible for updating the shared memory copy if the
368-
* parameter setting changes because of SIGHUP.
369-
*/
370-
UpdateSharedMemoryConfig();
371-
}
372-
if (shutdown_requested)
373-
{
374-
/*
375-
* From here on, elog(ERROR) should end with exit(1), not send
376-
* control back to the sigsetjmp block above
377-
*/
378-
ExitOnAnyError= true;
379-
/* Close down the database */
380-
ShutdownXLOG(0,0);
381-
/* Normal exit from the checkpointer is here */
382-
proc_exit(0);/* done */
383-
}
354+
HandleCheckpointerInterrupts();
384355

385356
/*
386357
* Detect a pending checkpoint request by checking whether the flags
@@ -558,6 +529,44 @@ CheckpointerMain(void)
558529
}
559530
}
560531

532+
/*
533+
* Process any new interrupts.
534+
*/
535+
staticvoid
536+
HandleCheckpointerInterrupts(void)
537+
{
538+
if (got_SIGHUP)
539+
{
540+
got_SIGHUP= false;
541+
ProcessConfigFile(PGC_SIGHUP);
542+
543+
/*
544+
* Checkpointer is the last process to shut down, so we ask it to
545+
* hold the keys for a range of other tasks required most of which
546+
* have nothing to do with checkpointing at all.
547+
*
548+
* For various reasons, some config values can change dynamically
549+
* so the primary copy of them is held in shared memory to make
550+
* sure all backends see the same value. We make Checkpointer
551+
* responsible for updating the shared memory copy if the
552+
* parameter setting changes because of SIGHUP.
553+
*/
554+
UpdateSharedMemoryConfig();
555+
}
556+
if (shutdown_requested)
557+
{
558+
/*
559+
* From here on, elog(ERROR) should end with exit(1), not send
560+
* control back to the sigsetjmp block above
561+
*/
562+
ExitOnAnyError= true;
563+
/* Close down the database */
564+
ShutdownXLOG(0,0);
565+
/* Normal exit from the checkpointer is here */
566+
proc_exit(0);/* done */
567+
}
568+
}
569+
561570
/*
562571
* CheckArchiveTimeout -- check for archive_timeout and switch xlog files
563572
*

‎src/backend/postmaster/walwriter.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ intWalWriterFlushAfter = 128;
8383
staticvolatilesig_atomic_tgot_SIGHUP= false;
8484
staticvolatilesig_atomic_tshutdown_requested= false;
8585

86+
staticvoidHandleWalWriterInterrupts(void);
87+
8688
/* Signal handlers */
8789
staticvoidwal_quickdie(SIGNAL_ARGS);
8890
staticvoidWalSigHupHandler(SIGNAL_ARGS);
@@ -242,19 +244,7 @@ WalWriterMain(void)
242244
/* Clear any already-pending wakeups */
243245
ResetLatch(MyLatch);
244246

245-
/*
246-
* Process any requests or signals received recently.
247-
*/
248-
if (got_SIGHUP)
249-
{
250-
got_SIGHUP= false;
251-
ProcessConfigFile(PGC_SIGHUP);
252-
}
253-
if (shutdown_requested)
254-
{
255-
/* Normal exit from the walwriter is here */
256-
proc_exit(0);/* done */
257-
}
247+
HandleWalWriterInterrupts();
258248

259249
/*
260250
* Do what we're here for; then, if XLogBackgroundFlush() found useful
@@ -282,6 +272,24 @@ WalWriterMain(void)
282272
}
283273
}
284274

275+
/*
276+
* Process any new interrupts.
277+
*/
278+
staticvoid
279+
HandleWalWriterInterrupts(void)
280+
{
281+
if (got_SIGHUP)
282+
{
283+
got_SIGHUP= false;
284+
ProcessConfigFile(PGC_SIGHUP);
285+
}
286+
if (shutdown_requested)
287+
{
288+
/* Normal exit from the walwriter is here */
289+
proc_exit(0);/* done */
290+
}
291+
}
292+
285293

286294
/* --------------------------------
287295
*signal handler routines

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp