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

From: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: GetBufferDescriptor() being called for local buffers from MarkBufferDirtyHint()
Date: 2026-06-29 07:59:09
Message-ID: CAJTYsWV3S==CdVx9XL4EvWMWZUcyVadizriWSLA5FSUsrEXipA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Thu, 11 Jun 2026 at 03:44, Michael Paquier <michael(at)paquier(dot)xyz> wrote:

> On Wed, Jun 10, 2026 at 10:36:22AM -0400, Andres Freund wrote:
> > I think it *should* blow up. It doesn't because we're lacking assertions
> in
> > GetBufferDescriptor(). But I don't think the assertions added in the
> patch are
> > quite right.
> >
> > We can't trivially add the correct assertions, because somebody though
> it was
> > a good idea to give GetBufferDescriptor() a uint32 parameter, which seems
> > completely wrong to me.
>
> This one is not as old as I expected: 3ac88fddd92c. You're right that
> switching that to be signed would be a correct first step forward.
>

Given the discussion here, I tried making the buffer descriptor accessors
take
a signed index and adding range assertions.

Most callers already pass signed buffer indexes derived from Buffer values
(e.g. buffer - 1, or -buffer - 1 for local buffers). The only caller I
found
that passes an unsigned value to GetBufferDescriptor() is ClockSweepTick(),
and
that normalizes the value before returning it, so it should still be less
than
NBuffers.

The change looked fairly straightforward to me, unless I'm missing
something.
I also made the same change for GetLocalBufferDescriptor(), since it has the
same uint32 signature and takes local buffer indexes.

Thoughts?

Regards,
Ayush

Attachment Content-Type Size
v1-0001-Make-buffer-descriptor-accessors-take-signed-int-.patch application/octet-stream 1.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message JoongHyuk Shin 2026-06-29 07:59:40 Re: [PATCH] Don't call ereport(ERROR) from recovery target GUC assign hooks
Previous Message Andrey Borodin 2026-06-29 07:46:57 Re: Why clearing the VM doesn't require registering vm buffer in wal record