Re: Assertion failure in SnapBuildInitialSnapshot()

Amit Kapila <amit.kapila16@gmail.com>

From: Amit Kapila <amit.kapila16@gmail.com>
To: "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>
Cc: Pradeep Kumar <spradeepkumar29@gmail.com>, Masahiko Sawada <sawada.mshk@gmail.com>, Alexander Lakhin <exclusion@gmail.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>, vignesh C <vignesh21@gmail.com>, Andres Freund <andres@anarazel.de>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>, Thomas Munro <thomas.munro@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-11-24T09:46:04Z
Lists: pgsql-hackers
On Fri, Nov 21, 2025 at 9:17 AM Zhijie Hou (Fujitsu)
<houzj.fnst@fujitsu.com> wrote:
>
> On Thursday, November 13, 2025 12:56 PM Zhijie Hou (Fujitsu) <houzj.fnst@fujitsu.com> wrote:
> >
>
> I have been thinking if there a way to avoid holding ReplicationSlotControlLock
> exclusively in ReplicationSlotsComputeRequiredXmin() because that could cause
> lock contention when many slots exist and advancements occur frequently.
>
> Given that the bug arises from a race condition between slot creation and
> concurrent slot xmin computation, I think another way is that, we acquire the
> ReplicationSlotControlLock exclusively only during slot creation to do the
> initial update of the slot xmin. In ReplicationSlotsComputeRequiredXmin(), we
> still hold the ReplicationSlotControlLock in shared mode until the global slot
> xmin is updated in ProcArraySetReplicationSlotXmin(). This approach prevents
> concurrent computations and updates of new xmin horizons by other backends
> during the initial slot xmin update process, while it still permits concurrent
> calls to ReplicationSlotsComputeRequiredXmin().
>

Yeah, this seems to work.

> Here is an update patch for this approach on HEAD.
>

Thanks for the patch.

Sawada-San, are you planning to look into this? Otherwise, I can take
care of it.

-- 
With Regards,
Amit Kapila.



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix a race condition in updating procArray->replication_slot_xmin.

  2. Don't retreat slot's confirmed_flush LSN.

  3. Add additional checks while creating the initial decoding snapshot.