Remove PMSIGNAL_RECOVERY_COMPLETED signal, and use 0 exit status to signal
authorHeikki Linnakangas <[email protected]>
Fri, 20 Feb 2009 11:57:13 +0000 (13:57 +0200)
committerHeikki Linnakangas <[email protected]>
Fri, 20 Feb 2009 11:57:13 +0000 (13:57 +0200)
successful completion of recovery instead.

src/backend/access/transam/xlog.c
src/backend/postmaster/postmaster.c
src/backend/storage/ipc/pmsignal.c
src/include/storage/pmsignal.h

index 6c0b5f116ebe3989e52494da7faf4fcd7fe6514b..747379f61e4b9a87cb8575df61dd572a93fe375b 100644 (file)
@@ -432,7 +432,7 @@ static bool InRedo = false;
 static volatile sig_atomic_t shutdown_requested = false;
 /*
  * Flag set when executing a restore command, to tell SIGTERM signal handler
- * that it's safe to just proc_exit(0).
+ * that it's safe to just proc_exit.
  */
 static volatile sig_atomic_t in_restore_command = false;
 
@@ -2752,7 +2752,7 @@ RestoreArchivedFile(char *path, const char *xlogfname,
         */
        in_restore_command = true;
        if (shutdown_requested)
-               proc_exit(0);
+               proc_exit(1);
 
        /*
         * Copy xlog from archival storage to XLOGDIR
@@ -2818,7 +2818,7 @@ RestoreArchivedFile(char *path, const char *xlogfname,
         * On SIGTERM, assume we have received a fast shutdown request, and exit
         * cleanly. It's pure chance whether we receive the SIGTERM first, or the
         * child process. If we receive it first, the signal handler will call
-        * proc_exit(0), otherwise we do it here. If we or the child process
+        * proc_exit(1), otherwise we do it here. If we or the child process
         * received SIGTERM for any other reason than a fast shutdown request,
         * postmaster will perform an immediate shutdown when it sees us exiting
         * unexpectedly.
@@ -2829,7 +2829,7 @@ RestoreArchivedFile(char *path, const char *xlogfname,
         * too.
         */
        if (WTERMSIG(rc) == SIGTERM)
-               proc_exit(0);
+               proc_exit(1);
 
        signaled = WIFSIGNALED(rc) || WEXITSTATUS(rc) > 125;
 
@@ -5367,7 +5367,7 @@ StartupXLOG(void)
                                 * recovery.
                                 */
                                if (shutdown_requested)
-                                       proc_exit(0);
+                                       proc_exit(1);
 
                                /*
                                 * Have we reached our safe starting point? If so, we can
@@ -7646,7 +7646,7 @@ static void
 StartupProcShutdownHandler(SIGNAL_ARGS)
 {
        if (in_restore_command)
-               proc_exit(0);
+               proc_exit(1);
        else
                shutdown_requested = true;
 }
@@ -7694,9 +7694,9 @@ StartupProcessMain(void)
 
        BuildFlatFiles(false);
 
-       /* Let postmaster know that startup is finished */
-       SetPostmasterSignal(PMSIGNAL_RECOVERY_COMPLETED);
-
-       /* exit normally */
+       /*
+        * Exit normally. Exit code 0 tells postmaster that we completed
+        * recovery successfully.
+        */
        proc_exit(0);
 }
index 80460d357d3f0eef51bea14eb4af5e5079a35d49..ed921e7cc1a26609535f9382442c603e6f03fbd7 100644 (file)
@@ -2154,24 +2154,14 @@ reaper(SIGNAL_ARGS)
                 */
                if (pid == StartupPID)
                {
-                       bool recoveryCompleted;
-
                        StartupPID = 0;
 
-                       /*
-                        * Check if the startup process completed recovery before exiting
-                        */
-                       if (CheckPostmasterSignal(PMSIGNAL_RECOVERY_COMPLETED))
-                               recoveryCompleted = true;
-                       else
-                               recoveryCompleted = false;
-
                        /*
                         * Unexpected exit of startup process (including FATAL exit)
                         * during PM_STARTUP is treated as catastrophic. There is no
                         * other processes running yet, so we can just exit.
                         */
-                       if (pmState == PM_STARTUP && !recoveryCompleted)
+                       if (pmState == PM_STARTUP && !EXIT_STATUS_0(exitstatus))
                        {
                                LogChildExit(LOG, _("startup process"),
                                                         pid, exitstatus);
@@ -2179,34 +2169,23 @@ reaper(SIGNAL_ARGS)
                                (errmsg("aborting startup due to startup process failure")));
                                ExitPostmaster(1);
                        }
-                       /*
-                        * Any unexpected exit (including FATAL exit) of the startup
-                        * process is treated as a crash, except that we don't want
-                        * to reinitialize.
-                        */
-                       if (!EXIT_STATUS_0(exitstatus))
-                       {
-                               RecoveryError = true;
-                               HandleChildCrash(pid, exitstatus,
-                                                                _("startup process"));
-                               continue;
-                       }
                        /*
                         * Startup process exited in response to a shutdown request (or
-                        * it finished normally regardless of the shutdown request).
+                        * it completed normally regardless of the shutdown request).
                         */
-                       if (Shutdown > NoShutdown)
+                       if (Shutdown > NoShutdown &&
+                               (EXIT_STATUS_0(exitstatus) || EXIT_STATUS_1(exitstatus)))
                        {
                                pmState = PM_WAIT_BACKENDS;
                                /* PostmasterStateMachine logic does the rest */
                                continue;
                        }
                        /*
-                        * Startup process exited normally, but didn't finish recovery.
-                        * This can happen if someone else than postmaster kills the
-                        * startup process with SIGTERM. Treat it like a crash.
+                        * Any unexpected exit (including FATAL exit) of the startup
+                        * process is treated as a crash, except that we don't want
+                        * to reinitialize.
                         */
-                       if (!recoveryCompleted)
+                       if (!EXIT_STATUS_0(exitstatus))
                        {
                                RecoveryError = true;
                                HandleChildCrash(pid, exitstatus,
index 2c992c443afc738019d19f2ad5058f5c9261f462..00bbbc7b43150e2b149af2361a42a0f093981da4 100644 (file)
@@ -71,23 +71,6 @@ SendPostmasterSignal(PMSignalReason reason)
        kill(PostmasterPid, SIGUSR1);
 }
 
-/*
- * SetPostmasterSignal - like SendPostmasterSignal, but don't wake up
- *                                              postmaster
- *
- * This is for signals that the postmaster polls with CheckPostmasterSignal()
- * but isn't interested in processing immediately.
- */
-void
-SetPostmasterSignal(PMSignalReason reason)
-{
-       /* If called in a standalone backend, do nothing */
-       if (!IsUnderPostmaster)
-               return;
-       /* Atomically set the proper flag */
-       PMSignalFlags[reason] = true;
-}
-
 /*
  * CheckPostmasterSignal - check to see if a particular reason has been
  * signaled, and clear the signal flag.  Should be called by postmaster
index 490dd921134dfed9a528646d80a197645dd64a70..4f0432ef91ae4f052056538a14fad5844e825238 100644 (file)
@@ -24,7 +24,6 @@ typedef enum
 {
        PMSIGNAL_RECOVERY_STARTED,      /* recovery has started */
        PMSIGNAL_RECOVERY_CONSISTENT, /* recovery has reached consistent state */
-       PMSIGNAL_RECOVERY_COMPLETED, /* recovery has completed */
        PMSIGNAL_PASSWORD_CHANGE,       /* pg_auth file has changed */
        PMSIGNAL_WAKEN_ARCHIVER,        /* send a NOTIFY signal to xlog archiver */
        PMSIGNAL_ROTATE_LOGFILE,        /* send SIGUSR1 to syslogger to rotate logfile */
@@ -39,7 +38,6 @@ typedef enum
  */
 extern void PMSignalInit(void);
 extern void SendPostmasterSignal(PMSignalReason reason);
-extern void SetPostmasterSignal(PMSignalReason reason);
 extern bool CheckPostmasterSignal(PMSignalReason reason);
 extern bool PostmasterIsAlive(bool amDirectChild);