postmaster: Rename some shutdown related PMState phase names
authorAndres Freund <[email protected]>
Fri, 10 Jan 2025 16:08:17 +0000 (11:08 -0500)
committerAndres Freund <[email protected]>
Fri, 10 Jan 2025 16:43:00 +0000 (11:43 -0500)
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 <[email protected]>
Reviewed-by: Nazir Bilal Yavuz <[email protected]>
Discussion: https://postgr.es/m/d2cd8fd3-396a-4390-8f0b-74be65e72899@iki.fi

src/backend/postmaster/postmaster.c
src/backend/replication/README

index 98fc751fc59421cee42afec7e8fca00267b020c8..5f615d0f605e4600ed72d8da65407d69d279381b 100644 (file)
@@ -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
  * 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,
- * or PM_RUN states, nor in PM_SHUTDOWN states (because we don't enter those
- * states when trying to recover from a crash).  It can be true in PM_STARTUP
- * state, because we don't clear it until we've successfully started WAL redo.
+ * or PM_RUN states, nor in PM_WAIT_XLOG_SHUTDOWN states (because we don't
+ * enter those states when trying to recover from a crash).  It can be true in
+ * PM_STARTUP state, because we don't clear it until we've successfully
+ * started WAL redo.
  */
 typedef enum
 {
@@ -329,9 +330,9 @@ typedef enum
        PM_RUN,                                         /* normal "database is alive" state */
        PM_STOP_BACKENDS,                       /* need to stop remaining backends */
        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 */
-       PM_SHUTDOWN_2,                          /* waiting for archiver and walsenders to
+       PM_WAIT_XLOG_ARCHIVAL,          /* waiting for archiver and walsenders to
                                                                 * finish */
        PM_WAIT_DEAD_END,                       /* waiting for dead-end children to exit */
        PM_NO_CHILDREN,                         /* all important children have exited */
@@ -2354,7 +2355,7 @@ process_pm_child_exit(void)
                {
                        ReleasePostmasterChildSlot(CheckpointerPMChild);
                        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
@@ -2363,8 +2364,8 @@ process_pm_child_exit(void)
                                 * occur on next postmaster start.)
                                 *
                                 * At this point we should have no normal backend children
-                                * left (else we'd not be in PM_SHUTDOWN state) but we might
-                                * have dead-end children to wait for.
+                                * left (else we'd not be in PM_WAIT_XLOG_SHUTDOWN state) but
+                                * we might have dead-end children to wait for.
                                 *
                                 * If we have an archiver subprocess, tell it to do a last
                                 * archive cycle and quit. Likewise, if we have walsender
@@ -2382,7 +2383,7 @@ process_pm_child_exit(void)
                                 */
                                SignalChildren(SIGUSR2, btmask(B_WAL_SENDER));
 
-                               UpdatePMState(PM_SHUTDOWN_2);
+                               UpdatePMState(PM_WAIT_XLOG_ARCHIVAL);
                        }
                        else
                        {
@@ -2733,7 +2734,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
                pmState == PM_HOT_STANDBY ||
                pmState == PM_RUN ||
                pmState == PM_STOP_BACKENDS ||
-               pmState == PM_SHUTDOWN)
+               pmState == PM_WAIT_XLOG_SHUTDOWN)
                UpdatePMState(PM_WAIT_BACKENDS);
 
        /*
@@ -2957,7 +2958,7 @@ PostmasterStateMachine(void)
                                if (CheckpointerPMChild != NULL)
                                {
                                        signal_child(CheckpointerPMChild, SIGUSR2);
-                                       UpdatePMState(PM_SHUTDOWN);
+                                       UpdatePMState(PM_WAIT_XLOG_SHUTDOWN);
                                }
                                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
-                * dead-end children left. There shouldn't be any regular backends
-                * left by now anyway; what we're really waiting for is walsenders and
-                * archiver.
+                * PM_WAIT_XLOG_ARCHIVAL state ends when there's no other children
+                * than dead-end children left. There shouldn't be any regular
+                * backends left by now anyway; what we're really waiting for is
+                * walsenders and archiver.
                 */
                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_STOP_BACKENDS);
                        PM_TOSTR_CASE(PM_WAIT_BACKENDS);
-                       PM_TOSTR_CASE(PM_SHUTDOWN);
-                       PM_TOSTR_CASE(PM_SHUTDOWN_2);
+                       PM_TOSTR_CASE(PM_WAIT_XLOG_SHUTDOWN);
+                       PM_TOSTR_CASE(PM_WAIT_XLOG_ARCHIVAL);
                        PM_TOSTR_CASE(PM_WAIT_DEAD_END);
                        PM_TOSTR_CASE(PM_NO_CHILDREN);
        }
@@ -3173,9 +3174,10 @@ LaunchMissingBackgroundProcesses(void)
         * The checkpointer and the background writer are active from the start,
         * until shutdown is initiated.
         *
-        * (If the checkpointer is not running when we enter the PM_SHUTDOWN
-        * state, it is launched one more time to perform the shutdown checkpoint.
-        * That's done in PostmasterStateMachine(), not here.)
+        * (If the checkpointer is not running when we enter the
+        * PM_WAIT_XLOG_SHUTDOWN state, it is launched one more time to perform
+        * the shutdown checkpoint.  That's done in PostmasterStateMachine(), not
+        * here.)
         */
        if (pmState == PM_RUN || pmState == PM_RECOVERY ||
                pmState == PM_HOT_STANDBY || pmState == PM_STARTUP)
@@ -3996,8 +3998,8 @@ bgworker_should_start_now(BgWorkerStartTime start_time)
        {
                case PM_NO_CHILDREN:
                case PM_WAIT_DEAD_END:
-               case PM_SHUTDOWN_2:
-               case PM_SHUTDOWN:
+               case PM_WAIT_XLOG_ARCHIVAL:
+               case PM_WAIT_XLOG_SHUTDOWN:
                case PM_WAIT_BACKENDS:
                case PM_STOP_BACKENDS:
                        break;
index 8fcd78da9aade75214e8c3e73929d9c996731f38..f05d2aae5f96c57c9e373af4e738c0b8f8733903 100644 (file)
@@ -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
 receive all the WAL, including the shutdown checkpoint, before the primary
 is shut down. Therefore postmaster treats walsenders like the pgarch process,
-and instructs them to terminate at PM_SHUTDOWN_2 phase, after all regular
-backends have died and checkpointer has issued the shutdown checkpoint.
+and instructs them to terminate at the PM_WAIT_XLOG_ARCHIVAL phase, after all
+regular backends have died and checkpointer has issued the shutdown checkpoint.
 
 When postmaster accepts a connection, it immediately forks a new process
 to handle the handshake and authentication, and the process initializes to