mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
postmaster: Rename some shutdown related PMState phase names
The previous names weren't particularly clear. Future patches will add more shutdown phases, making it even more important to have understandable shutdown phases. Suggested-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://postgr.es/m/d2cd8fd3-396a-4390-8f0b-74be65e72899@iki.fi
This commit is contained in:
parent
e84712c738
commit
28e7a9968e
@ -316,9 +316,10 @@ static bool FatalError = false; /* T if recovering from backend crash */
|
|||||||
* Notice that this state variable does not distinguish *why* we entered
|
* Notice that this state variable does not distinguish *why* we entered
|
||||||
* states later than PM_RUN --- Shutdown and FatalError must be consulted
|
* states later than PM_RUN --- Shutdown and FatalError must be consulted
|
||||||
* to find that out. FatalError is never true in PM_RECOVERY, PM_HOT_STANDBY,
|
* to find that out. FatalError is never true in PM_RECOVERY, PM_HOT_STANDBY,
|
||||||
* or PM_RUN states, nor in PM_SHUTDOWN states (because we don't enter those
|
* or PM_RUN states, nor in PM_WAIT_XLOG_SHUTDOWN states (because we don't
|
||||||
* states when trying to recover from a crash). It can be true in PM_STARTUP
|
* enter those states when trying to recover from a crash). It can be true in
|
||||||
* state, because we don't clear it until we've successfully started WAL redo.
|
* PM_STARTUP state, because we don't clear it until we've successfully
|
||||||
|
* started WAL redo.
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@ -329,9 +330,9 @@ typedef enum
|
|||||||
PM_RUN, /* normal "database is alive" state */
|
PM_RUN, /* normal "database is alive" state */
|
||||||
PM_STOP_BACKENDS, /* need to stop remaining backends */
|
PM_STOP_BACKENDS, /* need to stop remaining backends */
|
||||||
PM_WAIT_BACKENDS, /* waiting for live backends to exit */
|
PM_WAIT_BACKENDS, /* waiting for live backends to exit */
|
||||||
PM_SHUTDOWN, /* waiting for checkpointer to do shutdown
|
PM_WAIT_XLOG_SHUTDOWN, /* waiting for checkpointer to do shutdown
|
||||||
* ckpt */
|
* ckpt */
|
||||||
PM_SHUTDOWN_2, /* waiting for archiver and walsenders to
|
PM_WAIT_XLOG_ARCHIVAL, /* waiting for archiver and walsenders to
|
||||||
* finish */
|
* finish */
|
||||||
PM_WAIT_DEAD_END, /* waiting for dead-end children to exit */
|
PM_WAIT_DEAD_END, /* waiting for dead-end children to exit */
|
||||||
PM_NO_CHILDREN, /* all important children have exited */
|
PM_NO_CHILDREN, /* all important children have exited */
|
||||||
@ -2354,7 +2355,7 @@ process_pm_child_exit(void)
|
|||||||
{
|
{
|
||||||
ReleasePostmasterChildSlot(CheckpointerPMChild);
|
ReleasePostmasterChildSlot(CheckpointerPMChild);
|
||||||
CheckpointerPMChild = NULL;
|
CheckpointerPMChild = NULL;
|
||||||
if (EXIT_STATUS_0(exitstatus) && pmState == PM_SHUTDOWN)
|
if (EXIT_STATUS_0(exitstatus) && pmState == PM_WAIT_XLOG_SHUTDOWN)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* OK, we saw normal exit of the checkpointer after it's been
|
* OK, we saw normal exit of the checkpointer after it's been
|
||||||
@ -2363,8 +2364,8 @@ process_pm_child_exit(void)
|
|||||||
* occur on next postmaster start.)
|
* occur on next postmaster start.)
|
||||||
*
|
*
|
||||||
* At this point we should have no normal backend children
|
* At this point we should have no normal backend children
|
||||||
* left (else we'd not be in PM_SHUTDOWN state) but we might
|
* left (else we'd not be in PM_WAIT_XLOG_SHUTDOWN state) but
|
||||||
* have dead-end children to wait for.
|
* we might have dead-end children to wait for.
|
||||||
*
|
*
|
||||||
* If we have an archiver subprocess, tell it to do a last
|
* If we have an archiver subprocess, tell it to do a last
|
||||||
* archive cycle and quit. Likewise, if we have walsender
|
* archive cycle and quit. Likewise, if we have walsender
|
||||||
@ -2382,7 +2383,7 @@ process_pm_child_exit(void)
|
|||||||
*/
|
*/
|
||||||
SignalChildren(SIGUSR2, btmask(B_WAL_SENDER));
|
SignalChildren(SIGUSR2, btmask(B_WAL_SENDER));
|
||||||
|
|
||||||
UpdatePMState(PM_SHUTDOWN_2);
|
UpdatePMState(PM_WAIT_XLOG_ARCHIVAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2733,7 +2734,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
|
|||||||
pmState == PM_HOT_STANDBY ||
|
pmState == PM_HOT_STANDBY ||
|
||||||
pmState == PM_RUN ||
|
pmState == PM_RUN ||
|
||||||
pmState == PM_STOP_BACKENDS ||
|
pmState == PM_STOP_BACKENDS ||
|
||||||
pmState == PM_SHUTDOWN)
|
pmState == PM_WAIT_XLOG_SHUTDOWN)
|
||||||
UpdatePMState(PM_WAIT_BACKENDS);
|
UpdatePMState(PM_WAIT_BACKENDS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2957,7 +2958,7 @@ PostmasterStateMachine(void)
|
|||||||
if (CheckpointerPMChild != NULL)
|
if (CheckpointerPMChild != NULL)
|
||||||
{
|
{
|
||||||
signal_child(CheckpointerPMChild, SIGUSR2);
|
signal_child(CheckpointerPMChild, SIGUSR2);
|
||||||
UpdatePMState(PM_SHUTDOWN);
|
UpdatePMState(PM_WAIT_XLOG_SHUTDOWN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2982,13 +2983,13 @@ PostmasterStateMachine(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pmState == PM_SHUTDOWN_2)
|
if (pmState == PM_WAIT_XLOG_ARCHIVAL)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* PM_SHUTDOWN_2 state ends when there's no other children than
|
* PM_WAIT_XLOG_ARCHIVAL state ends when there's no other children
|
||||||
* dead-end children left. There shouldn't be any regular backends
|
* than dead-end children left. There shouldn't be any regular
|
||||||
* left by now anyway; what we're really waiting for is walsenders and
|
* backends left by now anyway; what we're really waiting for is
|
||||||
* archiver.
|
* walsenders and archiver.
|
||||||
*/
|
*/
|
||||||
if (CountChildren(btmask_all_except(B_LOGGER, B_DEAD_END_BACKEND)) == 0)
|
if (CountChildren(btmask_all_except(B_LOGGER, B_DEAD_END_BACKEND)) == 0)
|
||||||
{
|
{
|
||||||
@ -3131,8 +3132,8 @@ pmstate_name(PMState state)
|
|||||||
PM_TOSTR_CASE(PM_RUN);
|
PM_TOSTR_CASE(PM_RUN);
|
||||||
PM_TOSTR_CASE(PM_STOP_BACKENDS);
|
PM_TOSTR_CASE(PM_STOP_BACKENDS);
|
||||||
PM_TOSTR_CASE(PM_WAIT_BACKENDS);
|
PM_TOSTR_CASE(PM_WAIT_BACKENDS);
|
||||||
PM_TOSTR_CASE(PM_SHUTDOWN);
|
PM_TOSTR_CASE(PM_WAIT_XLOG_SHUTDOWN);
|
||||||
PM_TOSTR_CASE(PM_SHUTDOWN_2);
|
PM_TOSTR_CASE(PM_WAIT_XLOG_ARCHIVAL);
|
||||||
PM_TOSTR_CASE(PM_WAIT_DEAD_END);
|
PM_TOSTR_CASE(PM_WAIT_DEAD_END);
|
||||||
PM_TOSTR_CASE(PM_NO_CHILDREN);
|
PM_TOSTR_CASE(PM_NO_CHILDREN);
|
||||||
}
|
}
|
||||||
@ -3173,9 +3174,10 @@ LaunchMissingBackgroundProcesses(void)
|
|||||||
* The checkpointer and the background writer are active from the start,
|
* The checkpointer and the background writer are active from the start,
|
||||||
* until shutdown is initiated.
|
* until shutdown is initiated.
|
||||||
*
|
*
|
||||||
* (If the checkpointer is not running when we enter the PM_SHUTDOWN
|
* (If the checkpointer is not running when we enter the
|
||||||
* state, it is launched one more time to perform the shutdown checkpoint.
|
* PM_WAIT_XLOG_SHUTDOWN state, it is launched one more time to perform
|
||||||
* That's done in PostmasterStateMachine(), not here.)
|
* the shutdown checkpoint. That's done in PostmasterStateMachine(), not
|
||||||
|
* here.)
|
||||||
*/
|
*/
|
||||||
if (pmState == PM_RUN || pmState == PM_RECOVERY ||
|
if (pmState == PM_RUN || pmState == PM_RECOVERY ||
|
||||||
pmState == PM_HOT_STANDBY || pmState == PM_STARTUP)
|
pmState == PM_HOT_STANDBY || pmState == PM_STARTUP)
|
||||||
@ -3996,8 +3998,8 @@ bgworker_should_start_now(BgWorkerStartTime start_time)
|
|||||||
{
|
{
|
||||||
case PM_NO_CHILDREN:
|
case PM_NO_CHILDREN:
|
||||||
case PM_WAIT_DEAD_END:
|
case PM_WAIT_DEAD_END:
|
||||||
case PM_SHUTDOWN_2:
|
case PM_WAIT_XLOG_ARCHIVAL:
|
||||||
case PM_SHUTDOWN:
|
case PM_WAIT_XLOG_SHUTDOWN:
|
||||||
case PM_WAIT_BACKENDS:
|
case PM_WAIT_BACKENDS:
|
||||||
case PM_STOP_BACKENDS:
|
case PM_STOP_BACKENDS:
|
||||||
break;
|
break;
|
||||||
|
@ -45,8 +45,8 @@ shutdown checkpoint and terminating pgarch and other auxiliary processes, but
|
|||||||
that's not desirable for walsenders, because we want the standby servers to
|
that's not desirable for walsenders, because we want the standby servers to
|
||||||
receive all the WAL, including the shutdown checkpoint, before the primary
|
receive all the WAL, including the shutdown checkpoint, before the primary
|
||||||
is shut down. Therefore postmaster treats walsenders like the pgarch process,
|
is shut down. Therefore postmaster treats walsenders like the pgarch process,
|
||||||
and instructs them to terminate at PM_SHUTDOWN_2 phase, after all regular
|
and instructs them to terminate at the PM_WAIT_XLOG_ARCHIVAL phase, after all
|
||||||
backends have died and checkpointer has issued the shutdown checkpoint.
|
regular backends have died and checkpointer has issued the shutdown checkpoint.
|
||||||
|
|
||||||
When postmaster accepts a connection, it immediately forks a new process
|
When postmaster accepts a connection, it immediately forks a new process
|
||||||
to handle the handshake and authentication, and the process initializes to
|
to handle the handshake and authentication, and the process initializes to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user