Re: GetBufferDescriptor() being called for local buffers from MarkBufferDirtyHint()

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Cc: Ayush Tiwari <ayushtiwari.slg01@gmail.com>, Andres Freund <andres@anarazel.de>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-07-03T03:07:21Z
Lists: pgsql-hackers
On Fri, Jul 03, 2026 at 08:17:22AM +0530, Ashutosh Bapat wrote:
> An actual subtle problem does exist in check_temp_buffers.  If we set
> NLocBuffer to a non-zero value when LocalBufHash is not initialized,
> it's going to prohibit a change in the GUC. If LocalBufHash allocation
> fails, probably user would like to try again by reducing NLocBuffer.
> The prohibition makes that impossible.
> 
> The other such usage in hashbuild() is fine, since it will allocate
> more space if at all.
> 
> CheckForLocalBufferLeaks() walks the local buffer descriptor array,
> but it's already initialized when NLocBuffer is set.

Sure, now a lot of this code is also shaped with some internal static
routines, so I'm also slightly afraid of some refactorings.  It just
feels like in the long-term setting NLocBuffer earlier makes some of
the assumptions of the code a bit more brittle.  Not a bid deal,
still..
--
Michael

Commits

  1. Switch Get[Local]BufferDescriptor() to use a signed value in input

  2. Fix MarkBufferDirtyHint() to not call GetBufferDescriptor() for local buffers

  3. Require share-exclusive lock to set hint bits and to flush