pgsql: Consistency check should compare last record replayed, not last - Mailing list pgsql-committers

From Heikki Linnakangas
Subject pgsql: Consistency check should compare last record replayed, not last
Date
Msg-id E1TiTBC-0006pR-Vt@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Consistency check should compare last record replayed, not last record read.

EndRecPtr is the last record that we've read, but not necessarily yet
replayed. CheckRecoveryConsistency should compare minRecoveryPoint with the
last replayed record instead. This caused recovery to think it's reached
consistency too early.

Now that we do the check in CheckRecoveryConsistency correctly, we have to
move the call of that function to after redoing a record. The current place,
after reading a record but before replaying it, is wrong. In particular, if
there are no more records after the one ending at minRecoveryPoint, we don't
enter hot standby until one extra record is generated and read by the
standby, and CheckRecoveryConsistency is called. These two bugs conspired
to make the code appear to work correctly, except for the small window
between reading the last record that reaches minRecoveryPoint, and
replaying it.

In the passing, rename recoveryLastRecPtr, which is the last record
replayed, to lastReplayedEndRecPtr. This makes it slightly less confusing
with replayEndRecPtr, which is the last record read that we're about to
replay.

Original report from Kyotaro HORIGUCHI, further diagnosis by Fujii Masao.
Backpatch to 9.0, where Hot Standby subtly changed the test from
"minRecoveryPoint < EndRecPtr" to "minRecoveryPoint <= EndRecPtr". The
former works because where the test is performed, we have always read one
more record than we've replayed.

Branch
------
REL9_2_STABLE

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

Modified Files
--------------
src/backend/access/transam/xlog.c |   36 +++++++++++++++++++++---------------
1 files changed, 21 insertions(+), 15 deletions(-)


pgsql-committers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: pgsql: Consistency check should compare last record replayed, not last
Next
From: Heikki Linnakangas
Date:
Subject: pgsql: Consistency check should compare last record replayed, not last