Commit 36839c19 authored by Tom Lane's avatar Tom Lane

Restructure backend SIGINT/SIGTERM handling so that 'die' interrupts

are treated more like 'cancel' interrupts: the signal handler sets a
flag that is examined at well-defined spots, rather than trying to cope
with an interrupt that might happen anywhere.  See pghackers discussion
of 1/12/01.
parent 027f144e
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.73 2001/01/12 21:53:55 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.74 2001/01/14 05:08:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "access/nbtree.h" #include "access/nbtree.h"
#include "miscadmin.h"
typedef struct typedef struct
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.92 2001/01/12 21:53:56 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.93 2001/01/14 05:08:14 tgl Exp $
* *
* NOTES * NOTES
* Transaction aborts can now occur two ways: * Transaction aborts can now occur two ways:
...@@ -1015,6 +1015,9 @@ CommitTransaction(void) ...@@ -1015,6 +1015,9 @@ CommitTransaction(void)
if (s->state != TRANS_INPROGRESS) if (s->state != TRANS_INPROGRESS)
elog(NOTICE, "CommitTransaction and not in in-progress state "); elog(NOTICE, "CommitTransaction and not in in-progress state ");
/* Prevent cancel/die interrupt while cleaning up */
START_CRIT_SECTION();
/* ---------------- /* ----------------
* Tell the trigger manager that this transaction is about to be * Tell the trigger manager that this transaction is about to be
* committed. He'll invoke all trigger deferred until XACT before * committed. He'll invoke all trigger deferred until XACT before
...@@ -1083,6 +1086,8 @@ CommitTransaction(void) ...@@ -1083,6 +1086,8 @@ CommitTransaction(void)
* ---------------- * ----------------
*/ */
s->state = TRANS_DEFAULT; s->state = TRANS_DEFAULT;
END_CRIT_SECTION();
} }
/* -------------------------------- /* --------------------------------
...@@ -1095,6 +1100,9 @@ AbortTransaction(void) ...@@ -1095,6 +1100,9 @@ AbortTransaction(void)
{ {
TransactionState s = CurrentTransactionState; TransactionState s = CurrentTransactionState;
/* Prevent cancel/die interrupt while cleaning up */
START_CRIT_SECTION();
/* /*
* Let others to know about no transaction in progress - vadim * Let others to know about no transaction in progress - vadim
* 11/26/96 * 11/26/96
...@@ -1113,13 +1121,21 @@ AbortTransaction(void) ...@@ -1113,13 +1121,21 @@ AbortTransaction(void)
*/ */
ProcReleaseSpins(NULL); ProcReleaseSpins(NULL);
UnlockBuffers(); UnlockBuffers();
/*
* Also clean up any open wait for lock, since the lock manager
* will choke if we try to wait for another lock before doing this.
*/
LockWaitCancel();
/* ---------------- /* ----------------
* check the current transaction state * check the current transaction state
* ---------------- * ----------------
*/ */
if (s->state == TRANS_DISABLED) if (s->state == TRANS_DISABLED)
{
END_CRIT_SECTION();
return; return;
}
if (s->state != TRANS_INPROGRESS) if (s->state != TRANS_INPROGRESS)
elog(NOTICE, "AbortTransaction and not in in-progress state"); elog(NOTICE, "AbortTransaction and not in in-progress state");
...@@ -1169,6 +1185,7 @@ AbortTransaction(void) ...@@ -1169,6 +1185,7 @@ AbortTransaction(void)
* State remains TRANS_ABORT until CleanupTransaction(). * State remains TRANS_ABORT until CleanupTransaction().
* ---------------- * ----------------
*/ */
END_CRIT_SECTION();
} }
/* -------------------------------- /* --------------------------------
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.49 2001/01/12 21:53:56 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.50 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
int XLOGbuffers = 8; int XLOGbuffers = 8;
int XLOGfiles = 0; /* how many files to pre-allocate */ int XLOGfiles = 0; /* how many files to pre-allocate */
XLogRecPtr MyLastRecPtr = {0, 0}; XLogRecPtr MyLastRecPtr = {0, 0};
volatile uint32 CritSectionCount = 0;
bool InRecovery = false; bool InRecovery = false;
StartUpID ThisStartUpID = 0; StartUpID ThisStartUpID = 0;
XLogRecPtr RedoRecPtr; XLogRecPtr RedoRecPtr;
......
...@@ -8,7 +8,7 @@ ...@@ -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
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.102 2000/12/28 13:00:12 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.103 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -329,9 +329,10 @@ BootstrapMain(int argc, char *argv[]) ...@@ -329,9 +329,10 @@ BootstrapMain(int argc, char *argv[])
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
pqsignal(SIGINT, (pqsigfunc) die); pqsignal(SIGHUP, die);
pqsignal(SIGHUP, (pqsigfunc) die); pqsignal(SIGINT, die);
pqsignal(SIGTERM, (pqsigfunc) die); pqsignal(SIGTERM, die);
pqsignal(SIGQUIT, die);
} }
/* /*
...@@ -383,8 +384,6 @@ BootstrapMain(int argc, char *argv[]) ...@@ -383,8 +384,6 @@ BootstrapMain(int argc, char *argv[])
* abort processing resumes here * abort processing resumes here
* ---------------- * ----------------
*/ */
pqsignal(SIGHUP, handle_warn);
if (sigsetjmp(Warn_restart, 1) != 0) if (sigsetjmp(Warn_restart, 1) != 0)
{ {
Warnings++; Warnings++;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.10 2000/12/02 19:38:34 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.11 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,8 +72,7 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL) ...@@ -72,8 +72,7 @@ analyze_rel(Oid relid, List *anal_cols2, int MESSAGE_LEVEL)
* Check for user-requested abort. Note we want this to be inside a * Check for user-requested abort. Note we want this to be inside a
* transaction, so xact.c doesn't issue useless NOTICE. * transaction, so xact.c doesn't issue useless NOTICE.
*/ */
if (QueryCancel) CHECK_FOR_INTERRUPTS();
CancelQuery();
/* /*
* Race condition -- if the pg_class tuple has gone away since the * Race condition -- if the pg_class tuple has gone away since the
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.128 2001/01/06 03:33:17 ishii Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.129 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -449,8 +449,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, ...@@ -449,8 +449,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp,
{ {
bool need_delim = false; bool need_delim = false;
if (QueryCancel) CHECK_FOR_INTERRUPTS();
CancelQuery();
if (binary) if (binary)
{ {
...@@ -702,11 +701,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, ...@@ -702,11 +701,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp,
while (!done) while (!done)
{ {
if (QueryCancel) CHECK_FOR_INTERRUPTS();
{
lineno = 0;
CancelQuery();
}
lineno++; lineno++;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.182 2001/01/12 21:53:56 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.183 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -378,8 +378,7 @@ vacuum_rel(Oid relid) ...@@ -378,8 +378,7 @@ vacuum_rel(Oid relid)
* Check for user-requested abort. Note we want this to be inside a * Check for user-requested abort. Note we want this to be inside a
* transaction, so xact.c doesn't issue useless NOTICE. * transaction, so xact.c doesn't issue useless NOTICE.
*/ */
if (QueryCancel) CHECK_FOR_INTERRUPTS();
CancelQuery();
/* /*
* Race condition -- if the pg_class tuple has gone away since the * Race condition -- if the pg_class tuple has gone away since the
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.22 2000/10/26 21:35:15 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.23 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -248,14 +248,12 @@ ExecProcNode(Plan *node, Plan *parent) ...@@ -248,14 +248,12 @@ ExecProcNode(Plan *node, Plan *parent)
{ {
TupleTableSlot *result; TupleTableSlot *result;
CHECK_FOR_INTERRUPTS();
/* ---------------- /* ----------------
* deal with NULL nodes.. * deal with NULL nodes..
* ---------------- * ----------------
*/ */
if (QueryCancel)
CancelQuery();
if (node == NULL) if (node == NULL)
return NULL; return NULL;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.103 2001/01/12 21:53:57 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.104 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -92,6 +92,7 @@ static Buffer ReadBufferWithBufferLock(Relation relation, BlockNumber blockNum, ...@@ -92,6 +92,7 @@ static Buffer ReadBufferWithBufferLock(Relation relation, BlockNumber blockNum,
bool bufferLockHeld); bool bufferLockHeld);
static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum, static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum,
bool *foundPtr, bool bufferLockHeld); bool *foundPtr, bool bufferLockHeld);
static int ReleaseBufferWithBufferLock(Buffer buffer);
static int BufferReplace(BufferDesc *bufHdr); static int BufferReplace(BufferDesc *bufHdr);
void PrintBufferDescs(void); void PrintBufferDescs(void);
...@@ -687,10 +688,14 @@ ReleaseAndReadBuffer(Buffer buffer, ...@@ -687,10 +688,14 @@ ReleaseAndReadBuffer(Buffer buffer,
{ {
bufHdr = &BufferDescriptors[buffer - 1]; bufHdr = &BufferDescriptors[buffer - 1];
Assert(PrivateRefCount[buffer - 1] > 0); Assert(PrivateRefCount[buffer - 1] > 0);
PrivateRefCount[buffer - 1]--; if (PrivateRefCount[buffer - 1] > 1)
if (PrivateRefCount[buffer - 1] == 0) {
PrivateRefCount[buffer - 1]--;
}
else
{ {
SpinAcquire(BufMgrLock); SpinAcquire(BufMgrLock);
PrivateRefCount[buffer - 1] = 0;
Assert(bufHdr->refcount > 0); Assert(bufHdr->refcount > 0);
bufHdr->refcount--; bufHdr->refcount--;
if (bufHdr->refcount == 0) if (bufHdr->refcount == 0)
...@@ -1185,10 +1190,7 @@ recheck: ...@@ -1185,10 +1190,7 @@ recheck:
/* Assert checks that buffer will actually get freed! */ /* Assert checks that buffer will actually get freed! */
Assert(PrivateRefCount[i - 1] == 1 && Assert(PrivateRefCount[i - 1] == 1 &&
bufHdr->refcount == 1); bufHdr->refcount == 1);
/* ReleaseBuffer expects we do not hold the lock at entry */ ReleaseBufferWithBufferLock(i);
SpinRelease(BufMgrLock);
ReleaseBuffer(i);
SpinAcquire(BufMgrLock);
} }
/* /*
* And mark the buffer as no longer occupied by this rel. * And mark the buffer as no longer occupied by this rel.
...@@ -1270,10 +1272,7 @@ recheck: ...@@ -1270,10 +1272,7 @@ recheck:
/* Assert checks that buffer will actually get freed! */ /* Assert checks that buffer will actually get freed! */
Assert(PrivateRefCount[i - 1] == 1 && Assert(PrivateRefCount[i - 1] == 1 &&
bufHdr->refcount == 1); bufHdr->refcount == 1);
/* ReleaseBuffer expects we do not hold the lock at entry */ ReleaseBufferWithBufferLock(i);
SpinRelease(BufMgrLock);
ReleaseBuffer(i);
SpinAcquire(BufMgrLock);
} }
/* /*
* And mark the buffer as no longer occupied by this rel. * And mark the buffer as no longer occupied by this rel.
...@@ -1624,10 +1623,14 @@ ReleaseBuffer(Buffer buffer) ...@@ -1624,10 +1623,14 @@ ReleaseBuffer(Buffer buffer)
bufHdr = &BufferDescriptors[buffer - 1]; bufHdr = &BufferDescriptors[buffer - 1];
Assert(PrivateRefCount[buffer - 1] > 0); Assert(PrivateRefCount[buffer - 1] > 0);
PrivateRefCount[buffer - 1]--; if (PrivateRefCount[buffer - 1] > 1)
if (PrivateRefCount[buffer - 1] == 0) {
PrivateRefCount[buffer - 1]--;
}
else
{ {
SpinAcquire(BufMgrLock); SpinAcquire(BufMgrLock);
PrivateRefCount[buffer - 1] = 0;
Assert(bufHdr->refcount > 0); Assert(bufHdr->refcount > 0);
bufHdr->refcount--; bufHdr->refcount--;
if (bufHdr->refcount == 0) if (bufHdr->refcount == 0)
...@@ -1641,6 +1644,48 @@ ReleaseBuffer(Buffer buffer) ...@@ -1641,6 +1644,48 @@ ReleaseBuffer(Buffer buffer)
return STATUS_OK; return STATUS_OK;
} }
/*
* ReleaseBufferWithBufferLock
* Same as ReleaseBuffer except we hold the lock
*/
static int
ReleaseBufferWithBufferLock(Buffer buffer)
{
BufferDesc *bufHdr;
if (BufferIsLocal(buffer))
{
Assert(LocalRefCount[-buffer - 1] > 0);
LocalRefCount[-buffer - 1]--;
return STATUS_OK;
}
if (BAD_BUFFER_ID(buffer))
return STATUS_ERROR;
bufHdr = &BufferDescriptors[buffer - 1];
Assert(PrivateRefCount[buffer - 1] > 0);
if (PrivateRefCount[buffer - 1] > 1)
{
PrivateRefCount[buffer - 1]--;
}
else
{
PrivateRefCount[buffer - 1] = 0;
Assert(bufHdr->refcount > 0);
bufHdr->refcount--;
if (bufHdr->refcount == 0)
{
AddBufferToFreelist(bufHdr);
bufHdr->flags |= BM_FREE;
}
}
return STATUS_OK;
}
#ifdef NOT_USED #ifdef NOT_USED
void void
IncrBufferRefCount_Debug(char *file, int line, Buffer buffer) IncrBufferRefCount_Debug(char *file, int line, Buffer buffer)
...@@ -2217,9 +2262,9 @@ MarkBufferForCleanup(Buffer buffer, void (*CleanupFunc)(Buffer)) ...@@ -2217,9 +2262,9 @@ MarkBufferForCleanup(Buffer buffer, void (*CleanupFunc)(Buffer))
SpinRelease(BufMgrLock); SpinRelease(BufMgrLock);
LockBuffer(buffer, BUFFER_LOCK_UNLOCK); LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
PrivateRefCount[buffer - 1]--;
SpinAcquire(BufMgrLock); SpinAcquire(BufMgrLock);
PrivateRefCount[buffer - 1] = 0;
Assert(bufHdr->refcount > 0); Assert(bufHdr->refcount > 0);
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED); bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
bufHdr->CleanupFunc = CleanupFunc; bufHdr->CleanupFunc = CleanupFunc;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/s_lock.c,v 1.28 2000/12/29 21:31:20 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/s_lock.c,v 1.29 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include "miscadmin.h"
#include "storage/s_lock.h" #include "storage/s_lock.h"
...@@ -101,10 +102,16 @@ s_lock(volatile slock_t *lock, const char *file, const int line) ...@@ -101,10 +102,16 @@ s_lock(volatile slock_t *lock, const char *file, const int line)
/* /*
* If you are thinking of changing this code, be careful. This same * If you are thinking of changing this code, be careful. This same
* loop logic is used in other places that call TAS() directly. * loop logic is used in other places that call TAS() directly.
*
* While waiting for a lock, we check for cancel/die interrupts (which
* is a no-op if we are inside a critical section). The interrupt check
* can be omitted in places that know they are inside a critical section.
* Note that an interrupt must NOT be accepted after acquiring the lock.
*/ */
while (TAS(lock)) while (TAS(lock))
{ {
s_lock_sleep(spins++, 0, lock, file, line); s_lock_sleep(spins++, 0, lock, file, line);
CHECK_FOR_INTERRUPTS();
} }
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.59 2001/01/07 04:30:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.60 2001/01/14 05:08:15 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -131,8 +131,12 @@ proc_exit(int code) ...@@ -131,8 +131,12 @@ proc_exit(int code)
* to close up shop already. Note that the signal handlers will not * to close up shop already. Note that the signal handlers will not
* set these flags again, now that proc_exit_inprogress is set. * set these flags again, now that proc_exit_inprogress is set.
*/ */
QueryCancel = false; InterruptPending = false;
ProcDiePending = false; ProcDiePending = false;
QueryCancelPending = false;
/* And let's just make *sure* we're not interrupted ... */
ImmediateInterruptOK = false;
CritSectionCount = 1;
if (DebugLvl > 1) if (DebugLvl > 1)
elog(DEBUG, "proc_exit(%d)", code); elog(DEBUG, "proc_exit(%d)", code);
...@@ -367,7 +371,7 @@ CallbackSemaphoreKill(int status, Datum semId) ...@@ -367,7 +371,7 @@ CallbackSemaphoreKill(int status, Datum semId)
/* IpcSemaphoreLock(semId, sem) - locks a semaphore */ /* IpcSemaphoreLock(semId, sem) - locks a semaphore */
/****************************************************************************/ /****************************************************************************/
void void
IpcSemaphoreLock(IpcSemaphoreId semId, int sem) IpcSemaphoreLock(IpcSemaphoreId semId, int sem, bool interruptOK)
{ {
int errStatus; int errStatus;
struct sembuf sops; struct sembuf sops;
...@@ -380,11 +384,43 @@ IpcSemaphoreLock(IpcSemaphoreId semId, int sem) ...@@ -380,11 +384,43 @@ IpcSemaphoreLock(IpcSemaphoreId semId, int sem)
* Note: if errStatus is -1 and errno == EINTR then it means we * Note: if errStatus is -1 and errno == EINTR then it means we
* returned from the operation prematurely because we were * returned from the operation prematurely because we were
* sent a signal. So we try and lock the semaphore again. * sent a signal. So we try and lock the semaphore again.
* ---------------- *
* Each time around the loop, we check for a cancel/die interrupt.
* We assume that if such an interrupt comes in while we are waiting,
* it will cause the semop() call to exit with errno == EINTR, so that
* we will be able to service the interrupt (if not in a critical
* section already).
*
* Once we acquire the lock, we do NOT check for an interrupt before
* returning. The caller needs to be able to record ownership of
* the lock before any interrupt can be accepted.
*
* There is a window of a few instructions between CHECK_FOR_INTERRUPTS
* and entering the semop() call. If a cancel/die interrupt occurs in
* that window, we would fail to notice it until after we acquire the
* lock (or get another interrupt to escape the semop()). We can avoid
* this problem by temporarily setting ImmediateInterruptOK = true
* before we do CHECK_FOR_INTERRUPTS; then, a die() interrupt in this
* interval will execute directly. However, there is a huge pitfall:
* there is another window of a few instructions after the semop()
* before we are able to reset ImmediateInterruptOK. If an interrupt
* occurs then, we'll lose control, which means that the lock has been
* acquired but our caller did not get a chance to record the fact.
* Therefore, we only set ImmediateInterruptOK if the caller tells us
* it's OK to do so, ie, the caller does not need to record acquiring
* the lock. (This is currently true for lockmanager locks, since the
* process that granted us the lock did all the necessary state updates.
* It's not true for SysV semaphores used to emulate spinlocks --- but
* our performance on such platforms is so horrible anyway that I'm
* not going to worry too much about it.)
* ----------------
*/ */
do do
{ {
ImmediateInterruptOK = interruptOK;
CHECK_FOR_INTERRUPTS();
errStatus = semop(semId, &sops, 1); errStatus = semop(semId, &sops, 1);
ImmediateInterruptOK = false;
} while (errStatus == -1 && errno == EINTR); } while (errStatus == -1 && errno == EINTR);
if (errStatus == -1) if (errStatus == -1)
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.28 2001/01/12 21:53:59 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.29 2001/01/14 05:08:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -25,9 +25,11 @@ ...@@ -25,9 +25,11 @@
#include <sys/sem.h> #include <sys/sem.h>
#endif #endif
#include "miscadmin.h"
#include "storage/proc.h" #include "storage/proc.h"
#include "storage/s_lock.h" #include "storage/s_lock.h"
/* Probably should move these to an appropriate header file */ /* Probably should move these to an appropriate header file */
extern SPINLOCK ShmemLock; extern SPINLOCK ShmemLock;
extern SPINLOCK ShmemIndexLock; extern SPINLOCK ShmemIndexLock;
...@@ -144,20 +146,21 @@ SpinAcquire(SPINLOCK lockid) ...@@ -144,20 +146,21 @@ SpinAcquire(SPINLOCK lockid)
SLock *slckP = &(SLockArray[lockid]); SLock *slckP = &(SLockArray[lockid]);
PRINT_SLDEBUG("SpinAcquire", lockid, slckP); PRINT_SLDEBUG("SpinAcquire", lockid, slckP);
/*
* Lock out die() until we exit the critical section protected by the
* spinlock. This ensures that die() will not interrupt manipulations
* of data structures in shared memory. We don't want die() to
* interrupt this routine between S_LOCK and PROC_INCR_SLOCK, either,
* so must do it before acquiring the lock, not after.
*/
START_CRIT_SECTION();
/* /*
* Acquire the lock, then record that we have done so (for recovery * Acquire the lock, then record that we have done so (for recovery
* in case of elog(ERROR) during the critical section). * in case of elog(ERROR) during the critical section). Note we assume
* here that S_LOCK will not accept cancel/die interrupts once it has
* acquired the lock. However, interrupts should be accepted while
* waiting, if CritSectionCount is zero.
*/ */
S_LOCK(&(slckP->shlock)); S_LOCK(&(slckP->shlock));
PROC_INCR_SLOCK(lockid); PROC_INCR_SLOCK(lockid);
/*
* Lock out cancel/die interrupts until we exit the critical section
* protected by the spinlock. This ensures that interrupts will not
* interfere with manipulations of data structures in shared memory.
*/
START_CRIT_SECTION();
PRINT_SLDEBUG("SpinAcquire/done", lockid, slckP); PRINT_SLDEBUG("SpinAcquire/done", lockid, slckP);
} }
...@@ -317,10 +320,16 @@ SpinFreeAllSemaphores(void) ...@@ -317,10 +320,16 @@ SpinFreeAllSemaphores(void)
void void
SpinAcquire(SPINLOCK lock) SpinAcquire(SPINLOCK lock)
{ {
/* See the TAS() version of this routine for commentary */ /*
START_CRIT_SECTION(); * See the TAS() version of this routine for primary commentary.
IpcSemaphoreLock(SpinLockIds[0], lock); *
* NOTE we must pass interruptOK = false to IpcSemaphoreLock, to ensure
* that a cancel/die interrupt cannot prevent us from recording ownership
* of a lock we have just acquired.
*/
IpcSemaphoreLock(SpinLockIds[0], lock, false);
PROC_INCR_SLOCK(lock); PROC_INCR_SLOCK(lock);
START_CRIT_SECTION();
} }
/* /*
...@@ -338,8 +347,8 @@ SpinRelease(SPINLOCK lock) ...@@ -338,8 +347,8 @@ SpinRelease(SPINLOCK lock)
semval = IpcSemaphoreGetValue(SpinLockIds[0], lock); semval = IpcSemaphoreGetValue(SpinLockIds[0], lock);
Assert(semval < 1); Assert(semval < 1);
Assert(!MyProc || MyProc->sLocks[lockid] > 0);
#endif #endif
Assert(!MyProc || MyProc->sLocks[lockid] > 0);
PROC_DECR_SLOCK(lock); PROC_DECR_SLOCK(lock);
IpcSemaphoreUnlock(SpinLockIds[0], lock); IpcSemaphoreUnlock(SpinLockIds[0], lock);
END_CRIT_SECTION(); END_CRIT_SECTION();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.76 2001/01/10 01:24:19 inoue Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.77 2001/01/14 05:08:15 tgl Exp $
* *
* NOTES * NOTES
* Outside modules can create a lock table and acquire/release * Outside modules can create a lock table and acquire/release
...@@ -726,6 +726,12 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, ...@@ -726,6 +726,12 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
*/ */
status = WaitOnLock(lockmethod, lockmode, lock, holder); status = WaitOnLock(lockmethod, lockmode, lock, holder);
/*
* NOTE: do not do any material change of state between here and
* return. All required changes in locktable state must have been
* done when the lock was granted to us --- see notes in WaitOnLock.
*/
/* /*
* Check the holder entry status, in case something in the ipc * Check the holder entry status, in case something in the ipc
* communication doesn't work correctly. * communication doesn't work correctly.
...@@ -921,6 +927,8 @@ GrantLock(LOCK *lock, HOLDER *holder, LOCKMODE lockmode) ...@@ -921,6 +927,8 @@ GrantLock(LOCK *lock, HOLDER *holder, LOCKMODE lockmode)
lock->nActive++; lock->nActive++;
lock->activeHolders[lockmode]++; lock->activeHolders[lockmode]++;
lock->mask |= BITS_ON[lockmode]; lock->mask |= BITS_ON[lockmode];
if (lock->activeHolders[lockmode] == lock->holders[lockmode])
lock->waitMask &= BITS_OFF[lockmode];
LOCK_PRINT("GrantLock", lock, lockmode); LOCK_PRINT("GrantLock", lock, lockmode);
Assert((lock->nActive > 0) && (lock->activeHolders[lockmode] > 0)); Assert((lock->nActive > 0) && (lock->activeHolders[lockmode] > 0));
Assert(lock->nActive <= lock->nHolding); Assert(lock->nActive <= lock->nHolding);
...@@ -960,6 +968,17 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, ...@@ -960,6 +968,17 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
strcat(new_status, " waiting"); strcat(new_status, " waiting");
set_ps_display(new_status); set_ps_display(new_status);
/*
* NOTE: Think not to put any lock state cleanup after the call to
* ProcSleep, in either the normal or failure path. The lock state
* must be fully set by the lock grantor, or by HandleDeadlock if we
* give up waiting for the lock. This is necessary because of the
* possibility that a cancel/die interrupt will interrupt ProcSleep
* after someone else grants us the lock, but before we've noticed it.
* Hence, after granting, the locktable state must fully reflect the
* fact that we own the lock; we can't do additional work on return.
*/
if (ProcSleep(lockMethodTable->ctl, if (ProcSleep(lockMethodTable->ctl,
lockmode, lockmode,
lock, lock,
...@@ -967,26 +986,16 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode, ...@@ -967,26 +986,16 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
{ {
/* ------------------- /* -------------------
* We failed as a result of a deadlock, see HandleDeadLock(). * We failed as a result of a deadlock, see HandleDeadLock().
* Decrement the lock nHolding and holders fields as * Quit now. Removal of the holder and lock objects, if no longer
* we are no longer waiting on this lock. Removal of the holder and * needed, will happen in xact cleanup (see above for motivation).
* lock objects, if no longer needed, will happen in xact cleanup.
* ------------------- * -------------------
*/ */
lock->nHolding--;
lock->holders[lockmode]--;
LOCK_PRINT("WaitOnLock: aborting on lock", lock, lockmode); LOCK_PRINT("WaitOnLock: aborting on lock", lock, lockmode);
Assert((lock->nHolding >= 0) && (lock->holders[lockmode] >= 0));
Assert(lock->nActive <= lock->nHolding);
if (lock->activeHolders[lockmode] == lock->holders[lockmode])
lock->waitMask &= BITS_OFF[lockmode];
SpinRelease(lockMethodTable->ctl->masterLock); SpinRelease(lockMethodTable->ctl->masterLock);
elog(ERROR, DeadLockMessage); elog(ERROR, DeadLockMessage);
/* not reached */ /* not reached */
} }
if (lock->activeHolders[lockmode] == lock->holders[lockmode])
lock->waitMask &= BITS_OFF[lockmode];
set_ps_display(old_status); set_ps_display(old_status);
pfree(old_status); pfree(old_status);
pfree(new_status); pfree(new_status);
......
This diff is collapsed.
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.75 2001/01/09 18:40:14 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.76 2001/01/14 05:08:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -120,8 +120,10 @@ elog(int lev, const char *fmt, ...) ...@@ -120,8 +120,10 @@ elog(int lev, const char *fmt, ...)
char *msg_buf = msg_fixedbuf; char *msg_buf = msg_fixedbuf;
/* this buffer is only used for strange values of lev: */ /* this buffer is only used for strange values of lev: */
char prefix_buf[32]; char prefix_buf[32];
#ifdef HAVE_SYS_NERR
/* this buffer is only used if errno has a bogus value: */ /* this buffer is only used if errno has a bogus value: */
char errorstr_buf[32]; char errorstr_buf[32];
#endif
const char *errorstr; const char *errorstr;
const char *prefix; const char *prefix;
const char *cp; const char *cp;
...@@ -145,17 +147,16 @@ elog(int lev, const char *fmt, ...) ...@@ -145,17 +147,16 @@ elog(int lev, const char *fmt, ...)
errorstr = errorstr_buf; errorstr = errorstr_buf;
} }
#else #else
/* assume strerror() will cope gracefully with bogus errno values */
errorstr = strerror(errno); errorstr = strerror(errno);
#endif #endif
if (lev == ERROR || lev == FATAL) /* Convert initialization errors into fatal errors.
{ * This is probably redundant, because Warn_restart_ready won't
/* this is probably redundant... */ * be set anyway...
if (IsInitProcessingMode()) */
lev = FATAL; if (lev == ERROR && IsInitProcessingMode())
if (CritSectionCount > 0) lev = FATAL;
lev = STOP;
}
/* choose message prefix and indent level */ /* choose message prefix and indent level */
switch (lev) switch (lev)
...@@ -366,8 +367,6 @@ elog(int lev, const char *fmt, ...) ...@@ -366,8 +367,6 @@ elog(int lev, const char *fmt, ...)
if (Debugfile >= 0 && Use_syslog <= 1) if (Debugfile >= 0 && Use_syslog <= 1)
write(Debugfile, msg_buf, len); write(Debugfile, msg_buf, len);
#ifndef PG_STANDALONE
if (lev > DEBUG && whereToSendOutput == Remote) if (lev > DEBUG && whereToSendOutput == Remote)
{ {
/* Send IPC message to the front-end program */ /* Send IPC message to the front-end program */
...@@ -424,8 +423,6 @@ elog(int lev, const char *fmt, ...) ...@@ -424,8 +423,6 @@ elog(int lev, const char *fmt, ...)
fputs(msg_buf, stderr); fputs(msg_buf, stderr);
} }
#endif /* !PG_STANDALONE */
/* done with the message, release space */ /* done with the message, release space */
if (fmt_buf != fmt_fixedbuf) if (fmt_buf != fmt_fixedbuf)
free(fmt_buf); free(fmt_buf);
...@@ -437,6 +434,8 @@ elog(int lev, const char *fmt, ...) ...@@ -437,6 +434,8 @@ elog(int lev, const char *fmt, ...)
*/ */
if (lev == ERROR || lev == FATAL) if (lev == ERROR || lev == FATAL)
{ {
/* Prevent immediate interrupt while entering error recovery */
ImmediateInterruptOK = false;
/* /*
* For a FATAL error, we let proc_exit clean up and exit. * For a FATAL error, we let proc_exit clean up and exit.
...@@ -477,7 +476,6 @@ elog(int lev, const char *fmt, ...) ...@@ -477,7 +476,6 @@ elog(int lev, const char *fmt, ...)
if (lev > FATAL) if (lev > FATAL)
{ {
/* /*
* Serious crash time. Postmaster will observe nonzero process * Serious crash time. Postmaster will observe nonzero process
* exit status and kill the other backends too. * exit status and kill the other backends too.
...@@ -485,6 +483,7 @@ elog(int lev, const char *fmt, ...) ...@@ -485,6 +483,7 @@ elog(int lev, const char *fmt, ...)
* XXX: what if we are *in* the postmaster? proc_exit() won't kill * XXX: what if we are *in* the postmaster? proc_exit() won't kill
* our children... * our children...
*/ */
ImmediateInterruptOK = false;
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
proc_exit(lev); proc_exit(lev);
...@@ -493,8 +492,6 @@ elog(int lev, const char *fmt, ...) ...@@ -493,8 +492,6 @@ elog(int lev, const char *fmt, ...)
/* We reach here if lev <= NOTICE. OK to return to caller. */ /* We reach here if lev <= NOTICE. OK to return to caller. */
} }
#ifndef PG_STANDALONE
int int
DebugFileOpen(void) DebugFileOpen(void)
{ {
...@@ -556,9 +553,6 @@ DebugFileOpen(void) ...@@ -556,9 +553,6 @@ DebugFileOpen(void)
return Debugfile; return Debugfile;
} }
#endif
/* /*
* Return a timestamp string like * Return a timestamp string like
...@@ -602,6 +596,10 @@ print_pid(void) ...@@ -602,6 +596,10 @@ print_pid(void)
#ifdef ENABLE_SYSLOG #ifdef ENABLE_SYSLOG
#ifndef PG_SYSLOG_LIMIT
# define PG_SYSLOG_LIMIT 128
#endif
/* /*
* Write a message line to syslog if the syslog option is set. * Write a message line to syslog if the syslog option is set.
* *
...@@ -613,10 +611,6 @@ print_pid(void) ...@@ -613,10 +611,6 @@ print_pid(void)
static void static void
write_syslog(int level, const char *line) write_syslog(int level, const char *line)
{ {
#ifndef PG_SYSLOG_LIMIT
# define PG_SYSLOG_LIMIT 128
#endif
static bool openlog_done = false; static bool openlog_done = false;
static unsigned long seq = 0; static unsigned long seq = 0;
static int syslog_fac = LOG_LOCAL0; static int syslog_fac = LOG_LOCAL0;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.49 2001/01/07 04:17:29 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.50 2001/01/14 05:08:16 tgl Exp $
* *
* NOTES * NOTES
* Globals used all over the place should be declared here and not * Globals used all over the place should be declared here and not
...@@ -34,7 +34,12 @@ ProtocolVersion FrontendProtocol = PG_PROTOCOL_LATEST; ...@@ -34,7 +34,12 @@ ProtocolVersion FrontendProtocol = PG_PROTOCOL_LATEST;
bool Noversion = false; bool Noversion = false;
bool Quiet = false; bool Quiet = false;
volatile bool QueryCancel = false;
volatile bool InterruptPending = false;
volatile bool QueryCancelPending = false;
volatile bool ProcDiePending = false;
volatile bool ImmediateInterruptOK = false;
volatile uint32 CritSectionCount = 0;
int MyProcPid; int MyProcPid;
struct Port *MyProcPort; struct Port *MyProcPort;
...@@ -56,9 +61,7 @@ BackendId MyBackendId; ...@@ -56,9 +61,7 @@ BackendId MyBackendId;
char *DatabaseName = NULL; char *DatabaseName = NULL;
char *DatabasePath = NULL; char *DatabasePath = NULL;
bool MyDatabaseIdIsInitialized = false;
Oid MyDatabaseId = InvalidOid; Oid MyDatabaseId = InvalidOid;
bool TransactionInitWasProcessed = false;
bool IsUnderPostmaster = false; bool IsUnderPostmaster = false;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* PostgreSQL transaction log manager * PostgreSQL transaction log manager
* *
* $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.16 2001/01/12 21:54:01 tgl Exp $ * $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.17 2001/01/14 05:08:16 tgl Exp $
*/ */
#ifndef XLOG_H #ifndef XLOG_H
#define XLOG_H #define XLOG_H
...@@ -101,7 +101,6 @@ typedef XLogPageHeaderData *XLogPageHeader; ...@@ -101,7 +101,6 @@ typedef XLogPageHeaderData *XLogPageHeader;
extern StartUpID ThisStartUpID; /* current SUI */ extern StartUpID ThisStartUpID; /* current SUI */
extern bool InRecovery; extern bool InRecovery;
extern XLogRecPtr MyLastRecPtr; extern XLogRecPtr MyLastRecPtr;
extern volatile uint32 CritSectionCount;
typedef struct RmgrData typedef struct RmgrData
{ {
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: miscadmin.h,v 1.76 2001/01/07 04:17:28 tgl Exp $ * $Id: miscadmin.h,v 1.77 2001/01/14 05:08:16 tgl Exp $
* *
* NOTES * NOTES
* some of the information in this file will be moved to * some of the information in this file should be moved to
* other files. * other files.
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
...@@ -23,11 +23,63 @@ ...@@ -23,11 +23,63 @@
#ifndef MISCADMIN_H #ifndef MISCADMIN_H
#define MISCADMIN_H #define MISCADMIN_H
#include <sys/types.h> /* For pid_t */
#include "postgres.h"
#include "storage/ipc.h" #include "storage/ipc.h"
/*****************************************************************************
* System interrupt handling
*
* There are two types of interrupts that a running backend needs to accept
* without messing up its state: QueryCancel (SIGINT) and ProcDie (SIGTERM).
* In both cases, we need to be able to clean up the current transaction
* gracefully, so we can't respond to the interrupt instantaneously ---
* there's no guarantee that internal data structures would be self-consistent
* if the code is interrupted at an arbitrary instant. Instead, the signal
* handlers set flags that are checked periodically during execution.
*
* The CHECK_FOR_INTERRUPTS() macro is called at strategically located spots
* where it is normally safe to accept a cancel or die interrupt. In some
* cases, we invoke CHECK_FOR_INTERRUPTS() inside low-level subroutines that
* might sometimes be called in contexts that do *not* want to allow a cancel
* or die interrupt. The CRIT_SECTION mechanism allows code to ensure that
* no cancel or die interrupt will be accepted, even if CHECK_FOR_INTERRUPTS
* gets called in a subroutine.
*
* Special mechanisms are used to let an interrupt be accepted when we are
* waiting for a lock or spinlock, and when we are waiting for command input
* (but, of course, only if the critical section counter is zero). See the
* related code for details.
*
*****************************************************************************/
/* in globals.c */
/* these are marked volatile because they are set by signal handlers: */
extern volatile bool InterruptPending;
extern volatile bool QueryCancelPending;
extern volatile bool ProcDiePending;
/* these are marked volatile because they are examined by signal handlers: */
extern volatile bool ImmediateInterruptOK;
extern volatile uint32 CritSectionCount;
/* in postgres.c */
extern void ProcessInterrupts(void);
#define CHECK_FOR_INTERRUPTS() \
do { \
if (InterruptPending) \
ProcessInterrupts(); \
} while(0)
#define START_CRIT_SECTION() (CritSectionCount++)
#define END_CRIT_SECTION() \
do { \
Assert(CritSectionCount > 0); \
CritSectionCount--; \
if (CritSectionCount == 0 && InterruptPending) \
ProcessInterrupts(); \
} while(0)
/***************************************************************************** /*****************************************************************************
* globals.h -- * * globals.h -- *
*****************************************************************************/ *****************************************************************************/
...@@ -42,7 +94,6 @@ extern int PostmasterMain(int argc, char *argv[]); ...@@ -42,7 +94,6 @@ extern int PostmasterMain(int argc, char *argv[]);
*/ */
extern bool Noversion; extern bool Noversion;
extern bool Quiet; extern bool Quiet;
extern volatile bool QueryCancel;
extern char *DataDir; extern char *DataDir;
extern int MyProcPid; extern int MyProcPid;
...@@ -56,9 +107,7 @@ extern char OutputFileName[]; ...@@ -56,9 +107,7 @@ extern char OutputFileName[];
* *
* extern BackendId MyBackendId; * extern BackendId MyBackendId;
*/ */
extern bool MyDatabaseIdIsInitialized;
extern Oid MyDatabaseId; extern Oid MyDatabaseId;
extern bool TransactionInitWasProcessed;
extern bool IsUnderPostmaster; extern bool IsUnderPostmaster;
...@@ -143,7 +192,8 @@ extern void SetSessionUserIdFromUserName(const char *username); ...@@ -143,7 +192,8 @@ extern void SetSessionUserIdFromUserName(const char *username);
extern void SetDataDir(const char *dir); extern void SetDataDir(const char *dir);
extern int FindExec(char *full_path, const char *argv0, const char *binary_name); extern int FindExec(char *full_path, const char *argv0,
const char *binary_name);
extern int CheckPathAccess(char *path, char *name, int open_mode); extern int CheckPathAccess(char *path, char *name, int open_mode);
#ifdef CYR_RECODE #ifdef CYR_RECODE
...@@ -157,17 +207,17 @@ extern char *convertstr(unsigned char *buff, int len, int dest); ...@@ -157,17 +207,17 @@ extern char *convertstr(unsigned char *buff, int len, int dest);
/* /*
* Description: * Description:
* There are three processing modes in POSTGRES. They are * There are three processing modes in POSTGRES. They are
* "BootstrapProcessing or "bootstrap," InitProcessing or * BootstrapProcessing or "bootstrap," InitProcessing or
* "initialization," and NormalProcessing or "normal." * "initialization," and NormalProcessing or "normal."
* *
* The first 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 * system state indicates bootstrap processing, transactions are all given
* transaction id "one" and are consequently guarenteed to commit. This mode * transaction id "one" and are consequently guaranteed to commit. This mode
* is used during the initial generation of template databases. * is used during the initial generation of template databases.
* *
* Initialization mode until all normal initialization is complete. * Initialization mode: used while starting a backend, until all normal
* Some code behaves differently when executed in this mode to enable * initialization is complete. Some code behaves differently when executed
* system bootstrapping. * in this mode to enable system bootstrapping.
* *
* If a POSTGRES binary is in normal mode, then all code may be executed * If a POSTGRES binary is in normal mode, then all code may be executed
* normally. * normally.
...@@ -185,27 +235,13 @@ typedef enum ProcessingMode ...@@ -185,27 +235,13 @@ typedef enum ProcessingMode
* pinit.h -- * * pinit.h -- *
* POSTGRES initialization and cleanup definitions. * * POSTGRES initialization and cleanup definitions. *
*****************************************************************************/ *****************************************************************************/
/*
* Note:
* XXX AddExitHandler not defined yet.
*/
typedef int16 ExitStatus;
#define NormalExitStatus (0)
#define FatalExitStatus (127)
/* XXX are there any other meaningful exit codes? */
/* in utils/init/postinit.c */ /* in utils/init/postinit.c */
extern int lockingOff; extern int lockingOff;
extern void InitPostgres(const char *dbname, const char *username); extern void InitPostgres(const char *dbname, const char *username);
extern void BaseInit(void); extern void BaseInit(void);
/* one of the ways to get out of here */
#define ExitPostgres(status) proc_exec(status)
/* processing mode support stuff */ /* processing mode support stuff */
extern ProcessingMode Mode; extern ProcessingMode Mode;
...@@ -215,21 +251,22 @@ extern ProcessingMode Mode; ...@@ -215,21 +251,22 @@ extern ProcessingMode Mode;
#define SetProcessingMode(mode) \ #define SetProcessingMode(mode) \
do { \ do { \
AssertArg(mode == BootstrapProcessing || mode == InitProcessing || \ AssertArg((mode) == BootstrapProcessing || \
mode == NormalProcessing); \ (mode) == InitProcessing || \
Mode = mode; \ (mode) == NormalProcessing); \
Mode = (mode); \
} while(0) } while(0)
#define GetProcessingMode() Mode #define GetProcessingMode() Mode
extern void IgnoreSystemIndexes(bool mode);
extern bool IsIgnoringSystemIndexes(void);
extern bool IsCacheInitialized(void);
extern void SetWaitingForLock(bool);
extern bool CreateDataDirLockFile(const char *datadir, bool amPostmaster); extern bool CreateDataDirLockFile(const char *datadir, bool amPostmaster);
extern bool CreateSocketLockFile(const char *socketfile, bool amPostmaster); extern bool CreateSocketLockFile(const char *socketfile, bool amPostmaster);
extern void ValidatePgVersion(const char *path); extern void ValidatePgVersion(const char *path);
/* these externs do not belong here... */
extern void IgnoreSystemIndexes(bool mode);
extern bool IsIgnoringSystemIndexes(void);
extern bool IsCacheInitialized(void);
#endif /* MISCADMIN_H */ #endif /* MISCADMIN_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: ipc.h,v 1.44 2000/12/03 17:18:09 tgl Exp $ * $Id: ipc.h,v 1.45 2001/01/14 05:08:16 tgl Exp $
* *
* Some files that would normally need to include only sys/ipc.h must * Some files that would normally need to include only sys/ipc.h must
* instead include this file because on Ultrix, sys/ipc.h is not designed * instead include this file because on Ultrix, sys/ipc.h is not designed
...@@ -99,7 +99,7 @@ extern IpcSemaphoreId IpcSemaphoreCreate(int numSems, int permission, ...@@ -99,7 +99,7 @@ extern IpcSemaphoreId IpcSemaphoreCreate(int numSems, int permission,
int semStartValue, int semStartValue,
bool removeOnExit); bool removeOnExit);
extern void IpcSemaphoreKill(IpcSemaphoreId semId); extern void IpcSemaphoreKill(IpcSemaphoreId semId);
extern void IpcSemaphoreLock(IpcSemaphoreId semId, int sem); extern void IpcSemaphoreLock(IpcSemaphoreId semId, int sem, bool interruptOK);
extern void IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem); extern void IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem);
extern bool IpcSemaphoreTryLock(IpcSemaphoreId semId, int sem); extern bool IpcSemaphoreTryLock(IpcSemaphoreId semId, int sem);
extern int IpcSemaphoreGetValue(IpcSemaphoreId semId, int sem); extern int IpcSemaphoreGetValue(IpcSemaphoreId semId, int sem);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: proc.h,v 1.33 2000/12/22 00:51:54 tgl Exp $ * $Id: proc.h,v 1.34 2001/01/14 05:08:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,9 +22,8 @@ extern int DeadlockTimeout; ...@@ -22,9 +22,8 @@ extern int DeadlockTimeout;
typedef struct typedef struct
{ {
int sleeplock; IpcSemaphoreId semId; /* SysV semaphore set ID */
IpcSemaphoreId semId; int semNum; /* semaphore number within set */
int semNum;
} SEMA; } SEMA;
/* /*
...@@ -38,12 +37,6 @@ struct proc ...@@ -38,12 +37,6 @@ struct proc
SEMA sem; /* ONE semaphore to sleep on */ SEMA sem; /* ONE semaphore to sleep on */
int errType; /* error code tells why we woke up */ int errType; /* error code tells why we woke up */
int critSects; /* If critSects > 0, we are in sensitive
* routines that cannot be recovered when
* the process fails. */
int prio; /* priority for sleep queue */
TransactionId xid; /* transaction currently being executed by TransactionId xid; /* transaction currently being executed by
* this proc */ * this proc */
...@@ -72,6 +65,9 @@ struct proc ...@@ -72,6 +65,9 @@ struct proc
extern PROC *MyProc; extern PROC *MyProc;
extern SPINLOCK ProcStructLock;
#define PROC_INCR_SLOCK(lock) \ #define PROC_INCR_SLOCK(lock) \
do { \ do { \
if (MyProc) (MyProc->sLocks[(lock)])++; \ if (MyProc) (MyProc->sLocks[(lock)])++; \
...@@ -89,11 +85,6 @@ do { \ ...@@ -89,11 +85,6 @@ do { \
#define ERR_TIMEOUT 1 #define ERR_TIMEOUT 1
#define ERR_BUFFER_IO 2 #define ERR_BUFFER_IO 2
#define MAX_PRIO 50
#define MIN_PRIO (-1)
extern SPINLOCK ProcStructLock;
/* /*
* There is one ProcGlobal struct for the whole installation. * There is one ProcGlobal struct for the whole installation.
...@@ -142,5 +133,6 @@ extern int ProcLockWakeup(LOCKMETHOD lockmethod, LOCK *lock); ...@@ -142,5 +133,6 @@ extern int ProcLockWakeup(LOCKMETHOD lockmethod, LOCK *lock);
extern void ProcAddLock(SHM_QUEUE *elem); extern void ProcAddLock(SHM_QUEUE *elem);
extern void ProcReleaseSpins(PROC *proc); extern void ProcReleaseSpins(PROC *proc);
extern void LockWaitCancel(void); extern void LockWaitCancel(void);
extern void HandleDeadLock(SIGNAL_ARGS);
#endif /* PROC_H */ #endif /* PROC_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: tcopprot.h,v 1.36 2000/12/03 10:27:29 vadim Exp $ * $Id: tcopprot.h,v 1.37 2001/01/14 05:08:16 tgl 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
...@@ -40,9 +40,7 @@ extern void pg_exec_query_string(char *query_string, ...@@ -40,9 +40,7 @@ extern void pg_exec_query_string(char *query_string,
#endif /* BOOTSTRAP_INCLUDE */ #endif /* BOOTSTRAP_INCLUDE */
extern void handle_warn(SIGNAL_ARGS);
extern void die(SIGNAL_ARGS); extern void die(SIGNAL_ARGS);
extern void CancelQuery(void);
extern int PostgresMain(int argc, char *argv[], extern int PostgresMain(int argc, char *argv[],
int real_argc, char *real_argv[], const char *username); int real_argc, char *real_argv[], const char *username);
extern void ResetUsage(void); extern void ResetUsage(void);
......
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: elog.h,v 1.23 2001/01/12 21:54:01 tgl Exp $ * $Id: elog.h,v 1.24 2001/01/14 05:08:16 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef ELOG_H #ifndef ELOG_H
#define ELOG_H #define ELOG_H
/* Error level codes */
#define NOTICE 0 /* random info - no special action */ #define NOTICE 0 /* random info - no special action */
#define ERROR (-1) /* user error - return to known state */ #define ERROR (-1) /* user error - return to known state */
#define FATAL 1 /* fatal error - abort process */ #define FATAL 1 /* fatal error - abort process */
...@@ -23,47 +24,25 @@ ...@@ -23,47 +24,25 @@
#define LOG DEBUG #define LOG DEBUG
#define NOIND (-3) /* debug message, don't indent as far */ #define NOIND (-3) /* debug message, don't indent as far */
/* Configurable parameters */
#ifdef ENABLE_SYSLOG #ifdef ENABLE_SYSLOG
extern int Use_syslog; extern int Use_syslog;
#endif #endif
/*
* If CritSectionCount > 0, signal handlers mustn't do
* elog(ERROR|FATAL), instead remember what action is
* required with QueryCancel or ProcDiePending.
* ProcDiePending will be honored at critical section exit,
* but QueryCancel is only checked at specified points.
*/
extern volatile uint32 CritSectionCount; /* duplicates access/xlog.h */
extern volatile bool ProcDiePending;
extern void ForceProcDie(void); /* in postgres.c */
#define START_CRIT_SECTION() (CritSectionCount++)
#define END_CRIT_SECTION() \
do { \
Assert(CritSectionCount > 0); \
CritSectionCount--; \
if (CritSectionCount == 0 && ProcDiePending) \
ForceProcDie(); \
} while(0)
extern bool Log_timestamp; extern bool Log_timestamp;
extern bool Log_pid; extern bool Log_pid;
#ifndef __GNUC__ #ifndef __GNUC__
extern void elog(int lev, const char *fmt,...); extern void elog(int lev, const char *fmt, ...);
#else #else
/* This extension allows gcc to check the format string for consistency with /* This extension allows gcc to check the format string for consistency with
the supplied arguments. */ the supplied arguments. */
extern void elog(int lev, const char *fmt,...) __attribute__((format(printf, 2, 3))); extern void elog(int lev, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
#endif #endif
#ifndef PG_STANDALONE
extern int DebugFileOpen(void); extern int DebugFileOpen(void);
#endif
#endif /* ELOG_H */ #endif /* ELOG_H */
...@@ -12,10 +12,12 @@ ...@@ -12,10 +12,12 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.70 2000/12/15 20:01:55 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.71 2001/01/14 05:08:17 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h"
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#include <limits.h> #include <limits.h>
......
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