Re: Add macros for ReorderBufferTXN toptxn

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add macros for ReorderBufferTXN toptxn
Date: 2023-03-10 11:30:53
Message-ID: CAA4eK1+cX1Od4HPV-W0OeyJXWN_EQ03d=OyPDFBjPFa3b+6xSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 10, 2023 at 4:36 AM Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
>
> During a recent code review, I was confused multiple times by the
> toptxn member of ReorderBufferTXN, which is defined only for
> sub-transactions.
>
> e.g. txn->toptxn member == NULL means the txn is a top level txn.
> e.g. txn->toptxn member != NULL means the txn is not a top level txn
>
> It makes sense if you squint and read it slowly enough, but IMO it's
> too easy to accidentally misinterpret the meaning when reading code
> that uses this member.
>
> ~
>
> Such code can be made easier to read just by introducing some simple macros:
>
> #define isa_toptxn(rbtxn) (rbtxn->toptxn == NULL)
> #define isa_subtxn(rbtxn) (rbtxn->toptxn != NULL)
> #define get_toptxn(rbtxn) (isa_subtxn(rbtxn) ? rbtxn->toptxn : rbtxn)
>
> ~
>
> PSA a small patch that does this.
>

I also find it will make code easier to read. So, +1 to the idea. I'll
do the detailed review and test next week unless there are objections
to the idea.

--
With Regards,
Amit Kapila.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Drouvot, Bertrand 2023-03-10 11:33:50 Re: Minimal logical decoding on standbys
Previous Message Peter Eisentraut 2023-03-10 11:18:09 Re: How to get the real type use oid in internal codes?