Re: [PATCH] XLogReadRecord returns pointer to currently read page

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: a.lepikhov@postgrespro.ru, PostgreSQL-Dev <pgsql-hackers@postgresql.org>
Date: 2018-10-21T21:06:02Z
Lists: pgsql-hackers
On 17/08/2018 06:47, Andrey Lepikhov wrote:
> 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.

Hmm. I agree it looks weird the way it is. But I wonder, why do we even 
copy the record to readRecordBuf, if it fits on the WAL page? Returning 
a pointer to the xlog page buffer seems OK in that case. What if we 
remove the memcpy(), instead?

- Heikki


Commits

  1. Improve description of buffer used to store records in WAL reader

  2. Remove unnecessary memcpy when reading WAL record fitting on page