1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +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/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 */