1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-05 02:22:28 +03:00

Back-patch assorted latch-related fixes.

Fix a whole bunch of signal handlers that had been hacked to do things that
might change errno, without adding the necessary save/restore logic for
errno.  Also make some minor fixes in unix_latch.c, and clean up bizarre
and unsafe scheme for disowning the process's latch.  While at it, rename
the PGPROC latch field to procLatch for consistency with 9.2.

Issues noted while reviewing a patch by Peter Geoghegan.
This commit is contained in:
Tom Lane
2011-08-10 12:20:45 -04:00
parent 74d099494c
commit 989f530d3f
9 changed files with 124 additions and 39 deletions

View File

@@ -111,9 +111,6 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
Assert(SHMQueueIsDetached(&(MyProc->syncRepLinks)));
Assert(WalSndCtl != NULL);
/* Reset the latch before adding ourselves to the queue. */
ResetLatch(&MyProc->waitLatch);
LWLockAcquire(SyncRepLock, LW_EXCLUSIVE);
Assert(MyProc->syncRepState == SYNC_REP_NOT_WAITING);
@@ -167,7 +164,7 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
int syncRepState;
/* Must reset the latch before testing state. */
ResetLatch(&MyProc->waitLatch);
ResetLatch(&MyProc->procLatch);
/*
* Try checking the state without the lock first. There's no
@@ -247,11 +244,11 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
}
/*
* Wait on latch for up to 60 seconds. This allows us to check for
* Wait on latch for up to 10 seconds. This allows us to check for
* cancel/die signal or postmaster death regularly while waiting. Note
* that timeout here does not necessarily release from loop.
*/
WaitLatch(&MyProc->waitLatch, 60000L);
WaitLatch(&MyProc->procLatch, 10000L);
}
/*
@@ -322,7 +319,7 @@ SyncRepCancelWait(void)
}
void
SyncRepCleanupAtProcExit(int code, Datum arg)
SyncRepCleanupAtProcExit(void)
{
if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
{
@@ -330,8 +327,6 @@ SyncRepCleanupAtProcExit(int code, Datum arg)
SHMQueueDelete(&(MyProc->syncRepLinks));
LWLockRelease(SyncRepLock);
}
DisownLatch(&MyProc->waitLatch);
}
/*
@@ -560,9 +555,7 @@ SyncRepWakeQueue(bool all)
/*
* Wake only when we have set state and removed from queue.
*/
Assert(SHMQueueIsDetached(&(thisproc->syncRepLinks)));
Assert(thisproc->syncRepState == SYNC_REP_WAIT_COMPLETE);
SetLatch(&(thisproc->waitLatch));
SetLatch(&(thisproc->procLatch));
numprocs++;
}

View File

@@ -373,11 +373,15 @@ WalRcvSigHupHandler(SIGNAL_ARGS)
static void
WalRcvShutdownHandler(SIGNAL_ARGS)
{
int save_errno = errno;
got_SIGTERM = true;
/* Don't joggle the elbow of proc_exit */
if (!proc_exit_inprogress && WalRcvImmediateInterruptOK)
ProcessWalRcvInterrupts();
errno = save_errno;
}
/*

View File

@@ -1188,18 +1188,26 @@ XLogSend(char *msgbuf, bool *caughtup)
static void
WalSndSigHupHandler(SIGNAL_ARGS)
{
int save_errno = errno;
got_SIGHUP = true;
if (MyWalSnd)
SetLatch(&MyWalSnd->latch);
errno = save_errno;
}
/* SIGTERM: set flag to shut down */
static void
WalSndShutdownHandler(SIGNAL_ARGS)
{
int save_errno = errno;
walsender_shutdown_requested = true;
if (MyWalSnd)
SetLatch(&MyWalSnd->latch);
errno = save_errno;
}
/*
@@ -1238,16 +1246,24 @@ WalSndQuickDieHandler(SIGNAL_ARGS)
static void
WalSndXLogSendHandler(SIGNAL_ARGS)
{
int save_errno = errno;
latch_sigusr1_handler();
errno = save_errno;
}
/* SIGUSR2: set flag to do a last cycle and shut down afterwards */
static void
WalSndLastCycleHandler(SIGNAL_ARGS)
{
int save_errno = errno;
walsender_ready_to_stop = true;
if (MyWalSnd)
SetLatch(&MyWalSnd->latch);
errno = save_errno;
}
/* Set up signal handlers */