pgsql: Introduce a pipe between postmaster and each backend, which can

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Introduce a pipe between postmaster and each backend, which can
Date: 2011-07-08 16:06:02
Message-ID: E1QfDZ4-0001j5-7m@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/89fd72cbf26f5d2e3d86ab19c1ead73ab8fac0fe

Modified Files
--------------
src/backend/access/transam/xlog.c | 4 +-
src/backend/port/unix_latch.c | 101 ++++++++++++++++++++++----------
src/backend/port/win32_latch.c | 98 ++++++++++++++++++++++--------
src/backend/postmaster/autovacuum.c | 4 +-
src/backend/postmaster/bgwriter.c | 2 +-
src/backend/postmaster/pgarch.c | 61 +++++++++++++------
src/backend/postmaster/pgstat.c | 2 +-
src/backend/postmaster/postmaster.c | 106 +++++++++++++++++++++++++++------
src/backend/postmaster/walwriter.c | 2 +-
src/backend/replication/syncrep.c | 4 +-
src/backend/replication/walreceiver.c | 2 +-
src/backend/replication/walsender.c | 13 +++--
src/backend/storage/ipc/pmsignal.c | 41 ++++---------
src/include/postmaster/postmaster.h | 8 +++
src/include/storage/latch.h | 13 +++-
src/include/storage/pmsignal.h | 2 +-
16 files changed, 322 insertions(+), 141 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2011-07-08 21:03:31 pgsql: Fix another oversight in logging of changes in postgresql.conf s
Previous Message Heikki Linnakangas 2011-07-08 14:34:05 pgsql: Fix one overflow and one signedness error, caused by the patch t