diff options
| author | Heikki Linnakangas | 2011-07-08 15:27:49 +0000 |
|---|---|---|
| committer | Heikki Linnakangas | 2011-07-08 15:44:07 +0000 |
| commit | 89fd72cbf26f5d2e3d86ab19c1ead73ab8fac0fe (patch) | |
| tree | fa0605f7ec1ff3a798b1c22fd847185158288a8b /src/include/postmaster | |
| parent | 9598afa3b0f7a7fdcf3740173346950b2bd5942c (diff) | |
Introduce a pipe between postmaster and each backend, which can be used to
detect postmaster death. Postmaster keeps the write-end of the pipe open,
so when it dies, children get EOF in the read-end. That can conveniently
be waited for in select(), which allows eliminating some of the polling
loops that check for postmaster death. This patch doesn't yet change all
the loops to use the new mechanism, expect a follow-on patch to do that.
This changes the interface to WaitLatch, so that it takes as argument a
bitmask of events that it waits for. Possible events are latch set, timeout,
postmaster death, and socket becoming readable or writeable.
The pipe method behaves slightly differently from the kill() method
previously used in PostmasterIsAlive() in the case that postmaster has died,
but its parent has not yet read its exit code with waitpid(). The pipe
returns EOF as soon as the process dies, but kill() continues to return
true until waitpid() has been called (IOW while the process is a zombie).
Because of that, change PostmasterIsAlive() to use the pipe too, otherwise
WaitLatch() would return immediately with WL_POSTMASTER_DEATH, while
PostmasterIsAlive() would claim it's still alive. That could easily lead to
busy-waiting while postmaster is in zombie state.
Peter Geoghegan with further changes by me, reviewed by Fujii Masao and
Florian Pflug.
Diffstat (limited to 'src/include/postmaster')
| -rw-r--r-- | src/include/postmaster/postmaster.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index f7072f55cf8..be4f8a74989 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -32,6 +32,14 @@ extern bool restart_after_crash; #ifdef WIN32 extern HANDLE PostmasterHandle; +#else +extern int postmaster_alive_fds[2]; +/* + * Constants that represent which of postmaster_alive_fds is held by + * postmaster, and which is used in children to check for postmaster death. + */ +#define POSTMASTER_FD_WATCH 0 /* used in children to check for postmaster death */ +#define POSTMASTER_FD_OWN 1 /* kept open by postmaster only */ #endif extern const char *progname; |
