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

Commit 2f0d43b

Browse files
committed
Review uses of IsUnderPostmaster, change some tests to look at
whereToSendOutput instead because they are really inquiring about the correct client communication protocol. Update some comments. This is pointing towards supporting regular FE/BE client protocol in a standalone backend, per discussion a month or so back.
1 parent b3ead7c commit 2f0d43b

File tree

8 files changed

+51
-26
lines changed

8 files changed

+51
-26
lines changed

src/backend/access/transam/slru.c

Lines changed: 2 additions & 7 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.9 2004/01/26 22:35:31 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.10 2004/01/28 21:02:39 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -184,14 +184,12 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
184184
shared = (SlruShared) ptr;
185185

186186
#ifdef EXEC_BACKEND
187-
188187
/*
189188
* Locks are in shared memory
190189
*/
191190
locks = (SlruLock) (ptr + MAXALIGN(sizeof(SlruSharedData)) +
192191
BLCKSZ * NUM_CLOG_BUFFERS);
193192
#else
194-
195193
/*
196194
* Locks are in private memory
197195
*/
@@ -200,10 +198,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
200198
Assert(locks);
201199
#endif
202200

203-
204201
if (!IsUnderPostmaster)
205-
/* Initialize locks and shared memory area */
206202
{
203+
/* Initialize locks and shared memory area */
207204
char *bufptr;
208205
int slotno;
209206

@@ -229,11 +226,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
229226
else
230227
Assert(found);
231228

232-
233229
ctl->locks = locks;
234230
ctl->shared = shared;
235231

236-
237232
/* Init directory path */
238233
snprintf(ctl->Dir, MAXPGPATH, "%s/%s", DataDir, subdir);
239234
}

src/backend/catalog/index.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.225 2004/01/07 18:56:25 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.226 2004/01/28 21:02:39 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -508,8 +508,9 @@ index_create(Oid heapRelationId,
508508
* We cannot allow indexing a shared relation after initdb (because
509509
* there's no way to make the entry in other databases' pg_class).
510510
* Unfortunately we can't distinguish initdb from a manually started
511-
* standalone backend. However, we can at least prevent this mistake
512-
* under normal multi-user operation.
511+
* standalone backend (toasting of shared rels happens after the bootstrap
512+
* phase, so checking IsBootstrapProcessingMode() won't work). However,
513+
* we can at least prevent this mistake under normal multi-user operation.
513514
*/
514515
if (shared_relation && IsUnderPostmaster)
515516
ereport(ERROR,

src/backend/commands/copy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.216 2004/01/26 22:35:31 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.217 2004/01/28 21:02:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -829,7 +829,7 @@ DoCopy(const CopyStmt *stmt)
829829
}
830830
if (pipe)
831831
{
832-
if (IsUnderPostmaster)
832+
if (whereToSendOutput == Remote)
833833
ReceiveCopyBegin(binary, length(attnumlist));
834834
else
835835
copy_file = stdin;
@@ -879,7 +879,7 @@ DoCopy(const CopyStmt *stmt)
879879
}
880880
if (pipe)
881881
{
882-
if (IsUnderPostmaster)
882+
if (whereToSendOutput == Remote)
883883
SendCopyBegin(binary, length(attnumlist));
884884
else
885885
copy_file = stdout;
@@ -929,7 +929,7 @@ DoCopy(const CopyStmt *stmt)
929929
errmsg("could not write to file \"%s\": %m",
930930
filename)));
931931
}
932-
else if (IsUnderPostmaster && !is_from)
932+
else if (whereToSendOutput == Remote && !is_from)
933933
SendCopyEnd(binary);
934934
pfree(attribute_buf.data);
935935
pfree(line_buf.data);

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.96 2004/01/23 02:13:11 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.97 2004/01/28 21:02:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4027,8 +4027,9 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
40274027
* We cannot allow toasting a shared relation after initdb (because
40284028
* there's no way to mark it toasted in other databases' pg_class).
40294029
* Unfortunately we can't distinguish initdb from a manually started
4030-
* standalone backend. However, we can at least prevent this mistake
4031-
* under normal multi-user operation.
4030+
* standalone backend (toasting happens after the bootstrap phase,
4031+
* so checking IsBootstrapProcessingMode() won't work). However, we can
4032+
* at least prevent this mistake under normal multi-user operation.
40324033
*/
40334034
shared_relation = rel->rd_rel->relisshared;
40344035
if (shared_relation && IsUnderPostmaster)

src/backend/postmaster/pgstat.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.56 2004/01/26 22:59:53 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.57 2004/01/28 21:02:40 tgl Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -1339,6 +1339,12 @@ pgstat_mainInit(void)
13391339
{
13401340
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
13411341

1342+
#ifdef EXEC_BACKEND
1343+
/* In EXEC case we will not have inherited these settings */
1344+
IsPostmasterEnvironment = true;
1345+
whereToSendOutput = None;
1346+
#endif
1347+
13421348
MyProcPid = getpid(); /* reset MyProcPid */
13431349

13441350
/* Lose the postmaster's on-exit routines */

src/backend/postmaster/postmaster.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.363 2004/01/27 00:45:26 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.364 2004/01/28 21:02:40 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -2697,6 +2697,10 @@ SubPostmasterMain(int argc, char* argv[])
26972697
/* Do this sooner rather than later... */
26982698
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
26992699

2700+
/* In EXEC case we will not have inherited these settings */
2701+
IsPostmasterEnvironment = true;
2702+
whereToSendOutput = None;
2703+
27002704
/* Setup global context */
27012705
MemoryContextInit();
27022706
InitializeGUCOptions();
@@ -2994,6 +2998,14 @@ SSDataBaseInit(int xlop)
29942998
IsUnderPostmaster = true; /* we are a postmaster subprocess
29952999
* now */
29963000

3001+
#ifdef EXEC_BACKEND
3002+
/* In EXEC case we will not have inherited these settings */
3003+
IsPostmasterEnvironment = true;
3004+
whereToSendOutput = None;
3005+
#endif
3006+
3007+
MyProcPid = getpid(); /* reset MyProcPid */
3008+
29973009
/* Lose the postmaster's on-exit routines and port connections */
29983010
on_exit_reset();
29993011

src/backend/tcop/postgres.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.386 2004/01/26 22:59:53 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.387 2004/01/28 21:02:40 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -392,7 +392,7 @@ ReadCommand(StringInfo inBuf)
392392
{
393393
int result;
394394

395-
if (IsUnderPostmaster)
395+
if (whereToSendOutput == Remote)
396396
result = SocketBackend(inBuf);
397397
else
398398
result = InteractiveBackend(inBuf);
@@ -2627,8 +2627,8 @@ PostgresMain(int argc, char *argv[], const char *username)
26272627
/* Need not flush since ReadyForQuery will do it. */
26282628
}
26292629

2630-
/* Welcome banner for non-frontend case */
2631-
if (!IsUnderPostmaster)
2630+
/* Welcome banner for standalone case */
2631+
if (whereToSendOutput == Debug)
26322632
printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION);
26332633

26342634
/*

src/backend/utils/init/globals.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.80 2004/01/26 22:59:53 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.81 2004/01/28 21:02:40 tgl Exp $
1212
*
1313
* NOTES
1414
* Globals used all over the place should be declared here and not
@@ -53,9 +53,19 @@ BackendId MyBackendId;
5353
char *DatabasePath = NULL;
5454
Oid MyDatabaseId = InvalidOid;
5555

56-
pid_t PostmasterPid = 0;
56+
pid_t PostmasterPid = 0;
5757

58-
/* these are initialized for the bootstrap/standalone case: */
58+
/*
59+
* IsPostmasterEnvironment is true in a postmaster process and any postmaster
60+
* child process; it is false in a standalone process (bootstrap or
61+
* standalone backend). IsUnderPostmaster is true in postmaster child
62+
* processes. Note that "child process" includes all children, not only
63+
* regular backends. These should be set correctly as early as possible
64+
* in the execution of a process, so that error handling will do the right
65+
* things if an error should occur during process initialization.
66+
*
67+
* These are initialized for the bootstrap/standalone case.
68+
*/
5969
bool IsPostmasterEnvironment = false;
6070
bool IsUnderPostmaster = false;
6171

0 commit comments

Comments
 (0)