v23-0004-Do-away-with-zero-padding-assumption-before-WALR.patch

application/x-patch

Filename: v23-0004-Do-away-with-zero-padding-assumption-before-WALR.patch
Type: application/x-patch
Part: 1
Message: Re: Improve WALRead() to suck data directly from WAL buffers when possible

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v23-0004
Subject: Do away with zero-padding assumption before WALRead
File+
src/backend/access/transam/xlogutils.c 2 8
src/backend/postmaster/walsummarizer.c 1 6
src/backend/replication/walsender.c 1 1
From c43e78ec2738c92bd7c73e9ec96ba72acc594bc1 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Fri, 16 Feb 2024 06:56:23 +0000
Subject: [PATCH v23 4/5] Do away with zero-padding assumption before WALRead

---
 src/backend/access/transam/xlogutils.c | 10 ++--------
 src/backend/postmaster/walsummarizer.c |  7 +------
 src/backend/replication/walsender.c    |  2 +-
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index d4872ec170..8fb2e68e85 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -1010,19 +1010,13 @@ read_local_xlog_page_guts(XLogReaderState *state, XLogRecPtr targetPagePtr,
 	}
 
 	/* attempt to read WAL from WAL buffers first */
-	nbytes = XLOG_BLCKSZ;
+	nbytes = count;
 	rbytes = WALReadFromBuffers(cur_page, targetPagePtr, nbytes, currTLI);
 	cur_page += rbytes;
 	targetPagePtr += rbytes;
 	nbytes -= rbytes;
 
-	/*
-	 * Now read the remaining WAL from WAL file.
-	 *
-	 * Even though we just determined how much of the page can be validly read
-	 * as 'count', read the whole page anyway. It's guaranteed to be
-	 * zero-padded up to the page boundary if it's incomplete.
-	 */
+	/* now read the remaining WAL from WAL file */
 	if (nbytes > 0 &&
 		!WALRead(state, cur_page, targetPagePtr, nbytes, tli,
 				 &errinfo))
diff --git a/src/backend/postmaster/walsummarizer.c b/src/backend/postmaster/walsummarizer.c
index 3e1b146538..e85d497034 100644
--- a/src/backend/postmaster/walsummarizer.c
+++ b/src/backend/postmaster/walsummarizer.c
@@ -1318,12 +1318,7 @@ summarizer_read_local_xlog_page(XLogReaderState *state,
 		}
 	}
 
-	/*
-	 * Even though we just determined how much of the page can be validly read
-	 * as 'count', read the whole page anyway. It's guaranteed to be
-	 * zero-padded up to the page boundary if it's incomplete.
-	 */
-	if (!WALRead(state, cur_page, targetPagePtr, XLOG_BLCKSZ,
+	if (!WALRead(state, cur_page, targetPagePtr, count,
 				 private_data->tli, &errinfo))
 		WALReadRaiseError(&errinfo);
 
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 24687dab28..7ecc7174a0 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1098,7 +1098,7 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
 		count = flushptr - targetPagePtr;	/* part of the page available */
 
 	/* attempt to read WAL from WAL buffers first */
-	nbytes = XLOG_BLCKSZ;
+	nbytes = count;
 	rbytes = WALReadFromBuffers(cur_page, targetPagePtr, nbytes, currTLI);
 	cur_page += rbytes;
 	targetPagePtr += rbytes;
-- 
2.34.1