Re: Fix comments for buf_id field of BufferDesc structure

From: Daniil Davydov <3danissimo(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix comments for buf_id field of BufferDesc structure
Date: 2026-01-20 08:22:22
Message-ID: CAJDiXghykihizK5Hw99jETrsGUjgN0P1=BLQfEN76xb97tAY4g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Tue, Jan 20, 2026 at 1:59 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
> Good catch. But I think we should retain the explanation for -2. How about like:
>
> For buf_internal.h:
> ```
> /*
> * Buffer's index number: >= 0 for shared buffers, < -1 for local buffers.
> * * For shared buffers, buf_id is 0 to NBuffers-1.
> * * For local buffers, buf_id is -2 to -NLocBuffers-1.
> *
> * This ensures that (buf_id+1) done by BufferDescriptorGetBuffer never returns InvalidBuffer(0).
> */
> int buf_id;
> ```
>
> For localbuf.c
> ```
> /*
> * buf_id must be <= -2 for local buffers so that the
> * Buffer handle (buf_id + 1) is <= -1, avoiding InvalidBuffer (0)
> */
> ```

Thank you for looking into this!
I agree with your suggestion to add "This ensures that ..." comment. But if
we add it, I guess that we won't need to duplicate this comment in localbuf.c .

BTW, maybe it is not good that we are hardcoding the name of the
BufferDescriptorGetBuffer function in the comments, but I saw the same thing
in several other places.

Please, see the attached patch that includes your proposal.

--
Best regards,
Daniil Davydov

Attachment Content-Type Size
v2-0001-Fix-comment-in-BufferDesc-struct.patch text/x-patch 1.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Antonin Houska 2026-01-20 08:30:33 Re: Race conditions in logical decoding
Previous Message Chao Li 2026-01-20 08:16:26 Re: Fix accidentally cast away qualifiers