Cleanup the bootstrap code a little, and rename "dummy procs" in the code

comments and variables to "auxiliary proc", per Heikki's request.
This commit is contained in:
Alvaro Herrera 2007-03-07 13:35:03 +00:00
parent cc0cac4a49
commit 626eb02198
9 changed files with 151 additions and 168 deletions

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.86 2007/01/09 02:14:11 tgl Exp $ * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.87 2007/03/07 13:35:02 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -235,10 +235,7 @@ Boot_InsertStmt:
elog(ERROR, "incorrect number of columns in row (expected %d, got %d)", elog(ERROR, "incorrect number of columns in row (expected %d, got %d)",
numattr, num_columns_read); numattr, num_columns_read);
if (boot_reldesc == NULL) if (boot_reldesc == NULL)
{ elog(FATAL, "relation not open");
elog(ERROR, "relation not open");
err_out();
}
InsertOneTuple($2); InsertOneTuple($2);
do_end(); do_end();
} }

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.232 2007/02/16 02:10:07 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.233 2007/03/07 13:35:02 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -20,8 +20,6 @@
#include <getopt.h> #include <getopt.h>
#endif #endif
#define BOOTSTRAP_INCLUDE /* mask out stuff in tcop/tcopprot.h */
#include "access/genam.h" #include "access/genam.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "access/xact.h" #include "access/xact.h"
@ -48,8 +46,10 @@ extern char *optarg;
#define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t))) #define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t)))
static void CheckerModeMain(void);
static void BootstrapModeMain(void);
static void bootstrap_signals(void); static void bootstrap_signals(void);
static void ShutdownDummyProcess(int code, Datum arg); static void ShutdownAuxiliaryProcess(int code, Datum arg);
static hashnode *AddStr(char *str, int strlength, int mderef); static hashnode *AddStr(char *str, int strlength, int mderef);
static Form_pg_attribute AllocateAttribute(void); static Form_pg_attribute AllocateAttribute(void);
static int CompHash(char *str, int len); static int CompHash(char *str, int len);
@ -166,7 +166,6 @@ struct typmap
static struct typmap **Typ = NULL; static struct typmap **Typ = NULL;
static struct typmap *Ap = NULL; static struct typmap *Ap = NULL;
static int Warnings = 0;
static char Blanks[MAXATTR]; static char Blanks[MAXATTR];
Form_pg_attribute attrtypes[MAXATTR]; /* points to attribute info */ Form_pg_attribute attrtypes[MAXATTR]; /* points to attribute info */
@ -193,23 +192,19 @@ static IndexList *ILHead = NULL;
/* /*
* The main entry point for running the backend in bootstrap mode * AuxiliaryProcessMain
* *
* The bootstrap mode is used to initialize the template database. * The main entry point for auxiliary processes, such as the bgwriter,
* The bootstrap backend doesn't speak SQL, but instead expects * bootstrapper and the shared memory checker code.
* commands in a special bootstrap language.
* *
* For historical reasons, BootstrapMain is also used as the control * This code is here just because of historical reasons.
* routine for non-backend subprocesses launched by the postmaster,
* such as startup and shutdown.
*/ */
int void
BootstrapMain(int argc, char *argv[]) AuxiliaryProcessMain(int argc, char *argv[])
{ {
char *progname = argv[0]; char *progname = argv[0];
int i;
int flag; int flag;
int xlogop = BS_XLOG_NOP; AuxProcType auxType = CheckerProcess;
char *userDoption = NULL; char *userDoption = NULL;
/* /*
@ -278,7 +273,7 @@ BootstrapMain(int argc, char *argv[])
strlcpy(OutputFileName, optarg, MAXPGPATH); strlcpy(OutputFileName, optarg, MAXPGPATH);
break; break;
case 'x': case 'x':
xlogop = atoi(optarg); auxType = atoi(optarg);
break; break;
case 'c': case 'c':
case '-': case '-':
@ -328,12 +323,12 @@ BootstrapMain(int argc, char *argv[])
{ {
const char *statmsg; const char *statmsg;
switch (xlogop) switch (auxType)
{ {
case BS_XLOG_STARTUP: case StartupProcess:
statmsg = "startup process"; statmsg = "startup process";
break; break;
case BS_XLOG_BGWRITER: case BgWriterProcess:
statmsg = "writer process"; statmsg = "writer process";
break; break;
default: default:
@ -372,9 +367,9 @@ BootstrapMain(int argc, char *argv[])
BaseInit(); BaseInit();
/* /*
* When we are a dummy process, we aren't going to do the full * When we are an auxiliary process, we aren't going to do the full
* InitPostgres pushups, but there are a couple of things that need to get * InitPostgres pushups, but there are a couple of things that need to get
* lit up even in a dummy process. * lit up even in an auxiliary process.
*/ */
if (IsUnderPostmaster) if (IsUnderPostmaster)
{ {
@ -383,14 +378,14 @@ BootstrapMain(int argc, char *argv[])
* this was already done by SubPostmasterMain(). * this was already done by SubPostmasterMain().
*/ */
#ifndef EXEC_BACKEND #ifndef EXEC_BACKEND
InitDummyProcess(); InitAuxiliaryProcess();
#endif #endif
/* finish setting up bufmgr.c */ /* finish setting up bufmgr.c */
InitBufferPoolBackend(); InitBufferPoolBackend();
/* register a shutdown callback for LWLock cleanup */ /* register a shutdown callback for LWLock cleanup */
on_shmem_exit(ShutdownDummyProcess, 0); on_shmem_exit(ShutdownAuxiliaryProcess, 0);
} }
/* /*
@ -398,36 +393,47 @@ BootstrapMain(int argc, char *argv[])
*/ */
SetProcessingMode(NormalProcessing); SetProcessingMode(NormalProcessing);
switch (xlogop) switch (auxType)
{ {
case BS_XLOG_NOP: case CheckerProcess:
bootstrap_signals(); bootstrap_signals();
break; CheckerModeMain();
proc_exit(1); /* should never return */
case BS_XLOG_BOOTSTRAP: case BootstrapProcess:
bootstrap_signals(); bootstrap_signals();
BootStrapXLOG(); BootStrapXLOG();
StartupXLOG(); StartupXLOG();
break; BootstrapModeMain();
proc_exit(1); /* should never return */
case BS_XLOG_STARTUP: case StartupProcess:
bootstrap_signals(); bootstrap_signals();
StartupXLOG(); StartupXLOG();
LoadFreeSpaceMap(); LoadFreeSpaceMap();
BuildFlatFiles(false); BuildFlatFiles(false);
proc_exit(0); /* startup done */ proc_exit(0); /* startup done */
case BS_XLOG_BGWRITER: case BgWriterProcess:
/* don't set signals, bgwriter has its own agenda */ /* don't set signals, bgwriter has its own agenda */
InitXLOGAccess(); InitXLOGAccess();
BackgroundWriterMain(); BackgroundWriterMain();
proc_exit(1); /* should never return */ proc_exit(1); /* should never return */
default: default:
elog(PANIC, "unrecognized XLOG op: %d", xlogop); elog(PANIC, "unrecognized process type: %d", auxType);
proc_exit(1); proc_exit(1);
} }
}
/*
* In shared memory checker mode, all we really want to do is create shared
* memory and semaphores (just to prove we can do it with the current GUC
* settings).
*/
static void
CheckerModeMain(void)
{
/* /*
* We must be getting invoked for bootstrap mode * We must be getting invoked for bootstrap mode
*/ */
@ -439,15 +445,31 @@ BootstrapMain(int argc, char *argv[])
* Do backend-like initialization for bootstrap mode * Do backend-like initialization for bootstrap mode
*/ */
InitProcess(); InitProcess();
(void) InitPostgres(NULL, InvalidOid, NULL, NULL); InitPostgres(NULL, InvalidOid, NULL, NULL);
proc_exit(0);
}
/*
* The main entry point for running the backend in bootstrap mode
*
* The bootstrap mode is used to initialize the template database.
* The bootstrap backend doesn't speak SQL, but instead expects
* commands in a special bootstrap language.
*/
static void
BootstrapModeMain(void)
{
int i;
Assert(!IsUnderPostmaster);
SetProcessingMode(BootstrapProcessing);
/* /*
* In NOP mode, all we really want to do is create shared memory and * Do backend-like initialization for bootstrap mode
* semaphores (just to prove we can do it with the current GUC settings).
* So, quit now.
*/ */
if (xlogop == BS_XLOG_NOP) InitProcess();
proc_exit(0); InitPostgres(NULL, InvalidOid, NULL, NULL);
/* Initialize stuff for bootstrap-file processing */ /* Initialize stuff for bootstrap-file processing */
for (i = 0; i < MAXATTR; i++) for (i = 0; i < MAXATTR; i++)
@ -468,14 +490,10 @@ BootstrapMain(int argc, char *argv[])
/* Perform a checkpoint to ensure everything's down to disk */ /* Perform a checkpoint to ensure everything's down to disk */
SetProcessingMode(NormalProcessing); SetProcessingMode(NormalProcessing);
CreateCheckPoint(true, true); CreateCheckPoint(true, true);
SetProcessingMode(BootstrapProcessing);
/* Clean up and exit */ /* Clean up and exit */
StartTransactionCommand();
cleanup(); cleanup();
proc_exit(0);
/* not reached, here to make compiler happy */
return 0;
} }
@ -538,30 +556,18 @@ bootstrap_signals(void)
} }
/* /*
* Begin shutdown of a dummy process. This is approximately the equivalent * Begin shutdown of an auxiliary process. This is approximately the equivalent
* of ShutdownPostgres() in postinit.c. We can't run transactions in a * of ShutdownPostgres() in postinit.c. We can't run transactions in an
* dummy process, so most of the work of AbortTransaction() is not needed, * auxiliary process, so most of the work of AbortTransaction() is not needed,
* but we do need to make sure we've released any LWLocks we are holding. * but we do need to make sure we've released any LWLocks we are holding.
* (This is only critical during an error exit.) * (This is only critical during an error exit.)
*/ */
static void static void
ShutdownDummyProcess(int code, Datum arg) ShutdownAuxiliaryProcess(int code, Datum arg)
{ {
LWLockReleaseAll(); LWLockReleaseAll();
} }
/* ----------------
* error handling / abort routines
* ----------------
*/
void
err_out(void)
{
Warnings++;
cleanup();
}
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS * MANUAL BACKEND INTERACTIVE INTERFACE COMMANDS
* ---------------------------------------------------------------- * ----------------------------------------------------------------
@ -815,15 +821,7 @@ InsertOneValue(char *value, int i)
elog(DEBUG4, "inserting column %d value \"%s\"", i, value); elog(DEBUG4, "inserting column %d value \"%s\"", i, value);
if (Typ != NULL) typoid = boot_reldesc->rd_att->attrs[i]->atttypid;
{
typoid = boot_reldesc->rd_att->attrs[i]->atttypid;
}
else
{
/* XXX why is typoid determined differently in this case? */
typoid = attrtypes[i]->atttypid;
}
boot_get_type_io_data(typoid, boot_get_type_io_data(typoid,
&typlen, &typbyval, &typalign, &typlen, &typbyval, &typalign,
@ -856,19 +854,8 @@ InsertOneNull(int i)
static void static void
cleanup(void) cleanup(void)
{ {
static int beenhere = 0;
if (!beenhere)
beenhere = 1;
else
{
elog(FATAL, "cleanup called twice");
proc_exit(1);
}
if (boot_reldesc != NULL) if (boot_reldesc != NULL)
closerel(NULL); closerel(NULL);
CommitTransactionCommand();
proc_exit(Warnings ? 1 : 0);
} }
/* ---------------- /* ----------------
@ -934,7 +921,6 @@ gettype(char *type)
return gettype(type); return gettype(type);
} }
elog(ERROR, "unrecognized type \"%s\"", type); elog(ERROR, "unrecognized type \"%s\"", type);
err_out();
/* not reached, here to make compiler happy */ /* not reached, here to make compiler happy */
return 0; return 0;
} }

View File

@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.107 2007/01/05 22:19:29 momjian Exp $ * $PostgreSQL: pgsql/src/backend/main/main.c,v 1.108 2007/03/07 13:35:02 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -177,7 +177,7 @@ main(int argc, char *argv[])
#endif #endif
if (argc > 1 && strcmp(argv[1], "--boot") == 0) if (argc > 1 && strcmp(argv[1], "--boot") == 0)
exit(BootstrapMain(argc, argv)); AuxiliaryProcessMain(argc, argv); /* does not return */
if (argc > 1 && strcmp(argv[1], "--describe-config") == 0) if (argc > 1 && strcmp(argv[1], "--describe-config") == 0)
exit(GucInfoMain()); exit(GucInfoMain());

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.32 2007/02/15 23:23:23 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.33 2007/03/07 13:35:02 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -246,7 +246,7 @@ AutoVacLauncherMain(int argc, char *argv[])
#endif #endif
/* /*
* Set up signal handlers. Since this is a "dummy" process, it has * Set up signal handlers. Since this is an auxiliary process, it has
* particular signal requirements -- no deadlock checker or sinval * particular signal requirements -- no deadlock checker or sinval
* catchup, for example. * catchup, for example.
* *
@ -277,7 +277,7 @@ AutoVacLauncherMain(int argc, char *argv[])
* had to do some stuff with LWLocks). * had to do some stuff with LWLocks).
*/ */
#ifndef EXEC_BACKEND #ifndef EXEC_BACKEND
InitDummyProcess(); InitAuxiliaryProcess();
#endif #endif
/* /*

View File

@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.525 2007/02/16 17:06:59 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.526 2007/03/07 13:35:02 alvherre Exp $
* *
* NOTES * NOTES
* *
@ -275,7 +275,7 @@ static void SignalChildren(int signal);
static void SignalSomeChildren(int signal, bool only_autovac); static void SignalSomeChildren(int signal, bool only_autovac);
static int CountChildren(void); static int CountChildren(void);
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname); static bool CreateOptsFile(int argc, char *argv[], char *fullprogname);
static pid_t StartChildProcess(int xlop); static pid_t StartChildProcess(AuxProcType type);
static void StartAutovacuumWorker(void); static void StartAutovacuumWorker(void);
#ifdef EXEC_BACKEND #ifdef EXEC_BACKEND
@ -328,7 +328,7 @@ typedef struct
LWLock *LWLockArray; LWLock *LWLockArray;
slock_t *ProcStructLock; slock_t *ProcStructLock;
PROC_HDR *ProcGlobal; PROC_HDR *ProcGlobal;
PGPROC *DummyProcs; PGPROC *AuxiliaryProcs;
InheritableSocket pgStatSock; InheritableSocket pgStatSock;
pid_t PostmasterPid; pid_t PostmasterPid;
TimestampTz PgStartTime; TimestampTz PgStartTime;
@ -360,8 +360,8 @@ static void ShmemBackendArrayAdd(Backend *bn);
static void ShmemBackendArrayRemove(pid_t pid); static void ShmemBackendArrayRemove(pid_t pid);
#endif /* EXEC_BACKEND */ #endif /* EXEC_BACKEND */
#define StartupDataBase() StartChildProcess(BS_XLOG_STARTUP) #define StartupDataBase() StartChildProcess(StartupProcess)
#define StartBackgroundWriter() StartChildProcess(BS_XLOG_BGWRITER) #define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
/* Macros to check exit status of a child process */ /* Macros to check exit status of a child process */
#define EXIT_STATUS_0(st) ((st) == 0) #define EXIT_STATUS_0(st) ((st) == 0)
@ -3433,12 +3433,12 @@ SubPostmasterMain(int argc, char *argv[])
InitShmemAccess(UsedShmemSegAddr); InitShmemAccess(UsedShmemSegAddr);
/* Need a PGPROC to run CreateSharedMemoryAndSemaphores */ /* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
InitDummyProcess(); InitAuxiliaryProcess();
/* Attach process to shared data structures */ /* Attach process to shared data structures */
CreateSharedMemoryAndSemaphores(false, 0); CreateSharedMemoryAndSemaphores(false, 0);
BootstrapMain(argc - 2, argv + 2); AuxiliaryProcessMain(argc - 2, argv + 2);
proc_exit(0); proc_exit(0);
} }
if (strcmp(argv[1], "--forkavlauncher") == 0) if (strcmp(argv[1], "--forkavlauncher") == 0)
@ -3450,7 +3450,7 @@ SubPostmasterMain(int argc, char *argv[])
InitShmemAccess(UsedShmemSegAddr); InitShmemAccess(UsedShmemSegAddr);
/* Need a PGPROC to run CreateSharedMemoryAndSemaphores */ /* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
InitDummyProcess(); InitAuxiliaryProcess();
/* Attach process to shared data structures */ /* Attach process to shared data structures */
CreateSharedMemoryAndSemaphores(false, 0); CreateSharedMemoryAndSemaphores(false, 0);
@ -3700,21 +3700,21 @@ CountChildren(void)
/* /*
* StartChildProcess -- start a non-backend child process for the postmaster * StartChildProcess -- start an auxiliary process for the postmaster
* *
* xlop determines what kind of child will be started. All child types * xlop determines what kind of child will be started. All child types
* initially go to BootstrapMain, which will handle common setup. * initially go to AuxiliaryProcessMain, which will handle common setup.
* *
* Return value of StartChildProcess is subprocess' PID, or 0 if failed * Return value of StartChildProcess is subprocess' PID, or 0 if failed
* to start subprocess. * to start subprocess.
*/ */
static pid_t static pid_t
StartChildProcess(int xlop) StartChildProcess(AuxProcType type)
{ {
pid_t pid; pid_t pid;
char *av[10]; char *av[10];
int ac = 0; int ac = 0;
char xlbuf[32]; char typebuf[32];
/* /*
* Set up command-line arguments for subprocess * Set up command-line arguments for subprocess
@ -3726,8 +3726,8 @@ StartChildProcess(int xlop)
av[ac++] = NULL; /* filled in by postmaster_forkexec */ av[ac++] = NULL; /* filled in by postmaster_forkexec */
#endif #endif
snprintf(xlbuf, sizeof(xlbuf), "-x%d", xlop); snprintf(typebuf, sizeof(typebuf), "-x%d", type);
av[ac++] = xlbuf; av[ac++] = typebuf;
av[ac] = NULL; av[ac] = NULL;
Assert(ac < lengthof(av)); Assert(ac < lengthof(av));
@ -3752,7 +3752,7 @@ StartChildProcess(int xlop)
MemoryContextDelete(PostmasterContext); MemoryContextDelete(PostmasterContext);
PostmasterContext = NULL; PostmasterContext = NULL;
BootstrapMain(ac, av); AuxiliaryProcessMain(ac, av);
ExitPostmaster(0); ExitPostmaster(0);
} }
#endif /* EXEC_BACKEND */ #endif /* EXEC_BACKEND */
@ -3763,13 +3763,13 @@ StartChildProcess(int xlop)
int save_errno = errno; int save_errno = errno;
errno = save_errno; errno = save_errno;
switch (xlop) switch (type)
{ {
case BS_XLOG_STARTUP: case StartupProcess:
ereport(LOG, ereport(LOG,
(errmsg("could not fork startup process: %m"))); (errmsg("could not fork startup process: %m")));
break; break;
case BS_XLOG_BGWRITER: case BgWriterProcess:
ereport(LOG, ereport(LOG,
(errmsg("could not fork background writer process: %m"))); (errmsg("could not fork background writer process: %m")));
break; break;
@ -3783,7 +3783,7 @@ StartChildProcess(int xlop)
* fork failure is fatal during startup, but there's no need to choke * fork failure is fatal during startup, but there's no need to choke
* immediately if starting other child types fails. * immediately if starting other child types fails.
*/ */
if (xlop == BS_XLOG_STARTUP) if (type == StartupProcess)
ExitPostmaster(1); ExitPostmaster(1);
return 0; return 0;
} }
@ -3887,7 +3887,7 @@ extern slock_t *ShmemLock;
extern LWLock *LWLockArray; extern LWLock *LWLockArray;
extern slock_t *ProcStructLock; extern slock_t *ProcStructLock;
extern PROC_HDR *ProcGlobal; extern PROC_HDR *ProcGlobal;
extern PGPROC *DummyProcs; extern PGPROC *AuxiliaryProcs;
extern int pgStatSock; extern int pgStatSock;
#ifndef WIN32 #ifndef WIN32
@ -3930,7 +3930,7 @@ save_backend_variables(BackendParameters * param, Port *port,
param->LWLockArray = LWLockArray; param->LWLockArray = LWLockArray;
param->ProcStructLock = ProcStructLock; param->ProcStructLock = ProcStructLock;
param->ProcGlobal = ProcGlobal; param->ProcGlobal = ProcGlobal;
param->DummyProcs = DummyProcs; param->AuxiliaryProcs = AuxiliaryProcs;
write_inheritable_socket(&param->pgStatSock, pgStatSock, childPid); write_inheritable_socket(&param->pgStatSock, pgStatSock, childPid);
param->PostmasterPid = PostmasterPid; param->PostmasterPid = PostmasterPid;
@ -4133,7 +4133,7 @@ restore_backend_variables(BackendParameters * param, Port *port)
LWLockArray = param->LWLockArray; LWLockArray = param->LWLockArray;
ProcStructLock = param->ProcStructLock; ProcStructLock = param->ProcStructLock;
ProcGlobal = param->ProcGlobal; ProcGlobal = param->ProcGlobal;
DummyProcs = param->DummyProcs; AuxiliaryProcs = param->AuxiliaryProcs;
read_inheritable_socket(&pgStatSock, &param->pgStatSock); read_inheritable_socket(&pgStatSock, &param->pgStatSock);
PostmasterPid = param->PostmasterPid; PostmasterPid = param->PostmasterPid;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.185 2007/03/03 18:46:40 momjian Exp $ * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.186 2007/03/07 13:35:03 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -64,7 +64,7 @@ NON_EXEC_STATIC slock_t *ProcStructLock = NULL;
/* Pointers to shared-memory structures */ /* Pointers to shared-memory structures */
NON_EXEC_STATIC PROC_HDR *ProcGlobal = NULL; NON_EXEC_STATIC PROC_HDR *ProcGlobal = NULL;
NON_EXEC_STATIC PGPROC *DummyProcs = NULL; NON_EXEC_STATIC PGPROC *AuxiliaryProcs = NULL;
/* If we are waiting for a lock, this points to the associated LOCALLOCK */ /* If we are waiting for a lock, this points to the associated LOCALLOCK */
static LOCALLOCK *lockAwaited = NULL; static LOCALLOCK *lockAwaited = NULL;
@ -80,7 +80,7 @@ static TimestampTz statement_fin_time;
static void RemoveProcFromArray(int code, Datum arg); static void RemoveProcFromArray(int code, Datum arg);
static void ProcKill(int code, Datum arg); static void ProcKill(int code, Datum arg);
static void DummyProcKill(int code, Datum arg); static void AuxiliaryProcKill(int code, Datum arg);
static bool CheckStatementTimeout(void); static bool CheckStatementTimeout(void);
@ -94,8 +94,8 @@ ProcGlobalShmemSize(void)
/* ProcGlobal */ /* ProcGlobal */
size = add_size(size, sizeof(PROC_HDR)); size = add_size(size, sizeof(PROC_HDR));
/* DummyProcs */ /* AuxiliaryProcs */
size = add_size(size, mul_size(NUM_DUMMY_PROCS, sizeof(PGPROC))); size = add_size(size, mul_size(NUM_AUXILIARY_PROCS, sizeof(PGPROC)));
/* MyProcs */ /* MyProcs */
size = add_size(size, mul_size(MaxBackends, sizeof(PGPROC))); size = add_size(size, mul_size(MaxBackends, sizeof(PGPROC)));
/* ProcStructLock */ /* ProcStructLock */
@ -110,8 +110,8 @@ ProcGlobalShmemSize(void)
int int
ProcGlobalSemas(void) ProcGlobalSemas(void)
{ {
/* We need a sema per backend, plus one for each dummy process. */ /* We need a sema per backend, plus one for each auxiliary process. */
return MaxBackends + NUM_DUMMY_PROCS; return MaxBackends + NUM_AUXILIARY_PROCS;
} }
/* /*
@ -135,7 +135,7 @@ ProcGlobalSemas(void)
* postmaster, not in backends. * postmaster, not in backends.
* *
* Note: this is NOT called by individual backends under a postmaster, * Note: this is NOT called by individual backends under a postmaster,
* not even in the EXEC_BACKEND case. The ProcGlobal and DummyProcs * not even in the EXEC_BACKEND case. The ProcGlobal and AuxiliaryProcs
* pointers must be propagated specially for EXEC_BACKEND operation. * pointers must be propagated specially for EXEC_BACKEND operation.
*/ */
void void
@ -151,11 +151,11 @@ InitProcGlobal(void)
Assert(!found); Assert(!found);
/* /*
* Create the PGPROC structures for dummy (bgwriter) processes, too. These * Create the PGPROC structures for auxiliary (bgwriter) processes, too.
* do not get linked into the freeProcs list. * These do not get linked into the freeProcs list.
*/ */
DummyProcs = (PGPROC *) AuxiliaryProcs = (PGPROC *)
ShmemInitStruct("DummyProcs", NUM_DUMMY_PROCS * sizeof(PGPROC), ShmemInitStruct("AuxiliaryProcs", NUM_AUXILIARY_PROCS * sizeof(PGPROC),
&found); &found);
Assert(!found); Assert(!found);
@ -182,11 +182,11 @@ InitProcGlobal(void)
ProcGlobal->freeProcs = MAKE_OFFSET(&procs[i]); ProcGlobal->freeProcs = MAKE_OFFSET(&procs[i]);
} }
MemSet(DummyProcs, 0, NUM_DUMMY_PROCS * sizeof(PGPROC)); MemSet(AuxiliaryProcs, 0, NUM_AUXILIARY_PROCS * sizeof(PGPROC));
for (i = 0; i < NUM_DUMMY_PROCS; i++) for (i = 0; i < NUM_AUXILIARY_PROCS; i++)
{ {
DummyProcs[i].pid = 0; /* marks dummy proc as not in use */ AuxiliaryProcs[i].pid = 0; /* marks auxiliary proc as not in use */
PGSemaphoreCreate(&(DummyProcs[i].sem)); PGSemaphoreCreate(&(AuxiliaryProcs[i].sem));
} }
/* Create ProcStructLock spinlock, too */ /* Create ProcStructLock spinlock, too */
@ -320,21 +320,21 @@ InitProcessPhase2(void)
} }
/* /*
* InitDummyProcess -- create a dummy per-process data structure * InitAuxiliaryProcess -- create a per-auxiliary-process data structure
* *
* This is called by bgwriter and similar processes so that they will have a * This is called by bgwriter and similar processes so that they will have a
* MyProc value that's real enough to let them wait for LWLocks. The PGPROC * MyProc value that's real enough to let them wait for LWLocks. The PGPROC
* and sema that are assigned are one of the extra ones created during * and sema that are assigned are one of the extra ones created during
* InitProcGlobal. * InitProcGlobal.
* *
* Dummy processes are presently not expected to wait for real (lockmgr) * Auxiliary processes are presently not expected to wait for real (lockmgr)
* locks, so we need not set up the deadlock checker. They are never added * locks, so we need not set up the deadlock checker. They are never added
* to the ProcArray or the sinval messaging mechanism, either. * to the ProcArray or the sinval messaging mechanism, either.
*/ */
void void
InitDummyProcess(void) InitAuxiliaryProcess(void)
{ {
PGPROC *dummyproc; PGPROC *auxproc;
int proctype; int proctype;
int i; int i;
@ -342,7 +342,7 @@ InitDummyProcess(void)
* ProcGlobal should be set up already (if we are a backend, we inherit * ProcGlobal should be set up already (if we are a backend, we inherit
* this by fork() or EXEC_BACKEND mechanism from the postmaster). * this by fork() or EXEC_BACKEND mechanism from the postmaster).
*/ */
if (ProcGlobal == NULL || DummyProcs == NULL) if (ProcGlobal == NULL || AuxiliaryProcs == NULL)
elog(PANIC, "proc header uninitialized"); elog(PANIC, "proc header uninitialized");
if (MyProc != NULL) if (MyProc != NULL)
@ -350,7 +350,7 @@ InitDummyProcess(void)
/* /*
* We use the ProcStructLock to protect assignment and releasing of * We use the ProcStructLock to protect assignment and releasing of
* DummyProcs entries. * AuxiliaryProcs entries.
* *
* While we are holding the ProcStructLock, also copy the current shared * While we are holding the ProcStructLock, also copy the current shared
* estimate of spins_per_delay to local storage. * estimate of spins_per_delay to local storage.
@ -360,25 +360,25 @@ InitDummyProcess(void)
set_spins_per_delay(ProcGlobal->spins_per_delay); set_spins_per_delay(ProcGlobal->spins_per_delay);
/* /*
* Find a free dummyproc ... *big* trouble if there isn't one ... * Find a free auxproc ... *big* trouble if there isn't one ...
*/ */
for (proctype = 0; proctype < NUM_DUMMY_PROCS; proctype++) for (proctype = 0; proctype < NUM_AUXILIARY_PROCS; proctype++)
{ {
dummyproc = &DummyProcs[proctype]; auxproc = &AuxiliaryProcs[proctype];
if (dummyproc->pid == 0) if (auxproc->pid == 0)
break; break;
} }
if (proctype >= NUM_DUMMY_PROCS) if (proctype >= NUM_AUXILIARY_PROCS)
{ {
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
elog(FATAL, "all DummyProcs are in use"); elog(FATAL, "all AuxiliaryProcs are in use");
} }
/* Mark dummy proc as in use by me */ /* Mark auxiliary proc as in use by me */
/* use volatile pointer to prevent code rearrangement */ /* use volatile pointer to prevent code rearrangement */
((volatile PGPROC *) dummyproc)->pid = MyProcPid; ((volatile PGPROC *) auxproc)->pid = MyProcPid;
MyProc = dummyproc; MyProc = auxproc;
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
@ -412,7 +412,7 @@ InitDummyProcess(void)
/* /*
* Arrange to clean up at process exit. * Arrange to clean up at process exit.
*/ */
on_shmem_exit(DummyProcKill, Int32GetDatum(proctype)); on_shmem_exit(AuxiliaryProcKill, Int32GetDatum(proctype));
} }
/* /*
@ -582,28 +582,28 @@ ProcKill(int code, Datum arg)
} }
/* /*
* DummyProcKill() -- Cut-down version of ProcKill for dummy (bgwriter) * AuxiliaryProcKill() -- Cut-down version of ProcKill for auxiliary
* processes. The PGPROC and sema are not released, only marked * processes (bgwriter, etc). The PGPROC and sema are not released, only
* as not-in-use. * marked as not-in-use.
*/ */
static void static void
DummyProcKill(int code, Datum arg) AuxiliaryProcKill(int code, Datum arg)
{ {
int proctype = DatumGetInt32(arg); int proctype = DatumGetInt32(arg);
PGPROC *dummyproc; PGPROC *auxproc;
Assert(proctype >= 0 && proctype < NUM_DUMMY_PROCS); Assert(proctype >= 0 && proctype < NUM_AUXILIARY_PROCS);
dummyproc = &DummyProcs[proctype]; auxproc = &AuxiliaryProcs[proctype];
Assert(MyProc == dummyproc); Assert(MyProc == auxproc);
/* Release any LW locks I am holding (see notes above) */ /* Release any LW locks I am holding (see notes above) */
LWLockReleaseAll(); LWLockReleaseAll();
SpinLockAcquire(ProcStructLock); SpinLockAcquire(ProcStructLock);
/* Mark dummy proc no longer in use */ /* Mark auxiliary proc no longer in use */
MyProc->pid = 0; MyProc->pid = 0;
/* PGPROC struct isn't mine anymore */ /* PGPROC struct isn't mine anymore */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/bootstrap/bootstrap.h,v 1.45 2007/01/05 22:19:51 momjian Exp $ * $PostgreSQL: pgsql/src/include/bootstrap/bootstrap.h,v 1.46 2007/03/07 13:35:03 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -32,7 +32,7 @@ typedef struct hashnode
extern Relation boot_reldesc; extern Relation boot_reldesc;
extern Form_pg_attribute attrtypes[MAXATTR]; extern Form_pg_attribute attrtypes[MAXATTR];
extern int numattr; extern int numattr;
extern int BootstrapMain(int argc, char *argv[]); extern void AuxiliaryProcessMain(int argc, char *argv[]);
extern void index_register(Oid heap, Oid ind, IndexInfo *indexInfo); extern void index_register(Oid heap, Oid ind, IndexInfo *indexInfo);
@ -64,9 +64,12 @@ extern int boot_yyparse(void);
extern int boot_yylex(void); extern int boot_yylex(void);
extern void boot_yyerror(const char *str); extern void boot_yyerror(const char *str);
#define BS_XLOG_NOP 0 typedef enum
#define BS_XLOG_BOOTSTRAP 1 {
#define BS_XLOG_STARTUP 2 CheckerProcess,
#define BS_XLOG_BGWRITER 3 BootstrapProcess,
StartupProcess,
BgWriterProcess
} AuxProcType;
#endif /* BOOTSTRAP_H */ #endif /* BOOTSTRAP_H */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.95 2007/03/03 18:46:40 momjian Exp $ * $PostgreSQL: pgsql/src/include/storage/proc.h,v 1.96 2007/03/07 13:35:03 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -118,10 +118,10 @@ typedef struct PROC_HDR
} PROC_HDR; } PROC_HDR;
/* /*
* We set aside some extra PGPROC structures for "dummy" processes, * We set aside some extra PGPROC structures for auxiliary processes,
* ie things that aren't full-fledged backends but need shmem access. * ie things that aren't full-fledged backends but need shmem access.
*/ */
#define NUM_DUMMY_PROCS 3 #define NUM_AUXILIARY_PROCS 3
/* configurable options */ /* configurable options */
@ -140,7 +140,7 @@ extern Size ProcGlobalShmemSize(void);
extern void InitProcGlobal(void); extern void InitProcGlobal(void);
extern void InitProcess(void); extern void InitProcess(void);
extern void InitProcessPhase2(void); extern void InitProcessPhase2(void);
extern void InitDummyProcess(void); extern void InitAuxiliaryProcess(void);
extern bool HaveNFreeProcs(int n); extern bool HaveNFreeProcs(int n);
extern void ProcReleaseLocks(bool isCommit); extern void ProcReleaseLocks(bool isCommit);

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.87 2007/02/20 17:32:17 tgl Exp $ * $PostgreSQL: pgsql/src/include/tcop/tcopprot.h,v 1.88 2007/03/07 13:35:03 alvherre Exp $
* *
* OLD COMMENTS * OLD COMMENTS
* This file was created so that other c files could get the two * This file was created so that other c files could get the two
@ -44,8 +44,6 @@ typedef enum
extern LogStmtLevel log_statement; extern LogStmtLevel log_statement;
#ifndef BOOTSTRAP_INCLUDE
extern List *pg_parse_and_rewrite(const char *query_string, extern List *pg_parse_and_rewrite(const char *query_string,
Oid *paramTypes, int numParams); Oid *paramTypes, int numParams);
extern List *pg_parse_query(const char *query_string); extern List *pg_parse_query(const char *query_string);
@ -56,7 +54,6 @@ extern List *pg_plan_queries(List *querytrees, ParamListInfo boundParams,
bool needSnapshot); bool needSnapshot);
extern bool assign_max_stack_depth(int newval, bool doit, GucSource source); extern bool assign_max_stack_depth(int newval, bool doit, GucSource source);
#endif /* BOOTSTRAP_INCLUDE */
extern void die(SIGNAL_ARGS); extern void die(SIGNAL_ARGS);
extern void quickdie(SIGNAL_ARGS); extern void quickdie(SIGNAL_ARGS);