Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bc153c9

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 514a731 commit bc153c9

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ static void WALInsertLockUpdateInsertingAt(XLogRecPtr insertingAt);
944944
*
945945
* If 'fpw_lsn' is valid, it is the oldest LSN among the pages that this
946946
* WAL record applies to, that were not included in the record as full page
947-
* images. If fpw_lsn >= RedoRecPtr, the function does not perform the
947+
* images. If fpw_lsn <= RedoRecPtr, the function does not perform the
948948
* insertion and returns InvalidXLogRecPtr. The caller can then recalculate
949949
* which pages need a full-page image, and retry. If fpw_lsn is invalid, the
950950
* record is always inserted.
@@ -977,6 +977,7 @@ XLogInsertRecord(XLogRecData *rdata,
977977
info == XLOG_SWITCH);
978978
XLogRecPtr StartPos;
979979
XLogRecPtr EndPos;
980+
bool prevDoPageWrites = doPageWrites;
980981

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

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

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

0 commit comments

Comments
 (0)