Remove MyAuxProcType, use MyBackendType instead

MyAuxProcType was redundant with MyBackendType.

Reviewed-by: Reid Thompson, Andres Freund
Discussion: https://www.postgresql.org/message-id/f3ecd4cb-85ee-4e54-8278-5fabfb3a4ed0@iki.fi
This commit is contained in:
Heikki Linnakangas 2024-03-04 10:25:09 +02:00
parent a0cd954480
commit 067701f577
5 changed files with 75 additions and 115 deletions

View File

@ -38,14 +38,6 @@
static void ShutdownAuxiliaryProcess(int code, Datum arg);
/* ----------------
* global variables
* ----------------
*/
AuxProcType MyAuxProcType = NotAnAuxProcess; /* declared in miscadmin.h */
/*
* AuxiliaryProcessMain
*
@ -55,39 +47,11 @@ AuxProcType MyAuxProcType = NotAnAuxProcess; /* declared in miscadmin.h */
* This code is here just because of historical reasons.
*/
void
AuxiliaryProcessMain(AuxProcType auxtype)
AuxiliaryProcessMain(BackendType auxtype)
{
Assert(IsUnderPostmaster);
MyAuxProcType = auxtype;
switch (MyAuxProcType)
{
case StartupProcess:
MyBackendType = B_STARTUP;
break;
case ArchiverProcess:
MyBackendType = B_ARCHIVER;
break;
case BgWriterProcess:
MyBackendType = B_BG_WRITER;
break;
case CheckpointerProcess:
MyBackendType = B_CHECKPOINTER;
break;
case WalWriterProcess:
MyBackendType = B_WAL_WRITER;
break;
case WalReceiverProcess:
MyBackendType = B_WAL_RECEIVER;
break;
case WalSummarizerProcess:
MyBackendType = B_WAL_SUMMARIZER;
break;
default:
elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
MyBackendType = B_INVALID;
}
MyBackendType = auxtype;
init_ps_display(NULL);
@ -126,38 +90,38 @@ AuxiliaryProcessMain(AuxProcType auxtype)
SetProcessingMode(NormalProcessing);
switch (MyAuxProcType)
switch (MyBackendType)
{
case StartupProcess:
case B_STARTUP:
StartupProcessMain();
proc_exit(1);
case ArchiverProcess:
case B_ARCHIVER:
PgArchiverMain();
proc_exit(1);
case BgWriterProcess:
case B_BG_WRITER:
BackgroundWriterMain();
proc_exit(1);
case CheckpointerProcess:
case B_CHECKPOINTER:
CheckpointerMain();
proc_exit(1);
case WalWriterProcess:
case B_WAL_WRITER:
WalWriterMain();
proc_exit(1);
case WalReceiverProcess:
case B_WAL_RECEIVER:
WalReceiverMain();
proc_exit(1);
case WalSummarizerProcess:
case B_WAL_SUMMARIZER:
WalSummarizerMain();
proc_exit(1);
default:
elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
elog(PANIC, "unrecognized process type: %d", (int) MyBackendType);
proc_exit(1);
}
}

View File

@ -442,7 +442,7 @@ static int CountChildren(int target);
static bool assign_backendlist_entry(RegisteredBgWorker *rw);
static void maybe_start_bgworkers(void);
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname);
static pid_t StartChildProcess(AuxProcType type);
static pid_t StartChildProcess(BackendType type);
static void StartAutovacuumWorker(void);
static void MaybeStartWalReceiver(void);
static void MaybeStartWalSummarizer(void);
@ -1452,14 +1452,14 @@ PostmasterMain(int argc, char *argv[])
/* Start bgwriter and checkpointer so they can help with recovery */
if (CheckpointerPID == 0)
CheckpointerPID = StartChildProcess(CheckpointerProcess);
CheckpointerPID = StartChildProcess(B_CHECKPOINTER);
if (BgWriterPID == 0)
BgWriterPID = StartChildProcess(BgWriterProcess);
BgWriterPID = StartChildProcess(B_BG_WRITER);
/*
* We're ready to rock and roll...
*/
StartupPID = StartChildProcess(StartupProcess);
StartupPID = StartChildProcess(B_STARTUP);
Assert(StartupPID != 0);
StartupStatus = STARTUP_RUNNING;
pmState = PM_STARTUP;
@ -1793,9 +1793,9 @@ ServerLoop(void)
pmState == PM_HOT_STANDBY || pmState == PM_STARTUP)
{
if (CheckpointerPID == 0)
CheckpointerPID = StartChildProcess(CheckpointerProcess);
CheckpointerPID = StartChildProcess(B_CHECKPOINTER);
if (BgWriterPID == 0)
BgWriterPID = StartChildProcess(BgWriterProcess);
BgWriterPID = StartChildProcess(B_BG_WRITER);
}
/*
@ -1804,7 +1804,7 @@ ServerLoop(void)
* be writing any new WAL).
*/
if (WalWriterPID == 0 && pmState == PM_RUN)
WalWriterPID = StartChildProcess(WalWriterProcess);
WalWriterPID = StartChildProcess(B_WAL_WRITER);
/*
* If we have lost the autovacuum launcher, try to start a new one. We
@ -1823,7 +1823,7 @@ ServerLoop(void)
/* If we have lost the archiver, try to start a new one. */
if (PgArchPID == 0 && PgArchStartupAllowed())
PgArchPID = StartChildProcess(ArchiverProcess);
PgArchPID = StartChildProcess(B_ARCHIVER);
/* If we need to start a slot sync worker, try to do that now */
MaybeStartSlotSyncWorker();
@ -3003,11 +3003,11 @@ process_pm_child_exit(void)
* if this fails, we'll just try again later.
*/
if (CheckpointerPID == 0)
CheckpointerPID = StartChildProcess(CheckpointerProcess);
CheckpointerPID = StartChildProcess(B_CHECKPOINTER);
if (BgWriterPID == 0)
BgWriterPID = StartChildProcess(BgWriterProcess);
BgWriterPID = StartChildProcess(B_BG_WRITER);
if (WalWriterPID == 0)
WalWriterPID = StartChildProcess(WalWriterProcess);
WalWriterPID = StartChildProcess(B_WAL_WRITER);
MaybeStartWalSummarizer();
/*
@ -3017,7 +3017,7 @@ process_pm_child_exit(void)
if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0)
AutoVacPID = StartAutoVacLauncher();
if (PgArchStartupAllowed() && PgArchPID == 0)
PgArchPID = StartChildProcess(ArchiverProcess);
PgArchPID = StartChildProcess(B_ARCHIVER);
MaybeStartSlotSyncWorker();
/* workers may be scheduled to start now */
@ -3173,7 +3173,7 @@ process_pm_child_exit(void)
HandleChildCrash(pid, exitstatus,
_("archiver process"));
if (PgArchStartupAllowed())
PgArchPID = StartChildProcess(ArchiverProcess);
PgArchPID = StartChildProcess(B_ARCHIVER);
continue;
}
@ -3777,7 +3777,7 @@ PostmasterStateMachine(void)
Assert(Shutdown > NoShutdown);
/* Start the checkpointer if not running */
if (CheckpointerPID == 0)
CheckpointerPID = StartChildProcess(CheckpointerProcess);
CheckpointerPID = StartChildProcess(B_CHECKPOINTER);
/* And tell it to shut down */
if (CheckpointerPID != 0)
{
@ -3932,7 +3932,7 @@ PostmasterStateMachine(void)
/* re-create shared memory and semaphores */
CreateSharedMemoryAndSemaphores();
StartupPID = StartChildProcess(StartupProcess);
StartupPID = StartChildProcess(B_STARTUP);
Assert(StartupPID != 0);
StartupStatus = STARTUP_RUNNING;
pmState = PM_STARTUP;
@ -4967,7 +4967,7 @@ SubPostmasterMain(int argc, char *argv[])
}
if (strcmp(argv[1], "--forkaux") == 0)
{
AuxProcType auxtype;
BackendType auxtype;
Assert(argc == 4);
@ -5087,7 +5087,7 @@ process_pm_pmsignal(void)
*/
Assert(PgArchPID == 0);
if (XLogArchivingAlways())
PgArchPID = StartChildProcess(ArchiverProcess);
PgArchPID = StartChildProcess(B_ARCHIVER);
/*
* If we aren't planning to enter hot standby mode later, treat
@ -5313,7 +5313,7 @@ CountChildren(int target)
* to start subprocess.
*/
static pid_t
StartChildProcess(AuxProcType type)
StartChildProcess(BackendType type)
{
pid_t pid;
@ -5365,31 +5365,31 @@ StartChildProcess(AuxProcType type)
errno = save_errno;
switch (type)
{
case StartupProcess:
case B_STARTUP:
ereport(LOG,
(errmsg("could not fork startup process: %m")));
break;
case ArchiverProcess:
case B_ARCHIVER:
ereport(LOG,
(errmsg("could not fork archiver process: %m")));
break;
case BgWriterProcess:
case B_BG_WRITER:
ereport(LOG,
(errmsg("could not fork background writer process: %m")));
break;
case CheckpointerProcess:
case B_CHECKPOINTER:
ereport(LOG,
(errmsg("could not fork checkpointer process: %m")));
break;
case WalWriterProcess:
case B_WAL_WRITER:
ereport(LOG,
(errmsg("could not fork WAL writer process: %m")));
break;
case WalReceiverProcess:
case B_WAL_RECEIVER:
ereport(LOG,
(errmsg("could not fork WAL receiver process: %m")));
break;
case WalSummarizerProcess:
case B_WAL_SUMMARIZER:
ereport(LOG,
(errmsg("could not fork WAL summarizer process: %m")));
break;
@ -5403,7 +5403,7 @@ StartChildProcess(AuxProcType type)
* fork failure is fatal during startup, but there's no need to choke
* immediately if starting other child types fails.
*/
if (type == StartupProcess)
if (type == B_STARTUP)
ExitPostmaster(1);
return 0;
}
@ -5522,7 +5522,7 @@ MaybeStartWalReceiver(void)
pmState == PM_HOT_STANDBY) &&
Shutdown <= SmartShutdown)
{
WalReceiverPID = StartChildProcess(WalReceiverProcess);
WalReceiverPID = StartChildProcess(B_WAL_RECEIVER);
if (WalReceiverPID != 0)
WalReceiverRequested = false;
/* else leave the flag set, so we'll try again later */
@ -5539,7 +5539,7 @@ MaybeStartWalSummarizer(void)
if (summarize_wal && WalSummarizerPID == 0 &&
(pmState == PM_RUN || pmState == PM_HOT_STANDBY) &&
Shutdown <= SmartShutdown)
WalSummarizerPID = StartChildProcess(WalSummarizerProcess);
WalSummarizerPID = StartChildProcess(B_WAL_SUMMARIZER);
}

View File

@ -325,30 +325,58 @@ extern void InitProcessLocalLatch(void);
extern void SwitchToSharedLatch(void);
extern void SwitchBackToLocalLatch(void);
/*
* MyBackendType indicates what kind of a backend this is.
*/
typedef enum BackendType
{
B_INVALID = 0,
B_ARCHIVER,
/* Backends and other backend-like processes */
B_BACKEND,
B_AUTOVAC_LAUNCHER,
B_AUTOVAC_WORKER,
B_BACKEND,
B_BG_WORKER,
B_WAL_SENDER,
B_SLOTSYNC_WORKER,
B_STANDALONE_BACKEND,
/*
* Auxiliary processes. These have PGPROC entries, but they are not
* attached to any particular database. There can be only one of each of
* these running at a time.
*
* If you modify these, make sure to update NUM_AUXILIARY_PROCS and the
* glossary in the docs.
*/
B_ARCHIVER,
B_BG_WRITER,
B_CHECKPOINTER,
B_LOGGER,
B_SLOTSYNC_WORKER,
B_STANDALONE_BACKEND,
B_STARTUP,
B_WAL_RECEIVER,
B_WAL_SENDER,
B_WAL_SUMMARIZER,
B_WAL_WRITER,
/*
* Logger is not connected to shared memory and does not have a PGPROC
* entry.
*/
B_LOGGER,
} BackendType;
#define BACKEND_NUM_TYPES (B_WAL_WRITER + 1)
#define BACKEND_NUM_TYPES (B_LOGGER + 1)
extern PGDLLIMPORT BackendType MyBackendType;
#define AmArchiverProcess() (MyBackendType == B_ARCHIVER)
#define AmBackgroundWriterProcess() (MyBackendType == B_BG_WRITER)
#define AmCheckpointerProcess() (MyBackendType == B_CHECKPOINTER)
#define AmStartupProcess() (MyBackendType == B_STARTUP)
#define AmWalReceiverProcess() (MyBackendType == B_WAL_RECEIVER)
#define AmWalSummarizerProcess() (MyBackendType == B_WAL_SUMMARIZER)
#define AmWalWriterProcess() (MyBackendType == B_WAL_WRITER)
extern const char *GetBackendTypeDesc(BackendType backendType);
extern void SetDatabasePath(const char *path);
@ -431,37 +459,6 @@ extern PGDLLIMPORT ProcessingMode Mode;
} while(0)
/*
* Auxiliary-process type identifiers. These used to be in bootstrap.h
* but it seems saner to have them here, with the ProcessingMode stuff.
* The MyAuxProcType global is defined and set in auxprocess.c.
*
* Make sure to list in the glossary any items you add here.
*/
typedef enum
{
NotAnAuxProcess = -1,
StartupProcess = 0,
BgWriterProcess,
ArchiverProcess,
CheckpointerProcess,
WalWriterProcess,
WalReceiverProcess,
WalSummarizerProcess,
} AuxProcType;
extern PGDLLIMPORT AuxProcType MyAuxProcType;
#define AmStartupProcess() (MyAuxProcType == StartupProcess)
#define AmBackgroundWriterProcess() (MyAuxProcType == BgWriterProcess)
#define AmArchiverProcess() (MyAuxProcType == ArchiverProcess)
#define AmCheckpointerProcess() (MyAuxProcType == CheckpointerProcess)
#define AmWalWriterProcess() (MyAuxProcType == WalWriterProcess)
#define AmWalReceiverProcess() (MyAuxProcType == WalReceiverProcess)
#define AmWalSummarizerProcess() (MyAuxProcType == WalSummarizerProcess)
/*****************************************************************************
* pinit.h -- *
* POSTGRES initialization and cleanup definitions. *

View File

@ -15,6 +15,6 @@
#include "miscadmin.h"
extern void AuxiliaryProcessMain(AuxProcType auxtype) pg_attribute_noreturn();
extern void AuxiliaryProcessMain(BackendType auxtype) pg_attribute_noreturn();
#endif /* AUXPROCESS_H */

View File

@ -173,7 +173,6 @@ AutoVacOpts
AutoVacuumShmemStruct
AutoVacuumWorkItem
AutoVacuumWorkItemType
AuxProcType
BF_ctx
BF_key
BF_word