1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

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

First step in cleaning up backend initialization code.
Fix for FATAL: now FATAL is ERROR + exit.
This commit is contained in:
Vadim B. Mikheev
1999-10-06 21:58:18 +00:00
parent 9dcd8c528f
commit 4793740367
20 changed files with 1158 additions and 1015 deletions

View File

@@ -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));

View File

@@ -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

View File

@@ -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);
/* ----------------

View File

@@ -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

View File

@@ -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;
SpinLockId = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection,
IpcSemaphoreDefaultStartValue, 1);
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 (SpinLockId <= 0)
elog(STOP, "CreateSpinlocks: cannot create spin locks");
if (semid >= 0)
{
SpinLockId = semid;
return TRUE;
}
/* cannot create spinlocks */
elog(FATAL, "CreateSpinlocks: cannot create spin locks");
return FALSE;
}
/*
* Attach to existing spinlock set
*/
static bool
AttachSpinLocks(IPCKey key)
{
IpcSemaphoreId id;
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 */

View File

@@ -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;