diff options
author | Thomas Munro <tmunro@postgresql.org> | 2018-11-23 20:16:41 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2018-11-23 20:46:34 +1300 |
commit | cfdf4dc4fc9635ac8bf6eaaa5dbbcd364ab29f0c (patch) | |
tree | c1e3c40912c5f9274fb9381bea1082f6a2cc2296 /src/backend/storage/lmgr/condition_variable.c | |
parent | d392e9bdea957964e1fa6a5481e5adb5904d759a (diff) | |
download | postgresql-cfdf4dc4fc9635ac8bf6eaaa5dbbcd364ab29f0c.tar.gz postgresql-cfdf4dc4fc9635ac8bf6eaaa5dbbcd364ab29f0c.zip |
Add WL_EXIT_ON_PM_DEATH pseudo-event.
Users of the WaitEventSet and WaitLatch() APIs can now choose between
asking for WL_POSTMASTER_DEATH and then handling it explicitly, or asking
for WL_EXIT_ON_PM_DEATH to trigger immediate exit on postmaster death.
This reduces code duplication, since almost all callers want the latter.
Repair all code that was previously ignoring postmaster death completely,
or requesting the event but ignoring it, or requesting the event but then
doing an unconditional PostmasterIsAlive() call every time through its
event loop (which is an expensive syscall on platforms for which we don't
have USE_POSTMASTER_DEATH_SIGNAL support).
Assert that callers of WaitLatchXXX() under the postmaster remember to
ask for either WL_POSTMASTER_DEATH or WL_EXIT_ON_PM_DEATH, to prevent
future bugs.
The only process that doesn't handle postmaster death is syslogger. It
waits until all backends holding the write end of the syslog pipe
(including the postmaster) have closed it by exiting, to be sure to
capture any parting messages. By using the WaitEventSet API directly
it avoids the new assertion, and as a by-product it may be slightly
more efficient on platforms that have epoll().
Author: Thomas Munro
Reviewed-by: Kyotaro Horiguchi, Heikki Linnakangas, Tom Lane
Discussion: https://postgr.es/m/CAEepm%3D1TCviRykkUb69ppWLr_V697rzd1j3eZsRMmbXvETfqbQ%40mail.gmail.com,
https://postgr.es/m/CAEepm=2LqHzizbe7muD7-2yHUbTOoF7Q+qkSD5Q41kuhttRTwA@mail.gmail.com
Diffstat (limited to 'src/backend/storage/lmgr/condition_variable.c')
-rw-r--r-- | src/backend/storage/lmgr/condition_variable.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/backend/storage/lmgr/condition_variable.c b/src/backend/storage/lmgr/condition_variable.c index ef1d5baf016..7f75ee61cd6 100644 --- a/src/backend/storage/lmgr/condition_variable.c +++ b/src/backend/storage/lmgr/condition_variable.c @@ -72,7 +72,7 @@ ConditionVariablePrepareToSleep(ConditionVariable *cv) new_event_set = CreateWaitEventSet(TopMemoryContext, 2); AddWaitEventToSet(new_event_set, WL_LATCH_SET, PGINVALID_SOCKET, MyLatch, NULL); - AddWaitEventToSet(new_event_set, WL_POSTMASTER_DEATH, PGINVALID_SOCKET, + AddWaitEventToSet(new_event_set, WL_EXIT_ON_PM_DEATH, PGINVALID_SOCKET, NULL, NULL); /* Don't set cv_wait_event_set until we have a correct WES. */ cv_wait_event_set = new_event_set; @@ -154,16 +154,8 @@ ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info) * Wait for latch to be set. (If we're awakened for some other * reason, the code below will cope anyway.) */ - WaitEventSetWait(cv_wait_event_set, -1, &event, 1, wait_event_info); - - if (event.events & WL_POSTMASTER_DEATH) - { - /* - * Emergency bailout if postmaster has died. This is to avoid the - * necessity for manual cleanup of all postmaster children. - */ - exit(1); - } + (void) WaitEventSetWait(cv_wait_event_set, -1, &event, 1, + wait_event_info); /* Reset latch before examining the state of the wait list. */ ResetLatch(MyLatch); |