agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
From: Antonin Houska <ah@cybertec.at>
To: alvherre@kurilemu.de
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Race conditions in logical decoding
Date: Fri, 23 Jan 2026 07:33:32 +0100
Message-ID: <3805.1769150012@localhost> (raw)
In-Reply-To: <202601221950.c5lwdnye3idv@alvherre.pgsql>
References: <202601221950.c5lwdnye3idv@alvherre.pgsql>

Álvaro Herrera <alvherre@kurilemu.de> wrote:

> I think this algorithm is strange -- if you do have to wait more than
> once for one transaction, it would lead to doing the
> TransactionIdDidCommit again times for _all_ transactions by starting
> the inner loop from scratch, which sounds really wasteful.  Why not nest
> the for() loops the other way around?

I'm quite sure I wanted to iterate through committed.xnt in the outer loop,
but probably got distracted by something else and messed things up.

> Something like this perhaps,
> 
>     for (int i = 0; i < builder->committed.xcnt; i++)
>     {
>         for (;;)
>         {
>             if (TransactionIdDidCommit(builder->committed.xip[i]))
>                 break;
>             else
>             {
>                 (void) WaitLatch(MyLatch,
>                                  WL_LATCH_SET, WL_TIMEOUT, WL_EXIT_ON_PM_DEATH,
>                                  10L,
>                                  WAIT_EVENT_SNAPBUILD_CLOG);
>                 ResetLatch(MyLatch);
>             }
>             CHECK_FOR_INTERRUPTS();
>         }
>     }
> 
> This way you wait repeatedly for one transaction until it is marked
> committed; and once it does, you don't test it again.

Sure, that's much beter. Thanks.

-- 
Antonin Houska
Web: https://www.cybertec-postgresql.com





view thread (38+ messages)  latest in thread

Message-ID: <3805.1769150012@localhost>
Permalink:  ../3805.1769150012@localhost/
Also on:    postgresql.org/message-id/3805.1769150012@localhost

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: ah@cybertec.at, alvherre@kurilemu.de, pgsql-hackers@lists.postgresql.org
  Subject: Re: Race conditions in logical decoding
  In-Reply-To: <3805.1769150012@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox