0003-Don-t-retry-inside-XLogPageRead-if-reading-ahead.patch

text/x-patch

Filename: 0003-Don-t-retry-inside-XLogPageRead-if-reading-ahead.patch
Type: text/x-patch
Part: 2
Message: Re: logical decoding and replication of sequences

Patch

Format: format-patch
Series: patch 0003
Subject: Don't retry inside XLogPageRead() if reading ahead.
File+
src/backend/access/transam/xlogrecovery.c 8 0
From bb8a6d52ca91d463993c3e01a48fc776297b0aeb Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Mon, 29 Aug 2022 21:14:25 +1200
Subject: [PATCH 3/3] Don't retry inside XLogPageRead() if reading ahead.

Give up immediately if we have a short read or a page header
invalidation failure inside XLogPageRead().  Once recovery catches up to
this point, it can deal with it.  This doesn't fix any known live bug,
but it fits with the general philosophy of giving up fast when
prefetching runs into trouble.
---
 src/backend/access/transam/xlogrecovery.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 422322cf5a..76ce9704ca 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -3342,6 +3342,14 @@ retry:
 	return readLen;
 
 next_record_is_invalid:
+	/*
+	 * If we're reading ahead, give up fast.  Standby retries and error
+	 * reporting will be handled by a later read when recovery catches up to
+	 * this point.
+	 */
+	if (xlogreader->nonblocking)
+		return XLREAD_WOULDBLOCK;
+
 	lastSourceFailed = true;
 
 	if (readFile >= 0)
-- 
2.30.2