Re: ReadRecentBuffer() is broken for local buffer
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>,
Thomas Munro <thomas.munro@gmail.com>
Date: 2022-07-25T03:51:40Z
Lists: pgsql-hackers
On Mon, Jul 25, 2022 at 2:22 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote:
> if (BufferIsLocal(recent_buffer))
> {
> - bufHdr = GetBufferDescriptor(-recent_buffer - 1);
> + bufHdr = GetLocalBufferDescriptor(-recent_buffer - 1);
Aha, we're using the wrong buffer descriptors here. Currently this
function is only called in XLogReadBufferExtended(), so the branch for
local buffer cannot be reached. Maybe that's why it is not identified
until now.
> The code after that looks suspicious, too. It increases the usage count
> even if the buffer was already pinned. That's different from what it
> does for a shared buffer, and different from LocalBufferAlloc(). That's
> pretty harmless, just causes the usage count to be bumped more
> frequently, but I don't think it was intentional. The ordering of
> bumping the usage count, the local ref count, and registration in the
> resource owner are different too. As far as I can see, that makes no
> difference, but I think we should keep this code as close as possible to
> similar code used elsewhere, unless there's a particular reason to differ.
Agree. Maybe we can wrap the codes in an inline function or macro and
call that in both LocalBufferAlloc and here.
Thanks
Richard
Commits
-
Fix ReadRecentBuffer for local buffers.
- 3f968b941504 14.5 landed
- 19f82323db63 15.0 landed
- 7a08f78aea95 16.0 landed