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

Commit 6860198

Browse files
committed
Make recovery report error message when invalid page header is found.
Commit 0668719 changed XLogPageRead() so that it validated the page header, if invalid page header was found reset the error message and retried reading the page, to fix the scenario where streaming standby got stuck at a continuation record. This change hid the error message about invalid page header, which would make it harder for users to investigate what the actual issue was found in WAL. To fix the issue, this commit makes XLogPageRead() report the error message when invalid page header is found. When not in standby mode, an invalid page header should cause recovery to end, not retry reading the page, so XLogPageRead() doesn't need to validate the page header for the retry. Instead, ReadPageInternal() should be responsible for the validation in that case. Therefore this commit changes XLogPageRead() so that if not in standby mode it doesn't validate the page header for the retry. Reported-by: Yugo Nagata Author: Yugo Nagata, Kyotaro Horiguchi Reviewed-by: Ranier Vilela, Fujii Masao Discussion: https://postgr.es/m/20210718045505.32f463ed6c227111038d8ae4@sraoss.co.jp
1 parent f3fec23 commit 6860198

File tree

1 file changed

+16
-2
lines changed
  • src/backend/access/transam

1 file changed

+16
-2
lines changed

src/backend/access/transam/xlog.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -12423,7 +12423,7 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1242312423

1242412424
/*
1242512425
* Check the page header immediately, so that we can retry immediately if
12426-
* it's not valid. This may seem unnecessary, because XLogReadRecord()
12426+
* it's not valid. This may seem unnecessary, because ReadPageInternal()
1242712427
* validates the page header anyway, and would propagate the failure up to
1242812428
* ReadRecord(), which would retry. However, there's a corner case with
1242912429
* continuation records, if a record is split across two pages such that
@@ -12447,9 +12447,23 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1244712447
*
1244812448
* Validating the page header is cheap enough that doing it twice
1244912449
* shouldn't be a big deal from a performance point of view.
12450+
*
12451+
* When not in standby mode, an invalid page header should cause recovery
12452+
* to end, not retry reading the page, so we don't need to validate the
12453+
* page header here for the retry. Instead, ReadPageInternal() is
12454+
* responsible for the validation.
1245012455
*/
12451-
if (!XLogReaderValidatePageHeader(xlogreader, targetPagePtr, readBuf))
12456+
if (StandbyMode &&
12457+
!XLogReaderValidatePageHeader(xlogreader, targetPagePtr, readBuf))
1245212458
{
12459+
/*
12460+
* Emit this error right now then retry this page immediately. Use
12461+
* errmsg_internal() because the message was already translated.
12462+
*/
12463+
if (xlogreader->errormsg_buf[0])
12464+
ereport(emode_for_corrupt_record(emode, EndRecPtr),
12465+
(errmsg_internal("%s", xlogreader->errormsg_buf)));
12466+
1245312467
/* reset any error XLogReaderValidatePageHeader() might have set */
1245412468
xlogreader->errormsg_buf[0] = '\0';
1245512469
goto next_record_is_invalid;

0 commit comments

Comments
 (0)