Skip to content

Commit ff4220e

Browse files
author
Amit Kapila
committed
Attach FPI to the first record after full_page_writes is turned on.
XLogInsert fails to attach a required FPI to the first record after full_page_writes is turned on by the last checkpoint. This bug got introduced in 9.5 due to code rearrangement in commits 2c03216 and 2076db2. Fix it by ensuring that XLogInsertRecord performs a recomputation when the given record is generated with FPW as off but found that the flag has been turned on while actually inserting the record. Reported-by: Kyotaro Horiguchi Author: Kyotaro Horiguchi Reviewed-by: Amit Kapila Backpatch-through: 9.5 where this problem was introduced Discussion: https://postgr.es/m/20180420.151043.74298611.horiguchi.kyotaro@lab.ntt.co.jp
1 parent 12368f5 commit ff4220e

File tree

1 file changed

+13
-6
lines changed
  • src/backend/access/transam

1 file changed

+13
-6
lines changed

src/backend/access/transam/xlog.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ static void WALInsertLockUpdateInsertingAt(XLogRecPtr insertingAt);
943943
*
944944
* If 'fpw_lsn' is valid, it is the oldest LSN among the pages that this
945945
* WAL record applies to, that were not included in the record as full page
946-
* images. If fpw_lsn >= RedoRecPtr, the function does not perform the
946+
* images. If fpw_lsn <= RedoRecPtr, the function does not perform the
947947
* insertion and returns InvalidXLogRecPtr. The caller can then recalculate
948948
* which pages need a full-page image, and retry. If fpw_lsn is invalid, the
949949
* record is always inserted.
@@ -976,6 +976,7 @@ XLogInsertRecord(XLogRecData *rdata,
976976
info == XLOG_SWITCH);
977977
XLogRecPtr StartPos;
978978
XLogRecPtr EndPos;
979+
bool prevDoPageWrites = doPageWrites;
979980

980981
/* we assume that all of the record header is in the first chunk */
981982
Assert(rdata->len >= SizeOfXLogRecord);
@@ -1023,10 +1024,14 @@ XLogInsertRecord(XLogRecData *rdata,
10231024
WALInsertLockAcquire();
10241025

10251026
/*
1026-
* Check to see if my copy of RedoRecPtr or doPageWrites is out of date.
1027-
* If so, may have to go back and have the caller recompute everything.
1028-
* This can only happen just after a checkpoint, so it's better to be slow
1029-
* in this case and fast otherwise.
1027+
* Check to see if my copy of RedoRecPtr is out of date. If so, may have
1028+
* to go back and have the caller recompute everything. This can only
1029+
* happen just after a checkpoint, so it's better to be slow in this case
1030+
* and fast otherwise.
1031+
*
1032+
* Also check to see if fullPageWrites or forcePageWrites was just turned
1033+
* on; if we weren't already doing full-page writes then go back and
1034+
* recompute.
10301035
*
10311036
* If we aren't doing full-page writes then RedoRecPtr doesn't actually
10321037
* affect the contents of the XLOG record, so we'll update our local copy
@@ -1041,7 +1046,9 @@ XLogInsertRecord(XLogRecData *rdata,
10411046
}
10421047
doPageWrites = (Insert->fullPageWrites || Insert->forcePageWrites);
10431048

1044-
if (fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr && doPageWrites)
1049+
if (doPageWrites &&
1050+
(!prevDoPageWrites ||
1051+
(fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr)))
10451052
{
10461053
/*
10471054
* Oops, some buffer now needs to be backed up that the caller didn't

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy