Re: ReadRecentBuffer() is broken for local buffer - Mailing list pgsql-hackers

From Richard Guo
Subject Re: ReadRecentBuffer() is broken for local buffer
Date
Msg-id CAMbWs4-m8LpiPfMxRk4ALLaHN7zPCB5hNLa4h1yreZWk6OKKfw@mail.gmail.com
Whole thread Raw
In response to ReadRecentBuffer() is broken for local buffer  (Heikki Linnakangas <hlinnaka@iki.fi>)
List 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

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Unprivileged user can induce crash by using an SUSET param in PGOPTIONS
Next
From: Nathan Bossart
Date:
Subject: Re: optimize lookups in snapshot [sub]xip arrays