Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8edd8c7

Browse files
committed
postmaster: Move code to switch into FatalError state into function
There are two places switching to FatalError mode, behaving somewhat differently. An upcoming commit will introduce a third. That doesn't seem seem like a good idea. This commit just moves the FatalError related code from HandleChildCrash() into its own function, a subsequent commit will evolve the state machine change to be suitable for other callers. Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/kgng5nrvnlv335evmsuvpnh354rw7qyazl73kdysev2cr2v5zu@m3cfzxicm5kp
1 parent f0b7ab7 commit 8edd8c7

File tree

1 file changed

+51
-23
lines changed

1 file changed

+51
-23
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,40 +2674,35 @@ CleanupBackend(PMChild *bp,
26742674
}
26752675

26762676
/*
2677-
* HandleChildCrash -- cleanup after failed backend, bgwriter, checkpointer,
2678-
* walwriter, autovacuum, archiver, slot sync worker, or background worker.
2677+
* Transition into FatalError state, in response to something bad having
2678+
* happened. Commonly the caller will have logged the reason for entering
2679+
* FatalError state.
26792680
*
2680-
* The objectives here are to clean up our local state about the child
2681-
* process, and to signal all other remaining children to quickdie.
2682-
*
2683-
* The caller has already released its PMChild slot.
2681+
* This should only be called when not already in FatalError or
2682+
* ImmediateShutdown state.
26842683
*/
26852684
static void
2686-
HandleChildCrash(int pid, int exitstatus, const char *procname)
2685+
HandleFatalError(QuitSignalReason reason, bool consider_sigabrt)
26872686
{
2688-
/*
2689-
* We only log messages and send signals if this is the first process
2690-
* crash and we're not doing an immediate shutdown; otherwise, we're only
2691-
* here to update postmaster's idea of live processes. If we have already
2692-
* signaled children, nonzero exit status is to be expected, so don't
2693-
* clutter log.
2694-
*/
2695-
if (FatalError || Shutdown == ImmediateShutdown)
2696-
return;
2687+
int sigtosend;
26972688

2698-
LogChildExit(LOG, procname, pid, exitstatus);
2699-
ereport(LOG,
2700-
(errmsg("terminating any other active server processes")));
2701-
SetQuitSignalReason(PMQUIT_FOR_CRASH);
2689+
Assert(!FatalError);
2690+
Assert(Shutdown != ImmediateShutdown);
2691+
2692+
SetQuitSignalReason(reason);
2693+
2694+
if (consider_sigabrt && send_abort_for_crash)
2695+
sigtosend = SIGABRT;
2696+
else
2697+
sigtosend = SIGQUIT;
27022698

27032699
/*
2704-
* Signal all other child processes to exit. The crashed process has
2705-
* already been removed from ActiveChildList.
2700+
* Signal all other child processes to exit.
27062701
*
27072702
* We could exclude dead-end children here, but at least when sending
27082703
* SIGABRT it seems better to include them.
27092704
*/
2710-
TerminateChildren(send_abort_for_crash ? SIGABRT : SIGQUIT);
2705+
TerminateChildren(sigtosend);
27112706

27122707
FatalError = true;
27132708

@@ -2727,6 +2722,39 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
27272722
AbortStartTime = time(NULL);
27282723
}
27292724

2725+
/*
2726+
* HandleChildCrash -- cleanup after failed backend, bgwriter, checkpointer,
2727+
* walwriter, autovacuum, archiver, slot sync worker, or background worker.
2728+
*
2729+
* The objectives here are to clean up our local state about the child
2730+
* process, and to signal all other remaining children to quickdie.
2731+
*
2732+
* The caller has already released its PMChild slot.
2733+
*/
2734+
static void
2735+
HandleChildCrash(int pid, int exitstatus, const char *procname)
2736+
{
2737+
/*
2738+
* We only log messages and send signals if this is the first process
2739+
* crash and we're not doing an immediate shutdown; otherwise, we're only
2740+
* here to update postmaster's idea of live processes. If we have already
2741+
* signaled children, nonzero exit status is to be expected, so don't
2742+
* clutter log.
2743+
*/
2744+
if (FatalError || Shutdown == ImmediateShutdown)
2745+
return;
2746+
2747+
LogChildExit(LOG, procname, pid, exitstatus);
2748+
ereport(LOG,
2749+
(errmsg("terminating any other active server processes")));
2750+
2751+
/*
2752+
* Switch into error state. The crashed process has already been removed
2753+
* from ActiveChildList.
2754+
*/
2755+
HandleFatalError(PMQUIT_FOR_CRASH, true);
2756+
}
2757+
27302758
/*
27312759
* Log the death of a child process.
27322760
*/

0 commit comments

Comments
 (0)