mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Change the autovacuum launcher to use WaitLatch instead of a poll loop.
In pursuit of this (and with the expectation that WaitLatch will be needed in more places), convert the latch field that was already added to PGPROC for sync rep into a generic latch that is activated for all PGPROC-owning processes, and change many of the standard backend signal handlers to set that latch when a signal happens. This will allow WaitLatch callers to be wakened properly by these signals. In passing, 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. Much of this has to be back-patched into 9.1. Peter Geoghegan, with additional work by Tom
This commit is contained in:
@@ -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,10 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait on latch for up to 60 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.
|
||||
* Wait on latch. Any condition that should wake us up will set
|
||||
* the latch, so no need for timeout.
|
||||
*/
|
||||
WaitLatch(&MyProc->waitLatch, WL_LATCH_SET | WL_TIMEOUT, 60000L);
|
||||
WaitLatch(&MyProc->procLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -322,7 +318,7 @@ SyncRepCancelWait(void)
|
||||
}
|
||||
|
||||
void
|
||||
SyncRepCleanupAtProcExit(int code, Datum arg)
|
||||
SyncRepCleanupAtProcExit(void)
|
||||
{
|
||||
if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
|
||||
{
|
||||
@@ -330,8 +326,6 @@ SyncRepCleanupAtProcExit(int code, Datum arg)
|
||||
SHMQueueDelete(&(MyProc->syncRepLinks));
|
||||
LWLockRelease(SyncRepLock);
|
||||
}
|
||||
|
||||
DisownLatch(&MyProc->waitLatch);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -567,9 +561,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++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user