Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1a321f2

Browse files
committed
Code review for EXEC_BACKEND changes. Reduce the number of #ifdefs by
about a third, make it work on non-Windows platforms again. (But perhaps I broke the WIN32 code, since I have no way to test that.) Fold all the paths that fork postmaster child processes to go through the single routine SubPostmasterMain, which takes care of resurrecting the state that would normally be inherited from the postmaster (including GUC variables). Clean up some places where there's no particularly good reason for the EXEC and non-EXEC cases to work differently. Take care of one or two FIXMEs that remained in the code.
1 parent 37da0ba commit 1a321f2

File tree

19 files changed

+780
-799
lines changed

19 files changed

+780
-799
lines changed

src/backend/access/transam/slru.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.13 2004/02/23 23:03:10 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.14 2004/05/28 05:12:42 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -164,10 +164,9 @@ static bool SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions);
164164
int
165165
SimpleLruShmemSize(void)
166166
{
167-
return MAXALIGN(sizeof(SlruSharedData)) + BLCKSZ * NUM_CLOG_BUFFERS
168-
#ifdef EXEC_BACKEND
167+
return MAXALIGN(sizeof(SlruSharedData))
168+
+ BLCKSZ * NUM_CLOG_BUFFERS
169169
+ MAXALIGN(sizeof(SlruLockData))
170-
#endif
171170
;
172171
}
173172

@@ -181,21 +180,8 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
181180

182181
ptr = ShmemInitStruct(name, SimpleLruShmemSize(), &found);
183182
shared = (SlruShared) ptr;
184-
185-
#ifdef EXEC_BACKEND
186-
/*
187-
* Locks are in shared memory
188-
*/
189183
locks = (SlruLock) (ptr + MAXALIGN(sizeof(SlruSharedData)) +
190184
BLCKSZ * NUM_CLOG_BUFFERS);
191-
#else
192-
/*
193-
* Locks are in private memory
194-
*/
195-
Assert(!IsUnderPostmaster);
196-
locks = malloc(sizeof(SlruLockData));
197-
Assert(locks);
198-
#endif
199185

200186
if (!IsUnderPostmaster)
201187
{
@@ -225,6 +211,7 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
225211
else
226212
Assert(found);
227213

214+
/* Initialize the unshared control struct */
228215
ctl->locks = locks;
229216
ctl->shared = shared;
230217

src/backend/access/transam/xlog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.143 2004/05/27 17:12:42 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.144 2004/05/28 05:12:42 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -397,7 +397,7 @@ static char ControlFilePath[MAXPGPATH];
397397
* Private, possibly out-of-date copy of shared LogwrtResult.
398398
* See discussion above.
399399
*/
400-
NON_EXEC_STATIC XLogwrtResult LogwrtResult = {{0, 0}, {0, 0}};
400+
static XLogwrtResult LogwrtResult = {{0, 0}, {0, 0}};
401401

402402
/*
403403
* openLogFile is -1 or a kernel FD for an open log file segment.

src/backend/bootstrap/bootstrap.c

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.180 2004/05/27 17:12:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.181 2004/05/28 05:12:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -43,17 +43,12 @@
4343
#include "utils/fmgroids.h"
4444
#include "utils/guc.h"
4545
#include "utils/lsyscache.h"
46+
#include "utils/ps_status.h"
4647
#include "utils/relcache.h"
4748

4849

4950
#define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t)))
5051

51-
#ifdef EXEC_BACKEND
52-
typedef struct Port Port;
53-
extern void SSDataBaseInit(int);
54-
extern void read_backend_variables(unsigned long, Port*);
55-
#endif
56-
5752
extern int Int_yyparse(void);
5853
static hashnode *AddStr(char *str, int strlength, int mderef);
5954
static Form_pg_attribute AllocateAttribute(void);
@@ -233,42 +228,37 @@ usage(void)
233228
}
234229

235230

236-
237-
int
238-
BootstrapMain(int argc, char *argv[])
239-
/* ----------------------------------------------------------------
240-
* The main loop for handling the backend in bootstrap mode
241-
* the bootstrap mode is used to initialize the template database
242-
* the bootstrap backend doesn't speak SQL, but instead expects
231+
/*
232+
* The main loop for running the backend in bootstrap mode
233+
*
234+
* The bootstrap mode is used to initialize the template database.
235+
* The bootstrap backend doesn't speak SQL, but instead expects
243236
* commands in a special bootstrap language.
244237
*
245-
* The arguments passed in to BootstrapMain are the run-time arguments
246-
* without the argument '-boot', the caller is required to have
247-
* removed -boot from the run-time args
248-
* ----------------------------------------------------------------
238+
* For historical reasons, BootstrapMain is also used as the control
239+
* routine for non-backend subprocesses launched by the postmaster,
240+
* such as startup and shutdown.
249241
*/
242+
int
243+
BootstrapMain(int argc, char *argv[])
250244
{
251245
int i;
252246
char *dbname;
253247
int flag;
254248
int xlogop = BS_XLOG_NOP;
255249
char *potential_DataDir = NULL;
256-
#ifdef EXEC_BACKEND
257-
unsigned long backendID = 0;
258-
#endif
259250

260251
/*
261252
* initialize globals
262253
*/
263-
264254
MyProcPid = getpid();
265255

266256
/*
267257
* Fire up essential subsystems: error and memory management
268258
*
269259
* If we are running under the postmaster, this is done already.
270260
*/
271-
if (!IsUnderPostmaster || ExecBackend)
261+
if (!IsUnderPostmaster)
272262
MemoryContextInit();
273263

274264
/*
@@ -284,6 +274,13 @@ BootstrapMain(int argc, char *argv[])
284274
* variable */
285275
}
286276

277+
/* Ignore the initial -boot argument, if present */
278+
if (argc > 1 && strcmp(argv[1], "-boot") == 0)
279+
{
280+
argv++;
281+
argc--;
282+
}
283+
287284
while ((flag = getopt(argc, argv, "B:c:d:D:Fo:p:x:-:")) != -1)
288285
{
289286
switch (flag)
@@ -315,14 +312,6 @@ BootstrapMain(int argc, char *argv[])
315312
xlogop = atoi(optarg);
316313
break;
317314
case 'p':
318-
#ifdef EXEC_BACKEND
319-
{
320-
char buf[MAXPGPATH];
321-
IsUnderPostmaster = true;
322-
sscanf(optarg,"%lu,%s",&backendID,buf);
323-
dbname = strdup(buf);
324-
}
325-
#endif
326315
dbname = strdup(optarg);
327316
break;
328317
case 'B':
@@ -369,7 +358,7 @@ BootstrapMain(int argc, char *argv[])
369358
if (!dbname || argc != optind)
370359
usage();
371360

372-
if (!IsUnderPostmaster || ExecBackend)
361+
if (!IsUnderPostmaster)
373362
{
374363
if (!potential_DataDir)
375364
{
@@ -388,21 +377,43 @@ BootstrapMain(int argc, char *argv[])
388377
Assert(DataDir);
389378
ValidatePgVersion(DataDir);
390379

391-
/* Acquire configuration parameters */
380+
/*
381+
* Identify myself via ps
382+
*/
392383
if (IsUnderPostmaster)
393384
{
394-
#ifdef EXEC_BACKEND
395-
read_backend_variables(backendID,NULL);
396-
read_nondefault_variables();
385+
const char *statmsg;
397386

398-
SSDataBaseInit(xlogop);
399-
#endif
387+
switch (xlogop)
388+
{
389+
case BS_XLOG_STARTUP:
390+
statmsg = "startup subprocess";
391+
break;
392+
case BS_XLOG_CHECKPOINT:
393+
statmsg = "checkpoint subprocess";
394+
break;
395+
case BS_XLOG_BGWRITER:
396+
statmsg = "bgwriter subprocess";
397+
break;
398+
case BS_XLOG_SHUTDOWN:
399+
statmsg = "shutdown subprocess";
400+
break;
401+
default:
402+
statmsg = "??? subprocess";
403+
break;
404+
}
405+
init_ps_display(statmsg, "", "");
406+
set_ps_display("");
400407
}
401-
else
408+
409+
/* Acquire configuration parameters, unless inherited from postmaster */
410+
if (!IsUnderPostmaster)
411+
{
402412
ProcessConfigFile(PGC_POSTMASTER);
403413

404-
/* If timezone is not set, determine what the OS uses */
405-
pg_timezone_initialize();
414+
/* If timezone is not set, determine what the OS uses */
415+
pg_timezone_initialize();
416+
}
406417

407418
if (IsUnderPostmaster)
408419
{
@@ -450,10 +461,6 @@ BootstrapMain(int argc, char *argv[])
450461
SetProcessingMode(BootstrapProcessing);
451462
IgnoreSystemIndexes(true);
452463

453-
#ifdef EXEC_BACKEND
454-
if (IsUnderPostmaster)
455-
CreateSharedMemoryAndSemaphores(false, MaxBackends, 0);
456-
#endif
457464
XLOGPathInit();
458465

459466
BaseInit();

src/backend/main/main.c

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.83 2004/05/27 15:07:40 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.84 2004/05/28 05:12:50 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -242,9 +242,9 @@ main(int argc, char *argv[])
242242

243243
/*
244244
* Now dispatch to one of PostmasterMain, PostgresMain, GucInfoMain,
245-
* SubPostmasterMain, pgstat_main, pgstat_mainChild or BootstrapMain
246-
* depending on the program name (and possibly first argument) we were
247-
* called with. The lack of consistency here is historical.
245+
* SubPostmasterMain, or BootstrapMain depending on the program name
246+
* (and possibly first argument) we were called with. The lack of
247+
* consistency here is historical.
248248
*/
249249
len = strlen(argv[0]);
250250

@@ -259,43 +259,21 @@ main(int argc, char *argv[])
259259
}
260260

261261
/*
262-
* If the first argument is "-boot", then invoke bootstrap mode. Note
263-
* we remove "-boot" from the arguments passed on to BootstrapMain.
262+
* If the first argument begins with "-fork", then invoke
263+
* SubPostmasterMain. This is used for forking postmaster child
264+
* processes on systems where we can't simply fork.
264265
*/
265-
if (argc > 1 && strcmp(argv[1], "-boot") == 0)
266-
exit(BootstrapMain(argc - 1, argv + 1));
267-
268266
#ifdef EXEC_BACKEND
267+
if (argc > 1 && strncmp(argv[1], "-fork", 5) == 0)
268+
exit(SubPostmasterMain(argc, argv));
269+
#endif
269270

270271
/*
271-
* If the first argument is "-forkexec", then invoke
272-
* SubPostmasterMain. Note we remove "-forkexec" from the arguments
273-
* passed on to SubPostmasterMain.
274-
*/
275-
if (argc > 1 && strcmp(argv[1], "-forkexec") == 0)
276-
{
277-
SubPostmasterMain(argc - 2, argv + 2);
278-
exit(0);
279-
}
280-
281-
/*
282-
* If the first argument is "-statBuf", then invoke pgstat_main.
283-
*/
284-
if (argc > 1 && strcmp(argv[1], "-statBuf") == 0)
285-
{
286-
pgstat_main(argc, argv);
287-
exit(0);
288-
}
289-
290-
/*
291-
* If the first argument is "-statCol", then invoke pgstat_mainChild.
272+
* If the first argument is "-boot", then invoke bootstrap mode.
273+
* (This path is taken only for a standalone bootstrap process.)
292274
*/
293-
if (argc > 1 && strcmp(argv[1], "-statCol") == 0)
294-
{
295-
pgstat_mainChild(argc, argv);
296-
exit(0);
297-
}
298-
#endif
275+
if (argc > 1 && strcmp(argv[1], "-boot") == 0)
276+
exit(BootstrapMain(argc, argv));
299277

300278
/*
301279
* If the first argument is "--describe-config", then invoke runtime
@@ -331,7 +309,7 @@ main(int argc, char *argv[])
331309
exit(1);
332310
}
333311
}
334-
#endif
312+
#endif /* WIN32 */
335313

336314
exit(PostgresMain(argc, argv, pw_name_persist));
337315
}

src/backend/port/ipc_test.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $PostgreSQL: pgsql/src/backend/port/ipc_test.c,v 1.12 2003/12/12 18:45:09 petere Exp $
24+
* $PostgreSQL: pgsql/src/backend/port/ipc_test.c,v 1.13 2004/05/28 05:12:55 tgl Exp $
2525
*
2626
*-------------------------------------------------------------------------
2727
*/
@@ -46,8 +46,6 @@ volatile bool ImmediateInterruptOK = false;
4646
volatile uint32 InterruptHoldoffCount = 0;
4747
volatile uint32 CritSectionCount = 0;
4848

49-
const bool ExecBackend = false;
50-
5149
bool IsUnderPostmaster = false;
5250

5351
int MaxBackends = 32;

0 commit comments

Comments
 (0)