From: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
To: PostgreSQL-Dev <pgsql-hackers@postgresql.org>
Subject: [PATCH] XLogReadRecord returns pointer to currently read page
Date: Fri, 17 Aug 2018 08:47:15 +0500
Message-ID: <c2ea54dd-a1d3-80eb-ddbf-7e6f258e615e@postgrespro.ru> (raw)
Hi, hackers!
I propose the patch for fix one small code defect.
The XLogReadRecord() function reads the pages of a WAL segment that
contain a WAL-record. Then it creates a readRecordBuf buffer in private
memory of a backend and copy record from the pages to the readRecordBuf
buffer. Pointer 'record' is set to the beginning of the readRecordBuf
buffer.
But if the WAL-record is fully placed on one page, the XLogReadRecord()
function forgets to bind the "record" pointer with the beginning of the
readRecordBuf buffer. In this case, XLogReadRecord() returns a pointer
to an internal xlog page. This patch fixes the defect.
Previously, in all cases of using WAL this was not a problem. However if
you plan to perform some decoding operations before returning the WAL
record to the caller (this is my case), this can lead to bugs that are
difficult to catch.
--
Andrey Lepikhov
Postgres Professional
https://postgrespro.com
The Russian Postgres Company
Attachments:0001-WAL-record-local-buffer-pointer-fix.patch (text/x-patch, 775B) download
From 0a7d7bf07eb91a959b2864a7497088c4d203aaa4 Mon Sep 17 00:00:00 2001
From: "Andrey V. Lepikhov" <a.lepikhov@postgrespro.ru>
Date: Fri, 17 Aug 2018 07:56:30 +0500
Subject: [PATCH] WAL record local buffer pointer fix
---
src/backend/access/transam/xlogreader.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.cindex 4c633c6c49..7bccc68189 100644--- a/src/backend/access/transam/xlogreader.c+++ b/src/backend/access/transam/xlogreader.c@@ -480,6 +480,7 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg)
state->ReadRecPtr = RecPtr;
memcpy(state->readRecordBuf, record, total_len);
+ record = (XLogRecord *) state->readRecordBuf;
}
/*
--
2.17.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: a.lepikhov@postgrespro.ru
Subject: Re: [PATCH] XLogReadRecord returns pointer to currently read page
In-Reply-To: <c2ea54dd-a1d3-80eb-ddbf-7e6f258e615e@postgrespro.ru>
References: <c2ea54dd-a1d3-80eb-ddbf-7e6f258e615e@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox