Commit 47937403 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

XLOG (also known as WAL -:)) Bootstrap/Startup/Shutdown.

First step in cleaning up backend initialization code.
Fix for FATAL: now FATAL is ERROR + exit.
parent 9dcd8c52
This diff is collapsed.
......@@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.68 1999/09/27 20:26:58 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.69 1999/10/06 21:58:02 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -39,6 +39,14 @@
#define ALLOC(t, c) (t *)calloc((unsigned)(c), sizeof(t))
#define FIRST_TYPE_OID 16 /* OID of the first type */
extern void BaseInit(void);
extern void StartupXLOG(void);
extern void ShutdownXLOG(void);
extern void BootStrapXLOG(void);
extern char XLogDir[];
extern char ControlFilePath[];
extern int Int_yyparse(void);
static hashnode *AddStr(char *str, int strlength, int mderef);
static Form_pg_attribute AllocateAttribute(void);
......@@ -218,22 +226,13 @@ BootstrapMain(int argc, char *argv[])
*/
{
int i;
int portFd = -1;
char *dbName;
int flag;
int override = 1; /* use BootstrapProcessing or
* InitProcessing mode */
bool xloginit = false;
extern int optind;
extern char *optarg;
/* ----------------
* initialize signal handlers
* ----------------
*/
pqsignal(SIGINT, (sig_func) die);
pqsignal(SIGHUP, (sig_func) die);
pqsignal(SIGTERM, (sig_func) die);
/* --------------------
* initialize globals
......@@ -252,8 +251,9 @@ BootstrapMain(int argc, char *argv[])
Noversion = false;
dbName = NULL;
DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
IsUnderPostmaster = false;
while ((flag = getopt(argc, argv, "D:dCOQP:F")) != EOF)
while ((flag = getopt(argc, argv, "D:dCQxpB:F")) != EOF)
{
switch (flag)
{
......@@ -270,14 +270,17 @@ BootstrapMain(int argc, char *argv[])
case 'F':
disableFsync = true;
break;
case 'O':
override = true;
break;
case 'Q':
Quiet = true;
break;
case 'P': /* specify port */
portFd = atoi(optarg);
case 'x':
xloginit = true;
break;
case 'p':
IsUnderPostmaster = true;
break;
case 'B':
NBuffers = atoi(optarg);
break;
default:
usage();
......@@ -290,6 +293,8 @@ BootstrapMain(int argc, char *argv[])
else if (argc - optind == 1)
dbName = argv[optind];
SetProcessingMode(BootstrapProcessing);
if (!DataDir)
{
fprintf(stderr, "%s does not know where to find the database system "
......@@ -311,24 +316,50 @@ BootstrapMain(int argc, char *argv[])
}
}
/* ----------------
* initialize input fd
* ----------------
BaseInit();
if (!IsUnderPostmaster)
{
pqsignal(SIGINT, (sig_func) die);
pqsignal(SIGHUP, (sig_func) die);
pqsignal(SIGTERM, (sig_func) die);
}
/*
* Bootstrap under Postmaster means two things:
* (xloginit) ? StartupXLOG : ShutdownXLOG
*
* If !under Postmaster and xloginit then BootStrapXLOG.
*/
if (IsUnderPostmaster && portFd < 0)
if (IsUnderPostmaster || xloginit)
{
fputs("backend: failed, no -P option with -postmaster opt.\n", stderr);
proc_exit(1);
sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR);
sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR);
}
/* ----------------
if (IsUnderPostmaster && xloginit)
{
StartupXLOG();
proc_exit(0);
}
if (!IsUnderPostmaster && xloginit)
{
BootStrapXLOG();
}
/*
* backend initialization
* ----------------
*/
SetProcessingMode((override) ? BootstrapProcessing : InitProcessing);
InitPostgres(dbName);
LockDisable(true);
if (IsUnderPostmaster && !xloginit)
{
ShutdownXLOG();
proc_exit(0);
}
for (i = 0; i < MAXATTR; i++)
{
attrtypes[i] = (Form_pg_attribute) NULL;
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.30 1999/09/24 00:24:29 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.31 1999/10/06 21:58:04 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -230,16 +230,18 @@ InitBufferPool(IPCKey key)
#ifndef HAS_TEST_AND_SET
{
int status;
extern IpcSemaphoreId WaitIOSemId;
extern IpcSemaphoreId WaitCLSemId;
WaitIOSemId = IpcSemaphoreCreate(IPCKeyGetWaitIOSemaphoreKey(key),
1, IPCProtection, 0, 1, &status);
1, IPCProtection, 0, 1);
if (WaitIOSemId < 0)
elog(FATAL, "InitBufferPool: IpcSemaphoreCreate(WaitIOSemId) failed");
WaitCLSemId = IpcSemaphoreCreate(IPCKeyGetWaitCLSemaphoreKey(key),
1, IPCProtection,
IpcSemaphoreDefaultStartValue,
1, &status);
IpcSemaphoreDefaultStartValue, 1);
if (WaitCLSemId < 0)
elog(FATAL, "InitBufferPool: IpcSemaphoreCreate(WaitCLSemId) failed");
}
#endif
PrivateRefCount = (long *) calloc(NBuffers, sizeof(long));
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.38 1999/07/17 20:17:43 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.39 1999/10/06 21:58:06 vadim Exp $
*
* NOTES
*
......@@ -284,18 +284,6 @@ IPCPrivateMemoryKill(int status,
}
}
/****************************************************************************/
/* IpcSemaphoreCreate(semKey, semNum, permission, semStartValue) */
/* */
/* - returns a semaphore identifier: */
/* */
/* if key doesn't exist: return a new id, status:= IpcSemIdNotExist */
/* if key exists: return the old id, status:= IpcSemIdExist */
/* if semNum > MAX : return # of argument, status:=IpcInvalidArgument */
/* */
/****************************************************************************/
/*
* Note:
* XXX This should be split into two different calls. One should
......@@ -312,8 +300,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
int semNum,
int permission,
int semStartValue,
int removeOnExit,
int *status)
int removeOnExit)
{
int i;
int errStatus;
......@@ -321,20 +308,14 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
u_short array[IPC_NMAXSEM];
union semun semun;
/* get a semaphore if non-existent */
/* check arguments */
if (semNum > IPC_NMAXSEM || semNum <= 0)
{
*status = IpcInvalidArgument;
return 2; /* returns the number of the invalid
* argument */
}
return(-1);
semId = semget(semKey, 0, 0);
if (semId == -1)
{
*status = IpcSemIdNotExist; /* there doesn't exist a semaphore */
#ifdef DEBUG_IPC
EPRINTF("calling semget with %d, %d , %d\n",
semKey,
......@@ -348,7 +329,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
EPRINTF("IpcSemaphoreCreate: semget failed (%s) "
"key=%d, num=%d, permission=%o",
strerror(errno), semKey, semNum, permission);
proc_exit(3);
return(-1);
}
for (i = 0; i < semNum; i++)
array[i] = semStartValue;
......@@ -358,22 +339,16 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
{
EPRINTF("IpcSemaphoreCreate: semctl failed (%s) id=%d",
strerror(errno), semId);
semctl(semId, 0, IPC_RMID, semun);
return(-1);
}
if (removeOnExit)
on_shmem_exit(IPCPrivateSemaphoreKill, (caddr_t) semId);
}
else
{
/* there is a semaphore id for this key */
*status = IpcSemIdExist;
}
#ifdef DEBUG_IPC
EPRINTF("\nIpcSemaphoreCreate, status %d, returns %d\n",
*status,
semId);
EPRINTF("\nIpcSemaphoreCreate, returns %d\n", semId);
fflush(stdout);
fflush(stderr);
#endif
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.30 1999/07/17 20:17:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.31 1999/10/06 21:58:06 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -54,17 +54,17 @@ void
CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
{
int size;
extern int XLOGShmemSize(void);
extern void XLOGShmemInit(void);
#ifdef HAS_TEST_AND_SET
/* ---------------
* create shared memory for slocks
* --------------
/*
* Create shared memory for slocks
*/
CreateAndInitSLockMemory(IPCKeyGetSLockSharedMemoryKey(key));
#endif
/* ----------------
* kill and create the buffer manager buffer pool (and semaphore)
* ----------------
/*
* Kill and create the buffer manager buffer pool (and semaphore)
*/
CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key));
......@@ -73,7 +73,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
* moderately-accurate estimates for the big hogs, plus 100K for the
* stuff that's too small to bother with estimating.
*/
size = BufferShmemSize() + LockShmemSize(maxBackends);
size = BufferShmemSize() + LockShmemSize(maxBackends) + XLOGShmemSize();
#ifdef STABLE_MEMORY_STORAGE
size += MMShmemSize();
#endif
......@@ -89,6 +89,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
ShmemCreate(IPCKeyGetBufferMemoryKey(key), size);
ShmemIndexReset();
InitShmem(key, size);
XLOGShmemInit();
InitBufferPool(key);
/* ----------------
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.46 1999/09/24 00:24:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.47 1999/10/06 21:58:06 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -187,8 +187,7 @@ InitShmem(unsigned int key, unsigned int size)
* bootstrap initialize spin locks so we can start to use the
* allocator and shmem index.
*/
if (!InitSpinLocks(ShmemBootstrap, IPCKeyGetSpinLockSemaphoreKey(key)))
return FALSE;
InitSpinLocks();
/*
* We have just allocated additional space for two spinlocks. Now
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.20 1999/07/16 04:59:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.21 1999/10/06 21:58:06 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -40,15 +40,15 @@ IpcSemaphoreId SpinLockId;
#ifdef HAS_TEST_AND_SET
/* real spin lock implementations */
bool
void
CreateSpinlocks(IPCKey key)
{
/* the spin lock shared memory must have been created by now */
return TRUE;
return;
}
bool
InitSpinLocks(int init, IPCKey key)
void
InitSpinLocks(void)
{
extern SPINLOCK ShmemLock;
extern SPINLOCK ShmemIndexLock;
......@@ -57,7 +57,8 @@ InitSpinLocks(int init, IPCKey key)
extern SPINLOCK ProcStructLock;
extern SPINLOCK SInvalLock;
extern SPINLOCK OidGenLockId;
extern SPINLOCK XidGenLockId;
extern SPINLOCK ControlFileLockId;
#ifdef STABLE_MEMORY_STORAGE
extern SPINLOCK MMCacheLock;
......@@ -71,12 +72,14 @@ InitSpinLocks(int init, IPCKey key)
ProcStructLock = (SPINLOCK) PROCSTRUCTLOCKID;
SInvalLock = (SPINLOCK) SINVALLOCKID;
OidGenLockId = (SPINLOCK) OIDGENLOCKID;
XidGenLockId = (SPINLOCK) XIDGENLOCKID;
ControlFileLockId = (SPINLOCK) CNTLFILELOCKID;
#ifdef STABLE_MEMORY_STORAGE
MMCacheLock = (SPINLOCK) MMCACHELOCKID;
#endif
return TRUE;
return;
}
#ifdef LOCKDEBUG
......@@ -224,55 +227,17 @@ SpinIsLocked(SPINLOCK lock)
* the spinlocks
*
*/
bool
void
CreateSpinlocks(IPCKey key)
{
int status;
IpcSemaphoreId semid;
semid = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection,
IpcSemaphoreDefaultStartValue, 1, &status);
if (status == IpcSemIdExist)
{
IpcSemaphoreKill(key);
elog(NOTICE, "Destroying old spinlock semaphore");
semid = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection,
IpcSemaphoreDefaultStartValue, 1, &status);
}
if (semid >= 0)
{
SpinLockId = semid;
return TRUE;
}
/* cannot create spinlocks */
elog(FATAL, "CreateSpinlocks: cannot create spin locks");
return FALSE;
}
SpinLockId = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection,
IpcSemaphoreDefaultStartValue, 1);
/*
* Attach to existing spinlock set
*/
static bool
AttachSpinLocks(IPCKey key)
{
IpcSemaphoreId id;
if (SpinLockId <= 0)
elog(STOP, "CreateSpinlocks: cannot create spin locks");
id = semget(key, MAX_SPINS, 0);
if (id < 0)
{
if (errno == EEXIST)
{
/* key is the name of someone else's semaphore */
elog(FATAL, "AttachSpinlocks: SPIN_KEY belongs to someone else");
}
/* cannot create spinlocks */
elog(FATAL, "AttachSpinlocks: cannot create spin locks");
return FALSE;
}
SpinLockId = id;
return TRUE;
return;
}
/*
......@@ -287,8 +252,8 @@ AttachSpinLocks(IPCKey key)
* (SJCacheLock) for it. Same story for the main memory storage mgr.
*
*/
bool
InitSpinLocks(int init, IPCKey key)
void
InitSpinLocks(void)
{
extern SPINLOCK ShmemLock;
extern SPINLOCK ShmemIndexLock;
......@@ -297,26 +262,14 @@ InitSpinLocks(int init, IPCKey key)
extern SPINLOCK ProcStructLock;
extern SPINLOCK SInvalLock;
extern SPINLOCK OidGenLockId;
extern SPINLOCK XidGenLockId;
extern SPINLOCK ControlFileLockId;
#ifdef STABLE_MEMORY_STORAGE
extern SPINLOCK MMCacheLock;
#endif
if (!init || key != IPC_PRIVATE)
{
/*
* if bootstrap and key is IPC_PRIVATE, it means that we are
* running backend by itself. no need to attach spinlocks
*/
if (!AttachSpinLocks(key))
{
elog(FATAL, "InitSpinLocks: couldnt attach spin locks");
return FALSE;
}
}
/* These five (or six) spinlocks have fixed location is shmem */
ShmemLock = (SPINLOCK) SHMEMLOCKID;
ShmemIndexLock = (SPINLOCK) SHMEMINDEXLOCKID;
......@@ -325,12 +278,14 @@ InitSpinLocks(int init, IPCKey key)
ProcStructLock = (SPINLOCK) PROCSTRUCTLOCKID;
SInvalLock = (SPINLOCK) SINVALLOCKID;
OidGenLockId = (SPINLOCK) OIDGENLOCKID;
XidGenLockId = (SPINLOCK) XIDGENLOCKID;
ControlFileLockId = (SPINLOCK) CNTLFILELOCKID;
#ifdef STABLE_MEMORY_STORAGE
MMCacheLock = (SPINLOCK) MMCACHELOCKID;
#endif
return TRUE;
return;
}
#endif /* HAS_TEST_AND_SET */
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.61 1999/09/24 00:24:41 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.62 1999/10/06 21:58:07 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -46,7 +46,7 @@
* This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95
*
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.61 1999/09/24 00:24:41 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.62 1999/10/06 21:58:07 vadim Exp $
*/
#include <sys/time.h>
#include <unistd.h>
......@@ -70,7 +70,7 @@
#include "storage/proc.h"
#include "utils/trace.h"
static void HandleDeadLock(int sig);
void HandleDeadLock(SIGNAL_ARGS);
static void ProcFreeAllSemaphores(void);
#define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
......@@ -84,12 +84,6 @@ static void ProcFreeAllSemaphores(void);
*/
SPINLOCK ProcStructLock;
/*
* For cleanup routines. Don't cleanup if the initialization
* has not happened.
*/
static bool ProcInitialized = FALSE;
static PROC_HDR *ProcGlobal = NULL;
PROC *MyProc = NULL;
......@@ -167,8 +161,9 @@ InitProcGlobal(IPCKey key, int maxBackends)
PROC_NSEMS_PER_SET,
IPCProtection,
IpcSemaphoreDefaultStartValue,
0,
&semstat);
0);
if (semId < 0)
elog(FATAL, "InitProcGlobal: IpcSemaphoreCreate failed");
/* mark this sema set allocated */
ProcGlobal->freeSemMap[i] = (1 << PROC_NSEMS_PER_SET);
}
......@@ -189,12 +184,6 @@ InitProcess(IPCKey key)
unsigned long location,
myOffset;
/* ------------------
* Routine called if deadlock timer goes off. See ProcSleep()
* ------------------
*/
pqsignal(SIGALRM, HandleDeadLock);
SpinAcquire(ProcStructLock);
/* attach to the free list */
......@@ -203,7 +192,7 @@ InitProcess(IPCKey key)
if (!found)
{
/* this should not happen. InitProcGlobal() is called before this. */
elog(ERROR, "InitProcess: Proc Header uninitialized");
elog(STOP, "InitProcess: Proc Header uninitialized");
}
if (MyProc != NULL)
......@@ -271,8 +260,7 @@ InitProcess(IPCKey key)
PROC_NSEMS_PER_SET,
IPCProtection,
IpcSemaphoreDefaultStartValue,
0,
&semstat);
0);
/*
* we might be reusing a semaphore that belongs to a dead backend.
......@@ -316,14 +304,12 @@ InitProcess(IPCKey key)
*/
location = MAKE_OFFSET(MyProc);
if ((!ShmemPIDLookup(MyProcPid, &location)) || (location != MAKE_OFFSET(MyProc)))
elog(FATAL, "InitProc: ShmemPID table broken");
elog(STOP, "InitProc: ShmemPID table broken");
MyProc->errType = NO_ERROR;
SHMQueueElemInit(&(MyProc->links));
on_shmem_exit(ProcKill, (caddr_t) MyProcPid);
ProcInitialized = TRUE;
}
/*
......@@ -755,8 +741,8 @@ ProcAddLock(SHM_QUEUE *elem)
* up my semaphore.
* --------------------
*/
static void
HandleDeadLock(int sig)
void
HandleDeadLock(SIGNAL_ARGS)
{
LOCK *mywaitlock;
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.48 1999/09/11 19:06:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.49 1999/10/06 21:58:09 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -37,6 +37,7 @@
extern int errno;
extern int sys_nerr;
extern CommandDest whereToSendOutput;
#ifdef USE_SYSLOG
/*
......@@ -107,6 +108,19 @@ elog(int lev, const char *fmt, ...)
if (lev <= DEBUG && Debugfile < 0)
return; /* ignore debug msgs if noplace to send */
if (lev == ERROR || lev == FATAL)
{
if (IsInitProcessingMode())
{
extern TransactionState CurrentTransactionState;
if (CurrentTransactionState->state != TRANS_DEFAULT &&
CurrentTransactionState->state != TRANS_DISABLED)
abort();
lev = FATAL;
}
}
/* choose message prefix and indent level */
switch (lev)
{
......@@ -304,7 +318,7 @@ elog(int lev, const char *fmt, ...)
#ifndef PG_STANDALONE
if (lev > DEBUG && IsUnderPostmaster)
if (lev > DEBUG && whereToSendOutput == Remote)
{
/* Send IPC message to the front-end program */
char msgtype;
......@@ -336,7 +350,7 @@ elog(int lev, const char *fmt, ...)
pq_flush();
}
if (lev > DEBUG && ! IsUnderPostmaster)
if (lev > DEBUG && whereToSendOutput != Remote)
{
/* We are running as an interactive backend, so just send
* the message to stderr.
......@@ -355,30 +369,23 @@ elog(int lev, const char *fmt, ...)
/*
* Perform error recovery action as specified by lev.
*/
if (lev == ERROR)
if (lev == ERROR || lev == FATAL)
{
if (InError)
{
/* error reported during error recovery; don't loop forever */
elog(REALLYFATAL, "elog: error during error recovery, giving up!");
}
/* exit to main loop */
InError = true;
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
siglongjmp(Warn_restart, 1);
}
if (lev == FATAL)
{
/*
* Assume that if we have detected the failure we can exit with a
* normal exit status. This will prevent the postmaster from
* cleaning up when it's not needed.
*/
fflush(stdout);
fflush(stderr);
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
ProcReleaseLocks(); /* get rid of real locks we hold */
proc_exit(0);
if (IsInitProcessingMode())
ExitPostgres(0);
ExitAfterAbort = true;
}
/* exit to main loop */
siglongjmp(Warn_restart, 1);
}
if (lev > FATAL)
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.34 1999/07/17 20:18:08 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.35 1999/10/06 21:58:10 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -133,20 +133,7 @@ StatusPostmasterExit(int status)
* processing mode support stuff (used to be in pmod.c)
* ----------------------------------------------------------------
*/
static ProcessingMode Mode = NoProcessing;
#ifdef NOT_USED
/*
* IsNoProcessingMode
* True iff processing mode is NoProcessing.
*/
bool
IsNoProcessingMode()
{
return (bool) (Mode == NoProcessing);
}
#endif
static ProcessingMode Mode = InitProcessing;
/*
* IsBootstrapProcessingMode
......@@ -186,13 +173,13 @@ IsNormalProcessingMode()
* BadArg if called with invalid mode.
*
* Note:
* Mode is NoProcessing before the first time this is called.
* Mode is InitProcessing before the first time this is called.
*/
void
SetProcessingMode(ProcessingMode mode)
{
AssertArg(mode == NoProcessing || mode == BootstrapProcessing ||
mode == InitProcessing || mode == NormalProcessing);
AssertArg(mode == BootstrapProcessing || mode == InitProcessing ||
mode == NormalProcessing);
Mode = mode;
}
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.50 1999/09/28 11:41:09 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.51 1999/10/06 21:58:10 vadim Exp $
*
* NOTES
* InitPostgres() is the function called from PostgresMain
......@@ -53,12 +53,13 @@
#include "mb/pg_wchar.h"
#endif
void BaseInit(void);
static void VerifySystemDatabase(void);
static void VerifyMyDatabase(void);
static void ReverifyMyDatabase(char *name);
static void InitCommunication(void);
static void InitMyDatabaseInfo(char *name);
static void InitStdio(void);
static void InitUserid(void);
......@@ -385,37 +386,6 @@ InitCommunication()
{
if (MyBackendTag == -1)
elog(FATAL, "InitCommunication: missing POSTID");
/*
* Enable this if you are trying to force the backend to run as if
* it is running under the postmaster.
*
* This goto forces Postgres to attach to shared memory instead of
* using malloc'ed memory (which is the normal behavior if run
* directly).
*
* To enable emulation, run the following shell commands (in addition
* to enabling this goto)
*
* % setenv POSTID 1 % setenv POSTPORT 4321 % setenv IPC_KEY 4321000
* % postmaster & % kill -9 %1
*
* Upon doing this, Postmaster will have allocated the shared memory
* resources that Postgres will attach to if you enable
* EMULATE_UNDER_POSTMASTER.
*
* This comment may well age with time - it is current as of 8
* January 1990
*
* Greg
*/
#ifdef EMULATE_UNDER_POSTMASTER
goto forcesharedmemory;
#endif
}
else if (IsUnderPostmaster)
{
......@@ -439,12 +409,6 @@ InitCommunication()
* initialize shared memory and semaphores appropriately.
* ----------------
*/
#ifdef EMULATE_UNDER_POSTMASTER
forcesharedmemory:
#endif
if (!IsUnderPostmaster) /* postmaster already did this */
{
PostgresIpcKey = key;
......@@ -452,21 +416,6 @@ forcesharedmemory:
}
}
/* --------------------------------
* InitStdio
*
* this routine consists of a bunch of code fragments
* that used to be randomly scattered through cinit().
* they all seem to do stuff associated with io.
* --------------------------------
*/
static void
InitStdio()
{
DebugFileOpen();
}
/* --------------------------------
* InitPostgres
* Initialize POSTGRES.
......@@ -477,8 +426,6 @@ InitStdio()
*/
extern int NBuffers;
bool PostgresIsInitialized = false;
int lockingOff = 0; /* backend -L switch */
/*
......@@ -488,37 +435,11 @@ InitPostgres(char *name) /* database name */
{
bool bootstrap; /* true if BootstrapProcessing */
/* ----------------
* see if we're running in BootstrapProcessing mode
* ----------------
/*
* See if we're running in BootstrapProcessing mode
*/
bootstrap = IsBootstrapProcessingMode();
/* ----------------
* turn on the exception handler. Note: we cannot use elog, Assert,
* AssertState, etc. until after exception handling is on.
* ----------------
*/
EnableExceptionHandling(true);
/* ----------------
* A stupid check to make sure we don't call this more than once.
* But things like ReinitPostgres() get around this by just diddling
* the PostgresIsInitialized flag.
* ----------------
*/
AssertState(!PostgresIsInitialized);
/* ----------------
* Memory system initialization.
* (we may call palloc after EnableMemoryContext())
*
* Note EnableMemoryContext() must happen before EnablePortalManager().
* ----------------
*/
EnableMemoryContext(true); /* initializes the "top context" */
EnablePortalManager(true); /* memory for portal/transaction stuff */
/* ----------------
* initialize the backend local portal stack used by
* internal PQ function calls. see src/lib/libpq/be-dumpdata.c
......@@ -528,14 +449,6 @@ InitPostgres(char *name) /* database name */
*/
be_portalinit();
/* ----------------
* attach to shared memory and semaphores, and initialize our
* input/output/debugging file descriptors.
* ----------------
*/
InitCommunication();
InitStdio();
/*
* initialize the local buffer manager
*/
......@@ -574,13 +487,9 @@ InitPostgres(char *name) /* database name */
* Will try that, but may not work... - thomas 1997-11-01
*/
/* Does not touch files (?) - thomas 1997-11-01 */
smgrinit();
/* ----------------
* initialize the transaction system and the relation descriptor cache.
/*
* Initialize the transaction system and the relation descriptor cache.
* Note we have to make certain the lock manager is off while we do this.
* ----------------
*/
AmiTransactionOverride(IsBootstrapProcessingMode());
LockDisable(true);
......@@ -598,20 +507,18 @@ InitPostgres(char *name) /* database name */
LockDisable(false);
/* ----------------
/*
* Set up my per-backend PROC struct in shared memory.
* ----------------
*/
InitProcess(PostgresIpcKey);
/* ----------------
/*
* Initialize my entry in the shared-invalidation manager's
* array of per-backend data. (Formerly this came before
* InitProcess, but now it must happen after, because it uses
* MyProc.) Once I have done this, I am visible to other backends!
*
* Sets up MyBackendId, a unique backend identifier.
* ----------------
*/
InitSharedInvalidationState();
......@@ -622,16 +529,14 @@ InitPostgres(char *name) /* database name */
MyBackendId);
}
/* ----------------
* initialize the access methods.
/*
* Initialize the access methods.
* Does not touch files (?) - thomas 1997-11-01
* ----------------
*/
initam();
/* ----------------
* initialize all the system catalog caches.
* ----------------
/*
* Initialize all the system catalog caches.
*/
zerocaches();
......@@ -641,34 +546,19 @@ InitPostgres(char *name) /* database name */
*/
InitCatalogCache();
/* ----------------
* set ourselves to the proper user id and figure out our postgres
/*
* Set ourselves to the proper user id and figure out our postgres
* user id. If we ever add security so that we check for valid
* postgres users, we might do it here.
* ----------------
*/
InitUserid();
/* ----------------
* initialize local data in cache invalidation stuff
* ----------------
/*
* Initialize local data in cache invalidation stuff
*/
if (!bootstrap)
InitLocalInvalidateData();
/* ----------------
* ok, all done, now let's make sure we don't do it again.
* ----------------
*/
PostgresIsInitialized = true;
/* ----------------
* Done with "InitPostgres", now change to NormalProcessing unless
* we're in BootstrapProcessing mode.
* ----------------
*/
if (!bootstrap)
SetProcessingMode(NormalProcessing);
if (lockingOff)
LockDisable(true);
......@@ -680,3 +570,30 @@ InitPostgres(char *name) /* database name */
if (!bootstrap)
ReverifyMyDatabase(name);
}
void
BaseInit(void)
{
/*
* Turn on the exception handler. Note: we cannot use elog, Assert,
* AssertState, etc. until after exception handling is on.
*/
EnableExceptionHandling(true);
/*
* Memory system initialization - we may call palloc after
* EnableMemoryContext()). Note that EnableMemoryContext()
* must happen before EnablePortalManager().
*/
EnableMemoryContext(true); /* initializes the "top context" */
EnablePortalManager(true); /* memory for portal/transaction stuff */
/*
* Attach to shared memory and semaphores, and initialize our
* input/output/debugging file descriptors.
*/
InitCommunication();
DebugFileOpen();
smgrinit();
}
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.31 1999/07/15 22:40:15 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.32 1999/10/06 21:58:11 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -18,8 +18,6 @@
#include "utils/tqual.h"
extern bool PostgresIsInitialized;
SnapshotData SnapshotDirtyData;
Snapshot SnapshotDirty = &SnapshotDirtyData;
......@@ -194,17 +192,6 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
if (AMI_OVERRIDE)
return true;
/*
* If the transaction system isn't yet initialized, then we assume
* that transactions committed. We only look at system catalogs
* during startup, so this is less awful than it seems, but it's still
* pretty awful.
*/
if (!PostgresIsInitialized)
return ((bool) (TransactionIdIsValid(tuple->t_xmin) &&
!TransactionIdIsValid(tuple->t_xmax)));
if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
{
if (tuple->t_infomask & HEAP_XMIN_INVALID)
......
......@@ -26,7 +26,7 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.60 1999/05/20 16:50:06 wieck Exp $
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.61 1999/10/06 21:58:12 vadim Exp $
#
#-------------------------------------------------------------------------
......@@ -300,6 +300,12 @@ else
mkdir $PGDATA/base
if [ $? -ne 0 ]; then exit 5; fi
fi
if [ ! -d $PGDATA/pg_xlog ]; then
echo "Creating Postgres database XLOG directory $PGDATA/pg_xlog"
echo
mkdir $PGDATA/pg_xlog
if [ $? -ne 0 ]; then exit 5; fi
fi
fi
#----------------------------------------------------------------------------
......@@ -316,6 +322,7 @@ else
fi
BACKENDARGS="-boot -C -F -D$PGDATA $BACKEND_TALK_ARG"
FIRSTRUN="-boot -x -C -F -D$PGDATA $BACKEND_TALK_ARG"
echo "Creating template database in $PGDATA/base/template1"
[ "$debug" -ne 0 ] && echo "Running: postgres $BACKENDARGS template1"
......@@ -323,7 +330,7 @@ echo "Creating template database in $PGDATA/base/template1"
cat $TEMPLATE \
| sed -e "s/postgres PGUID/$POSTGRES_SUPERUSERNAME $POSTGRES_SUPERUID/" \
-e "s/PGUID/$POSTGRES_SUPERUID/" \
| postgres $BACKENDARGS template1
| postgres $FIRSTRUN template1
if [ $? -ne 0 ]; then
echo "$CMDNAME: could not create template database"
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pqsignal.h,v 1.9 1999/02/13 23:21:36 momjian Exp $
* $Id: pqsignal.h,v 1.10 1999/10/06 21:58:16 vadim Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
......@@ -17,6 +17,28 @@
#ifndef PQSIGNAL_H
#define PQSIGNAL_H
#ifdef HAVE_SIGPROCMASK
extern sigset_t UnBlockSig,
BlockSig;
#define PG_INITMASK() ( \
sigemptyset(&UnBlockSig), \
sigfillset(&BlockSig) \
)
#define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL)
#else
extern int UnBlockSig,
BlockSig;
#define PG_INITMASK() ( \
UnBlockSig = 0, \
BlockSig = sigmask(SIGHUP) | sigmask(SIGQUIT) | \
sigmask(SIGTERM) | sigmask(SIGALRM) | \
sigmask(SIGINT) | sigmask(SIGUSR1) | \
sigmask(SIGUSR2) | sigmask(SIGCHLD) | \
sigmask(SIGWINCH) | sigmask(SIGFPE) \
)
#define PG_SETMASK(mask) sigsetmask(*((int*)(mask)))
#endif
typedef void (*pqsigfunc) (int);
extern pqsigfunc pqsignal(int signo, pqsigfunc func);
......
......@@ -11,7 +11,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: miscadmin.h,v 1.42 1999/09/27 20:27:26 momjian Exp $
* $Id: miscadmin.h,v 1.43 1999/10/06 21:58:13 vadim Exp $
*
* NOTES
* some of the information in this file will be moved to
......@@ -143,28 +143,25 @@ extern int CheckPathAccess(char *path, char *name, int open_mode);
*****************************************************************************/
/*
* Description:
* There are four processing modes in POSTGRES. They are NoProcessing
* or "none," BootstrapProcessing or "bootstrap," InitProcessing or
* There are three processing modes in POSTGRES. They are
* "BootstrapProcessing or "bootstrap," InitProcessing or
* "initialization," and NormalProcessing or "normal."
*
* If a POSTGRES binary is in normal mode, then all code may be executed
* normally. In the none mode, only bookkeeping code may be called. In
* particular, access method calls may not occur in this mode since the
* execution state is outside a transaction.
*
* The final two processing modes are used during special times. When the
* The first two processing modes are used during special times. When the
* system state indicates bootstrap processing, transactions are all given
* transaction id "one" and are consequently guarenteed to commit. This mode
* is used during the initial generation of template databases.
*
* Finally, the execution state is in initialization mode until all normal
* initialization is complete. Some code behaves differently when executed in
* this mode to enable system bootstrapping.
* Initialization mode until all normal initialization is complete.
* Some code behaves differently when executed in this mode to enable
* system bootstrapping.
*
* If a POSTGRES binary is in normal mode, then all code may be executed
* normally.
*/
typedef enum ProcessingMode
{
NoProcessing, /* "nothing" can be done */
BootstrapProcessing, /* bootstrap creation of template database */
InitProcessing, /* initializing system */
NormalProcessing /* normal processing */
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: ipc.h,v 1.35 1999/07/15 23:04:10 momjian Exp $
* $Id: ipc.h,v 1.36 1999/10/06 21:58:17 vadim Exp $
*
* NOTES
* This file is very architecture-specific. This stuff should actually
......@@ -79,7 +79,7 @@ extern void on_exit_reset(void);
extern IpcSemaphoreId IpcSemaphoreCreate(IpcSemaphoreKey semKey,
int semNum, int permission, int semStartValue,
int removeOnExit, int *status);
int removeOnExit);
extern void IpcSemaphoreKill(IpcSemaphoreKey key);
extern void IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock);
extern void IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock);
......@@ -105,6 +105,8 @@ typedef enum _LockId_
BUFMGRLOCKID,
LOCKLOCKID,
OIDGENLOCKID,
XIDGENLOCKID,
CNTLFILELOCKID,
SHMEMLOCKID,
SHMEMINDEXLOCKID,
LOCKMGRLOCKID,
......@@ -147,6 +149,8 @@ typedef enum _LockId_
PROCSTRUCTLOCKID,
OIDGENLOCKID,
XIDGENLOCKID,
CNTLFILELOCKID,
FIRSTFREELOCKID
} _LockId_;
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: spin.h,v 1.9 1999/07/15 23:04:16 momjian Exp $
* $Id: spin.h,v 1.10 1999/10/06 21:58:17 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -27,8 +27,8 @@
typedef int SPINLOCK;
extern bool CreateSpinlocks(IPCKey key);
extern bool InitSpinLocks(int init, IPCKey key);
extern void CreateSpinlocks(IPCKey key);
extern void InitSpinLocks(void);
extern void SpinAcquire(SPINLOCK lockid);
extern void SpinRelease(SPINLOCK lockid);
......
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: tcopprot.h,v 1.21 1999/05/26 12:56:58 momjian Exp $
* $Id: tcopprot.h,v 1.22 1999/10/06 21:58:18 vadim Exp $
*
* OLD COMMENTS
* This file was created so that other c files could get the two
......@@ -38,6 +38,7 @@
#endif
extern DLLIMPORT sigjmp_buf Warn_restart;
extern bool InError;
extern bool ExitAfterAbort;
#ifndef BOOTSTRAP_INCLUDE
extern List *pg_parse_and_plan(char *query_string, Oid *typev, int nargs,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment