From 4fd212090fd1bbdb5631001f9e96564f8fffe9fd Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 20 Feb 2009 13:57:13 +0200 Subject: [PATCH] Remove PMSIGNAL_RECOVERY_COMPLETED signal, and use 0 exit status to signal successful completion of recovery instead. --- src/backend/access/transam/xlog.c | 20 ++++++++-------- src/backend/postmaster/postmaster.c | 37 +++++++---------------------- src/backend/storage/ipc/pmsignal.c | 17 ------------- src/include/storage/pmsignal.h | 2 -- 4 files changed, 18 insertions(+), 58 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 6c0b5f116e..747379f61e 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -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); } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 80460d357d..ed921e7cc1 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -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, diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c index 2c992c443a..00bbbc7b43 100644 --- a/src/backend/storage/ipc/pmsignal.c +++ b/src/backend/storage/ipc/pmsignal.c @@ -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 diff --git a/src/include/storage/pmsignal.h b/src/include/storage/pmsignal.h index 490dd92113..4f0432ef91 100644 --- a/src/include/storage/pmsignal.h +++ b/src/include/storage/pmsignal.h @@ -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); -- 2.39.5