Re: Fix race condition in SSI when reading PredXact->SxactGlobalXmin

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
To: Josh Curtis <jcurtis825(at)gmail(dot)com>
Cc: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Fix race condition in SSI when reading PredXact->SxactGlobalXmin
Date: 2026-08-26 18:28:51
Message-ID: 8950FE6F-F07A-43AF-B8F7-F6556EEB904A@yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 12 Jun 2026, at 06:04, Josh Curtis <jcurtis825(at)gmail(dot)com> wrote:
>
> <v4-0001-Fix-race-condition-when-reading-PredXact-SxactGlo.patch>

Hi Josh,

I suspect a race in the test:

+step s2_insert_wait_at_page_split: <... completed>
+step s1_commit_wait_in_SetNewSxactGlobalXmin: <... completed>

Adding an explicit dependency can make the output stable:

s2_insert_wait_at_page_split(s1_commit_wait_in_SetNewSxactGlobalXmin)

I don't think we should acquire SerializableXactHashLock in shared mode
on every page split to fix this. The race exists because
SetNewSxactGlobalXmin() uses the shared fields as local variables and
publishes a transient InvalidTransactionId while recalculating them.

Could it instead calculate the new xmin and count in local variables,
then publish them after scanning the active list? Readers that use both
fields already hold SerializableXactHashLock. Lockless readers inspect
only SxactGlobalXmin and may safely see the previous valid value. That
can only cause unnecessary predicate-lock work. Publishing
SxactGlobalXmin last would preserve that property and the existing fast
path when no serializable transactions are running.

That seems both simpler and better for the page-split path. I think the
patch should fix the publication side instead of adding the three reader
locks. WDYT?

Thank you!

Best regards, Andrey Borodin.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2026-08-26 18:43:34 Re: Allow aggressive VACUUM to freeze without a cleanup lock
Previous Message Peter Eisentraut 2026-08-26 18:28:15 Re: Add a Nix flake