pgsql: Add locking around WAL-replay modification of shared-memory vari - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Add locking around WAL-replay modification of shared-memory vari
Date
Msg-id E1RuSSP-00052f-Sk@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Add locking around WAL-replay modification of shared-memory variables.

Originally, most of this code assumed that no Postgres backends could be
running concurrently with it, and so no locking could be needed.  That
assumption fails in Hot Standby.  While it's still true that Hot Standby
backends should never change values like nextXid, they can examine them,
and consistency is important in some cases such as when computing a
snapshot.  Therefore, prudence requires that WAL replay code obtain the
relevant locks when modifying such variables, even though it can examine
them without taking a lock.  We were following that coding rule in some
places but not all.  This commit applies the coding rule uniformly to all
updates of ShmemVariableCache and MultiXactState fields; a search of the
replay routines did not find any other cases that seemed to be at risk.

In addition, this commit fixes a longstanding thinko in replay of NEXTOID
and checkpoint records: we tried to advance nextOid only if it was behind
the value in the WAL record, but the comparison would draw the wrong
conclusion if OID wraparound had occurred since the previous value.
Better to just unconditionally assign the new value, since OID assignment
shouldn't be happening during replay anyway.

The additional locking seems to be more in the nature of future-proofing
than fixing any live bug, so I am not going to back-patch it.  The NEXTOID
fix will be back-patched separately.

Branch
------
master

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

Modified Files
--------------
src/backend/access/transam/multixact.c |   12 ++++++--
src/backend/access/transam/twophase.c  |    6 ++++
src/backend/access/transam/xlog.c      |   49 +++++++++++++++++++++++--------
src/backend/storage/ipc/procarray.c    |   28 +++++++++++++++--
4 files changed, 75 insertions(+), 20 deletions(-)


pgsql-committers by date:

Previous
From: Robert Haas
Date:
Subject: pgsql: Remove dead declaration.
Next
From: Robert Haas
Date:
Subject: pgsql: pg_dump: Reduce dependencies on global variables.