From 5c5871111a754ea92eee1a07248f05582e608cbe Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Fri, 27 Sep 2024 17:47:05 +0200 Subject: [PATCH] WalProposer: Read WAL directly from WAL buffers in PG17 (#9171) This reduces the overhead of the WalProposer when it is not being throttled by SK WAL acceptance rate --- pgxn/neon/walproposer_pg.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pgxn/neon/walproposer_pg.c b/pgxn/neon/walproposer_pg.c index 4d0d06e6de..bb65a11c7d 100644 --- a/pgxn/neon/walproposer_pg.c +++ b/pgxn/neon/walproposer_pg.c @@ -1473,11 +1473,33 @@ walprop_pg_wal_read(Safekeeper *sk, char *buf, XLogRecPtr startptr, Size count, { NeonWALReadResult res; - res = NeonWALRead(sk->xlogreader, - buf, - startptr, - count, - walprop_pg_get_timeline_id()); +#if PG_MAJORVERSION_NUM >= 17 + if (!sk->wp->config->syncSafekeepers) + { + Size rbytes; + rbytes = WALReadFromBuffers(buf, startptr, count, + walprop_pg_get_timeline_id()); + + startptr += rbytes; + count -= rbytes; + } +#endif + + if (count == 0) + { + res = NEON_WALREAD_SUCCESS; + } + else + { + Assert(count > 0); + + /* Now read the remaining WAL from the WAL file */ + res = NeonWALRead(sk->xlogreader, + buf, + startptr, + count, + walprop_pg_get_timeline_id()); + } if (res == NEON_WALREAD_SUCCESS) {