]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove MyAuxProcType, use MyBackendType instead
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 4 Mar 2024 08:25:09 +0000 (10:25 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 4 Mar 2024 08:25:09 +0000 (10:25 +0200)
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

src/backend/postmaster/auxprocess.c
src/backend/postmaster/postmaster.c
src/include/miscadmin.h
src/include/postmaster/auxprocess.h
src/tools/pgindent/typedefs.list

index 39171fea06bf7632ee072e78359828d3d61c21a9..fc13cd7632193c2c9e73c5ada44eed4547320477 100644 (file)
 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);
        }
 }
index da0c627107e04de0876225aee7219cc9b7b36284..cad5987bcbceb720bef0f4de6c39fb775b0c5a3e 100644 (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);
 }
 
 
index e1adb7cd9d35622d3f5011bc5633cf1ec0df8222..712f4ad68a1d1f98eea47c56794743c292b11896 100644 (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_BG_WRITER,
-       B_CHECKPOINTER,
-       B_LOGGER,
+       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_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.                 *
index 1fdde3bb77b033e42004a0033c7b38d1fc9653f1..3e443edde704f1a582b738c6c2a9ee919d76ba38 100644 (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 */
index 782b7d7b1c81143b3f4b0b45513bd0825033e6a7..95ae7845d8695ebce4cb5ad5294f907014dd61db 100644 (file)
@@ -173,7 +173,6 @@ AutoVacOpts
 AutoVacuumShmemStruct
 AutoVacuumWorkItem
 AutoVacuumWorkItemType
-AuxProcType
 BF_ctx
 BF_key
 BF_word