Hi,

It looks like we have an unnecessary XLogSegNoOffsetToRecPtr() in
XLogReaderValidatePageHeader(). We pass the start LSN of the WAL page
and check if it matches with the LSN that was stored in the WAL page
header (xlp_pageaddr). We find segno, offset and LSN again using
XLogSegNoOffsetToRecPtr(). This happens to be the same as the passed
in LSN 'recptr'.

Here's a tiny patch removing the unnecessary XLogSegNoOffsetToRecPtr()
and using the passed in 'recptr'.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
From c831b7fdd6a0b053fedbf37b2bbda5d73739d42f Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Sun, 9 Oct 2022 09:53:39 +0000
Subject: [PATCH v1] Remove an unnecessary LSN calculation while validating WAL
 page header

---
 src/backend/access/transam/xlogreader.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 5a8fe81f82..93f667b254 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -1210,7 +1210,6 @@ bool
 XLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr,
 							 char *phdr)
 {
-	XLogRecPtr	recaddr;
 	XLogSegNo	segno;
 	int32		offset;
 	XLogPageHeader hdr = (XLogPageHeader) phdr;
@@ -1220,8 +1219,6 @@ XLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr,
 	XLByteToSeg(recptr, segno, state->segcxt.ws_segsize);
 	offset = XLogSegmentOffset(recptr, state->segcxt.ws_segsize);
 
-	XLogSegNoOffsetToRecPtr(segno, offset, state->segcxt.ws_segsize, recaddr);
-
 	if (hdr->xlp_magic != XLOG_PAGE_MAGIC)
 	{
 		char		fname[MAXFNAMELEN];
@@ -1296,7 +1293,7 @@ XLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr,
 	 * check typically fails when an old WAL segment is recycled, and hasn't
 	 * yet been overwritten with new data yet.
 	 */
-	if (hdr->xlp_pageaddr != recaddr)
+	if (hdr->xlp_pageaddr != recptr)
 	{
 		char		fname[MAXFNAMELEN];
 
-- 
2.34.1

Reply via email to