Re: Remove Start* macros from postmaster.c to ease understanding of code

2024-02-07 Thread Nathan Bossart
On Tue, Feb 06, 2024 at 02:37:25PM -0600, Nathan Bossart wrote:
> Unless there are objections, I'll plan on committing this in the next day
> or two.

Committed.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com




Re: Remove Start* macros from postmaster.c to ease understanding of code

2024-02-06 Thread Nathan Bossart
On Wed, Feb 07, 2024 at 12:48:00AM +0530, Bharath Rupireddy wrote:
> +1. Patch LGTM.

Unless there are objections, I'll plan on committing this in the next day
or two.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com




Re: Remove Start* macros from postmaster.c to ease understanding of code

2024-02-06 Thread Bharath Rupireddy
On Tue, Feb 6, 2024 at 10:34 PM  wrote:
>
> Hi,
>
> Attached is a small patch implemented as I agree with Andres' comment
> below noted while reviewing the thread
> https://www.postgresql.org/message-id/flat/20240122210740.7vq5fd4woixpwx3f%40awork3.anarazel.de#6eb7595873392621d60e6b5a723941bc
>
> I agree that its easier to not have to refer back to the macros only to
> see that they're all invoking StartChildProcess(X). All invocations are
> within postmaster.c.
>
> > @@ -561,13 +561,13 @@ static void ShmemBackendArrayAdd(Backend *bn);
> >  static void ShmemBackendArrayRemove(Backend *bn);
> >  #endif   /* 
> > EXEC_BACKEND */
> >
> > -#define StartupDataBase()StartChildProcess(StartupProcess)
> > -#define StartArchiver()  
> > StartChildProcess(ArchiverProcess)
> > -#define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
> > -#define StartCheckpointer()  StartChildProcess(CheckpointerProcess)
> > -#define StartWalWriter() StartChildProcess(WalWriterProcess)
> > -#define StartWalReceiver()   StartChildProcess(WalReceiverProcess)
> > -#define StartWalSummarizer() StartChildProcess(WalSummarizerProcess)
> > +#define StartupDataBase()StartChildProcess(B_STARTUP)
> > +#define StartArchiver()  StartChildProcess(B_ARCHIVER)
> > +#define StartBackgroundWriter() StartChildProcess(B_BG_WRITER)
> > +#define StartCheckpointer()  StartChildProcess(B_CHECKPOINTER)
> > +#define StartWalWriter() StartChildProcess(B_WAL_WRITER)
> > +#define StartWalReceiver()   StartChildProcess(B_WAL_RECEIVER)
> > +#define StartWalSummarizer() StartChildProcess(B_WAL_SUMMARIZER)
>
> Not for this commit, but we ought to rip out these macros - all they do is to 
> make it harder to understand the code.

+1. Patch LGTM.

-- 
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com




Re: Remove Start* macros from postmaster.c to ease understanding of code

2024-02-06 Thread Nathan Bossart
On Tue, Feb 06, 2024 at 11:58:50AM -0500, reid.thomp...@crunchydata.com wrote:
> Attached is a small patch implemented as I agree with Andres' comment
> below noted while reviewing the thread
> https://www.postgresql.org/message-id/flat/20240122210740.7vq5fd4woixpwx3f%40awork3.anarazel.de#6eb7595873392621d60e6b5a723941bc
> 
> I agree that its easier to not have to refer back to the macros only to
> see that they're all invoking StartChildProcess(X). All invocations are
> within postmaster.c. 

Seems reasonable to me.

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com




Remove Start* macros from postmaster.c to ease understanding of code

2024-02-06 Thread reid . thompson
Hi,

Attached is a small patch implemented as I agree with Andres' comment
below noted while reviewing the thread
https://www.postgresql.org/message-id/flat/20240122210740.7vq5fd4woixpwx3f%40awork3.anarazel.de#6eb7595873392621d60e6b5a723941bc

I agree that its easier to not have to refer back to the macros only to
see that they're all invoking StartChildProcess(X). All invocations are
within postmaster.c. 

> @@ -561,13 +561,13 @@ static void ShmemBackendArrayAdd(Backend *bn);
>  static void ShmemBackendArrayRemove(Backend *bn);
>  #endif   /* EXEC_BACKEND 
> */
>  
> -#define StartupDataBase()StartChildProcess(StartupProcess)
> -#define StartArchiver()  
> StartChildProcess(ArchiverProcess)
> -#define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
> -#define StartCheckpointer()  StartChildProcess(CheckpointerProcess)
> -#define StartWalWriter() StartChildProcess(WalWriterProcess)
> -#define StartWalReceiver()   StartChildProcess(WalReceiverProcess)
> -#define StartWalSummarizer() StartChildProcess(WalSummarizerProcess)
> +#define StartupDataBase()StartChildProcess(B_STARTUP)
> +#define StartArchiver()  StartChildProcess(B_ARCHIVER)
> +#define StartBackgroundWriter() StartChildProcess(B_BG_WRITER)
> +#define StartCheckpointer()  StartChildProcess(B_CHECKPOINTER)
> +#define StartWalWriter() StartChildProcess(B_WAL_WRITER)
> +#define StartWalReceiver()   StartChildProcess(B_WAL_RECEIVER)
> +#define StartWalSummarizer() StartChildProcess(B_WAL_SUMMARIZER)

Not for this commit, but we ought to rip out these macros - all they do is to 
make it harder to understand the code.
From 236580a0dd381e245a459d0e8769bd30ba2d79e3 Mon Sep 17 00:00:00 2001
From: Reid Thompson 
Date: Tue, 6 Feb 2024 09:17:28 -0500
Subject: [PATCH] Remove Start* macros in postmaster.c to ease understanding of
 code. Per comment in thread here
 https://www.postgresql.org/message-id/20240122210740.7vq5fd4woixpw...@awork3.anarazel.de
 I agree that its easier to not have to refer back to the macros only to see
 that they're just invoking StartChildProcess(X). All invocations are
 within postmaster.c. 

---
 src/backend/postmaster/postmaster.c | 44 -
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index feb471dd1d..f1e60c7fd9 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -561,14 +561,6 @@ static void ShmemBackendArrayAdd(Backend *bn);
 static void ShmemBackendArrayRemove(Backend *bn);
 #endif			/* EXEC_BACKEND */
 
-#define StartupDataBase()		StartChildProcess(StartupProcess)
-#define StartArchiver()			StartChildProcess(ArchiverProcess)
-#define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
-#define StartCheckpointer()		StartChildProcess(CheckpointerProcess)
-#define StartWalWriter()		StartChildProcess(WalWriterProcess)
-#define StartWalReceiver()		StartChildProcess(WalReceiverProcess)
-#define StartWalSummarizer()	StartChildProcess(WalSummarizerProcess)
-
 /* Macros to check exit status of a child process */
 #define EXIT_STATUS_0(st)  ((st) == 0)
 #define EXIT_STATUS_1(st)  (WIFEXITED(st) && WEXITSTATUS(st) == 1)
@@ -1457,14 +1449,14 @@ PostmasterMain(int argc, char *argv[])
 
 	/* Start bgwriter and checkpointer so they can help with recovery */
 	if (CheckpointerPID == 0)
-		CheckpointerPID = StartCheckpointer();
+		CheckpointerPID = StartChildProcess(CheckpointerProcess);
 	if (BgWriterPID == 0)
-		BgWriterPID = StartBackgroundWriter();
+		BgWriterPID = StartChildProcess(BgWriterProcess);
 
 	/*
 	 * We're ready to rock and roll...
 	 */
-	StartupPID = StartupDataBase();
+	StartupPID = StartChildProcess(StartupProcess);
 	Assert(StartupPID != 0);
 	StartupStatus = STARTUP_RUNNING;
 	pmState = PM_STARTUP;
@@ -1798,9 +1790,9 @@ ServerLoop(void)
 			pmState == PM_HOT_STANDBY || pmState == PM_STARTUP)
 		{
 			if (CheckpointerPID == 0)
-CheckpointerPID = StartCheckpointer();
+CheckpointerPID = StartChildProcess(CheckpointerProcess);
 			if (BgWriterPID == 0)
-BgWriterPID = StartBackgroundWriter();
+BgWriterPID = StartChildProcess(BgWriterProcess);
 		}
 
 		/*
@@ -1809,7 +1801,7 @@ ServerLoop(void)
 		 * be writing any new WAL).
 		 */
 		if (WalWriterPID == 0 && pmState == PM_RUN)
-			WalWriterPID = StartWalWriter();
+			WalWriterPID = StartChildProcess(WalWriterProcess);
 
 		/*
 		 * If we have lost the autovacuum launcher, try to start a new one. We
@@ -1828,7 +1820,7 @@ ServerLoop(void)
 
 		/* If we have lost the archiver, try to start a new one. */
 		if (PgArchPID == 0 && PgArchStartupAllowed())
-			PgArchPID = StartArchiver();
+			PgArchPID = StartChildProcess(ArchiverProcess);
 
 		/* If we need to signal the autovacuum launcher, do so now */
 		if (avlauncher