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.
This commit is contained in:
Tom Lane 2004-01-28 21:02:40 +00:00
parent b3ead7c045
commit 2f0d43b251
8 changed files with 51 additions and 26 deletions

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.9 2004/01/26 22:35:31 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.10 2004/01/28 21:02:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -184,14 +184,12 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
shared = (SlruShared) ptr;
#ifdef EXEC_BACKEND
/*
* Locks are in shared memory
*/
locks = (SlruLock) (ptr + MAXALIGN(sizeof(SlruSharedData)) +
BLCKSZ * NUM_CLOG_BUFFERS);
#else
/*
* Locks are in private memory
*/
@ -200,10 +198,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
Assert(locks);
#endif
if (!IsUnderPostmaster)
/* Initialize locks and shared memory area */
{
/* Initialize locks and shared memory area */
char *bufptr;
int slotno;
@ -229,11 +226,9 @@ SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir)
else
Assert(found);
ctl->locks = locks;
ctl->shared = shared;
/* Init directory path */
snprintf(ctl->Dir, MAXPGPATH, "%s/%s", DataDir, subdir);
}

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.225 2004/01/07 18:56:25 neilc Exp $
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.226 2004/01/28 21:02:39 tgl Exp $
*
*
* INTERFACE ROUTINES
@ -508,8 +508,9 @@ index_create(Oid heapRelationId,
* We cannot allow indexing a shared relation after initdb (because
* there's no way to make the entry in other databases' pg_class).
* Unfortunately we can't distinguish initdb from a manually started
* standalone backend. However, we can at least prevent this mistake
* under normal multi-user operation.
* standalone backend (toasting of shared rels happens after the bootstrap
* phase, so checking IsBootstrapProcessingMode() won't work). However,
* we can at least prevent this mistake under normal multi-user operation.
*/
if (shared_relation && IsUnderPostmaster)
ereport(ERROR,

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.216 2004/01/26 22:35:31 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.217 2004/01/28 21:02:39 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -829,7 +829,7 @@ DoCopy(const CopyStmt *stmt)
}
if (pipe)
{
if (IsUnderPostmaster)
if (whereToSendOutput == Remote)
ReceiveCopyBegin(binary, length(attnumlist));
else
copy_file = stdin;
@ -879,7 +879,7 @@ DoCopy(const CopyStmt *stmt)
}
if (pipe)
{
if (IsUnderPostmaster)
if (whereToSendOutput == Remote)
SendCopyBegin(binary, length(attnumlist));
else
copy_file = stdout;
@ -929,7 +929,7 @@ DoCopy(const CopyStmt *stmt)
errmsg("could not write to file \"%s\": %m",
filename)));
}
else if (IsUnderPostmaster && !is_from)
else if (whereToSendOutput == Remote && !is_from)
SendCopyEnd(binary);
pfree(attribute_buf.data);
pfree(line_buf.data);

View File

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

View File

@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.56 2004/01/26 22:59:53 momjian Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.57 2004/01/28 21:02:40 tgl Exp $
* ----------
*/
#include "postgres.h"
@ -1339,6 +1339,12 @@ pgstat_mainInit(void)
{
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
#ifdef EXEC_BACKEND
/* In EXEC case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = None;
#endif
MyProcPid = getpid(); /* reset MyProcPid */
/* Lose the postmaster's on-exit routines */

View File

@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.363 2004/01/27 00:45:26 momjian Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.364 2004/01/28 21:02:40 tgl Exp $
*
* NOTES
*
@ -2697,6 +2697,10 @@ SubPostmasterMain(int argc, char* argv[])
/* Do this sooner rather than later... */
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
/* In EXEC case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = None;
/* Setup global context */
MemoryContextInit();
InitializeGUCOptions();
@ -2994,6 +2998,14 @@ SSDataBaseInit(int xlop)
IsUnderPostmaster = true; /* we are a postmaster subprocess
* now */
#ifdef EXEC_BACKEND
/* In EXEC case we will not have inherited these settings */
IsPostmasterEnvironment = true;
whereToSendOutput = None;
#endif
MyProcPid = getpid(); /* reset MyProcPid */
/* Lose the postmaster's on-exit routines and port connections */
on_exit_reset();

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.386 2004/01/26 22:59:53 momjian Exp $
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.387 2004/01/28 21:02:40 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@ -392,7 +392,7 @@ ReadCommand(StringInfo inBuf)
{
int result;
if (IsUnderPostmaster)
if (whereToSendOutput == Remote)
result = SocketBackend(inBuf);
else
result = InteractiveBackend(inBuf);
@ -2627,8 +2627,8 @@ PostgresMain(int argc, char *argv[], const char *username)
/* Need not flush since ReadyForQuery will do it. */
}
/* Welcome banner for non-frontend case */
if (!IsUnderPostmaster)
/* Welcome banner for standalone case */
if (whereToSendOutput == Debug)
printf("\nPostgreSQL stand-alone backend %s\n", PG_VERSION);
/*

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.80 2004/01/26 22:59:53 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.81 2004/01/28 21:02:40 tgl Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
@ -53,9 +53,19 @@ BackendId MyBackendId;
char *DatabasePath = NULL;
Oid MyDatabaseId = InvalidOid;
pid_t PostmasterPid = 0;
pid_t PostmasterPid = 0;
/* these are initialized for the bootstrap/standalone case: */
/*
* IsPostmasterEnvironment is true in a postmaster process and any postmaster
* child process; it is false in a standalone process (bootstrap or
* standalone backend). IsUnderPostmaster is true in postmaster child
* processes. Note that "child process" includes all children, not only
* regular backends. These should be set correctly as early as possible
* in the execution of a process, so that error handling will do the right
* things if an error should occur during process initialization.
*
* These are initialized for the bootstrap/standalone case.
*/
bool IsPostmasterEnvironment = false;
bool IsUnderPostmaster = false;