summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc
diff options
context:
space:
mode:
authorHeikki Linnakangas2008-12-09 14:28:20 +0000
committerHeikki Linnakangas2008-12-09 14:28:20 +0000
commit7b05b3fa3996c6b7795c22757a31e2348378209d (patch)
treeacfe73e103dc5291a7c61d7b90b476c9c1e27a35 /src/backend/storage/ipc
parent9edd720050a2979c684b514f7d5118a8a0d45dff (diff)
Provide support for multiplexing SIGUSR1 signal. The upcoming synchronous
replication patch needs a signal, but we've already used SIGUSR1 and SIGUSR2 in normal backends. This patch allows reusing SIGUSR1 for that, and for other purposes too if the need arises.
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r--src/backend/storage/ipc/sinval.c23
-rw-r--r--src/backend/storage/ipc/sinvaladt.c37
2 files changed, 30 insertions, 30 deletions
diff --git a/src/backend/storage/ipc/sinval.c b/src/backend/storage/ipc/sinval.c
index e2c6ca2aec9..d002f45489c 100644
--- a/src/backend/storage/ipc/sinval.c
+++ b/src/backend/storage/ipc/sinval.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.86 2008/06/19 21:32:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.87 2008/12/09 14:28:20 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,8 +26,8 @@
* Because backends sitting idle will not be reading sinval events, we
* need a way to give an idle backend a swift kick in the rear and make
* it catch up before the sinval queue overflows and forces it to go
- * through a cache reset exercise. This is done by sending SIGUSR1
- * to any backend that gets too far behind.
+ * through a cache reset exercise. This is done by sending
+ * PROCSIG_CATCHUP_INTERRUPT to any backend that gets too far behind.
*
* State for catchup events consists of two flags: one saying whether
* the signal handler is currently allowed to call ProcessCatchupEvent
@@ -144,9 +144,9 @@ ReceiveSharedInvalidMessages(
/*
- * CatchupInterruptHandler
+ * HandleCatchupInterrupt
*
- * This is the signal handler for SIGUSR1.
+ * This is called when PROCSIG_CATCHUP_INTERRUPT signal is received.
*
* If we are idle (catchupInterruptEnabled is set), we can safely
* invoke ProcessCatchupEvent directly. Otherwise, just set a flag
@@ -156,13 +156,11 @@ ReceiveSharedInvalidMessages(
* since there's no longer any reason to do anything.)
*/
void
-CatchupInterruptHandler(SIGNAL_ARGS)
+HandleCatchupInterrupt(void)
{
- int save_errno = errno;
-
/*
- * Note: this is a SIGNAL HANDLER. You must be very wary what you do
- * here.
+ * Note: this is called by a SIGNAL HANDLER.
+ * You must be very wary what you do here.
*/
/* Don't joggle the elbow of proc_exit */
@@ -216,8 +214,6 @@ CatchupInterruptHandler(SIGNAL_ARGS)
*/
catchupInterruptOccurred = 1;
}
-
- errno = save_errno;
}
/*
@@ -289,7 +285,8 @@ DisableCatchupInterrupt(void)
/*
* ProcessCatchupEvent
*
- * Respond to a catchup event (SIGUSR1) from another backend.
+ * Respond to a catchup event (PROCSIG_CATCHUP_INTERRUPT) from another
+ * backend.
*
* This is called either directly from the SIGUSR1 signal handler,
* or the next time control reaches the outer idle loop (assuming
diff --git a/src/backend/storage/ipc/sinvaladt.c b/src/backend/storage/ipc/sinvaladt.c
index b7933a05c42..fe9ff43ae74 100644
--- a/src/backend/storage/ipc/sinvaladt.c
+++ b/src/backend/storage/ipc/sinvaladt.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.74 2008/07/18 14:45:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.75 2008/12/09 14:28:20 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,6 +21,7 @@
#include "storage/backendid.h"
#include "storage/ipc.h"
#include "storage/proc.h"
+#include "storage/procarray.h"
#include "storage/shmem.h"
#include "storage/sinvaladt.h"
#include "storage/spin.h"
@@ -136,9 +137,9 @@
/* Per-backend state in shared invalidation structure */
typedef struct ProcState
{
- /* procPid is zero in an inactive ProcState array entry. */
- pid_t procPid; /* PID of backend, for signaling */
- /* nextMsgNum is meaningless if procPid == 0 or resetState is true. */
+ /* proc is NULL in an inactive ProcState array entry. */
+ PGPROC *proc; /* PGPROC entry of backend, for signaling */
+ /* nextMsgNum is meaningless if proc == NULL or resetState is true. */
int nextMsgNum; /* next message number to read */
bool resetState; /* backend needs to reset its state */
bool signaled; /* backend has been sent catchup signal */
@@ -235,7 +236,7 @@ CreateSharedInvalidationState(void)
/* Mark all backends inactive, and initialize nextLXID */
for (i = 0; i < shmInvalBuffer->maxBackends; i++)
{
- shmInvalBuffer->procState[i].procPid = 0; /* inactive */
+ shmInvalBuffer->procState[i].proc = NULL; /* inactive */
shmInvalBuffer->procState[i].nextMsgNum = 0; /* meaningless */
shmInvalBuffer->procState[i].resetState = false;
shmInvalBuffer->procState[i].signaled = false;
@@ -266,7 +267,7 @@ SharedInvalBackendInit(void)
/* Look for a free entry in the procState array */
for (index = 0; index < segP->lastBackend; index++)
{
- if (segP->procState[index].procPid == 0) /* inactive slot? */
+ if (segP->procState[index].proc == NULL) /* inactive slot? */
{
stateP = &segP->procState[index];
break;
@@ -278,7 +279,7 @@ SharedInvalBackendInit(void)
if (segP->lastBackend < segP->maxBackends)
{
stateP = &segP->procState[segP->lastBackend];
- Assert(stateP->procPid == 0);
+ Assert(stateP->proc == NULL);
segP->lastBackend++;
}
else
@@ -303,7 +304,7 @@ SharedInvalBackendInit(void)
nextLocalTransactionId = stateP->nextLXID;
/* mark myself active, with all extant messages already read */
- stateP->procPid = MyProcPid;
+ stateP->proc = MyProc;
stateP->nextMsgNum = segP->maxMsgNum;
stateP->resetState = false;
stateP->signaled = false;
@@ -341,7 +342,7 @@ CleanupInvalidationState(int status, Datum arg)
stateP->nextLXID = nextLocalTransactionId;
/* Mark myself inactive */
- stateP->procPid = 0;
+ stateP->proc = NULL;
stateP->nextMsgNum = 0;
stateP->resetState = false;
stateP->signaled = false;
@@ -349,7 +350,7 @@ CleanupInvalidationState(int status, Datum arg)
/* Recompute index of last active backend */
for (i = segP->lastBackend; i > 0; i--)
{
- if (segP->procState[i - 1].procPid != 0)
+ if (segP->procState[i - 1].proc != NULL)
break;
}
segP->lastBackend = i;
@@ -374,7 +375,7 @@ BackendIdIsActive(int backendID)
{
ProcState *stateP = &segP->procState[backendID - 1];
- result = (stateP->procPid != 0);
+ result = (stateP->proc != NULL);
}
else
result = false;
@@ -590,7 +591,7 @@ SICleanupQueue(bool callerHasWriteLock, int minFree)
int n = stateP->nextMsgNum;
/* Ignore if inactive or already in reset state */
- if (stateP->procPid == 0 || stateP->resetState)
+ if (stateP->proc == NULL || stateP->resetState)
continue;
/*
@@ -644,18 +645,20 @@ SICleanupQueue(bool callerHasWriteLock, int minFree)
segP->nextThreshold = (numMsgs / CLEANUP_QUANTUM + 1) * CLEANUP_QUANTUM;
/*
- * Lastly, signal anyone who needs a catchup interrupt. Since kill()
- * might not be fast, we don't want to hold locks while executing it.
+ * Lastly, signal anyone who needs a catchup interrupt. Since
+ * SendProcSignal() might not be fast, we don't want to hold locks while
+ * executing it.
*/
if (needSig)
{
- pid_t his_pid = needSig->procPid;
+ PGPROC *his_proc = needSig->proc;
needSig->signaled = true;
LWLockRelease(SInvalReadLock);
LWLockRelease(SInvalWriteLock);
- elog(DEBUG4, "sending sinval catchup signal to PID %d", (int) his_pid);
- kill(his_pid, SIGUSR1);
+ elog(DEBUG4, "sending sinval catchup signal to PID %d",
+ (int) his_proc->pid);
+ SendProcSignal(his_proc, PROCSIG_CATCHUP_INTERRUPT);
if (callerHasWriteLock)
LWLockAcquire(SInvalWriteLock, LW_EXCLUSIVE);
}