pgsql: Fix management of pendingOpsTable in auxiliary processes.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix management of pendingOpsTable in auxiliary processes.
Date: 2012-07-18 19:38:03
Message-ID: E1Sra4R-0001kv-9K@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix management of pendingOpsTable in auxiliary processes.

mdinit() was misusing IsBootstrapProcessingMode() to decide whether to
create an fsync pending-operations table in the current process. This led
to creating a table not only in the startup and checkpointer processes as
intended, but also in the bgwriter process, not to mention other auxiliary
processes such as walwriter and walreceiver. Creation of the table in the
bgwriter is fatal, because it absorbs fsync requests that should have gone
to the checkpointer; instead they just sit in bgwriter local memory and are
never acted on. So writes performed by the bgwriter were not being fsync'd
which could result in data loss after an OS crash. I think there is no
live bug with respect to walwriter and walreceiver because those never
perform any writes of shared buffers; but the potential is there for
future breakage in those processes too.

To fix, make AuxiliaryProcessMain() export the current process's
AuxProcType as a global variable, and then make mdinit() test directly for
the types of aux process that should have a pendingOpsTable. Having done
that, we might as well also get rid of the random bool flags such as
am_walreceiver that some of the aux processes had grown. (Note that we
could not have fixed the bug by examining those variables in mdinit(),
because it's called from BaseInit() which is run by AuxiliaryProcessMain()
before entering any of the process-type-specific code.)

Back-patch to 9.2, where the problem was introduced by the split-up of
bgwriter and checkpointer processes. The bogus pendingOpsTable exists
in walwriter and walreceiver processes in earlier branches, but absent
any evidence that it causes actual problems there, I'll leave the older
branches alone.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/d843589e5ab361dd4738dab5c9016e704faf4153

Modified Files
--------------
src/backend/access/transam/xlog.c | 2 +-
src/backend/bootstrap/bootstrap.c | 20 +++++++++------
src/backend/postmaster/bgwriter.c | 11 +-------
src/backend/postmaster/checkpointer.c | 13 ++++------
src/backend/postmaster/walwriter.c | 4 +-
src/backend/replication/walreceiver.c | 6 +----
src/backend/storage/ipc/procsignal.c | 1 -
src/backend/storage/smgr/md.c | 7 ++---
src/include/bootstrap/bootstrap.h | 12 ---------
src/include/miscadmin.h | 42 ++++++++++++++++++++++++++++----
src/include/replication/walreceiver.h | 1 -
11 files changed, 62 insertions(+), 57 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2012-07-18 19:40:48 pgsql: Fix statistics breakage from bgwriter/checkpointer process split
Previous Message Heikki Linnakangas 2012-07-18 15:17:20 Re: Re: [COMMITTERS] pgsql: Fix mapping of PostgreSQL encodings to Python encodings.