pgsql: Fix race condition in invalidating obsolete replication slots

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix race condition in invalidating obsolete replication slots
Date: 2021-06-11 16:21:15
Message-ID: E1lrjuF-00065F-CZ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix race condition in invalidating obsolete replication slots

The code added to mark replication slots invalid in commit c6550776394e
had the race condition that a slot can be dropped or advanced
concurrently with checkpointer trying to invalidate it. Rewrite the
code to close those races.

The changes to ReplicationSlotAcquire's API added with c6550776394e are
not necessary anymore. To avoid an ABI break in released branches, this
commit leaves that unchanged; it'll be changed in a master-only commit
separately.

Backpatch to 13, where this code first appeared.

Reported-by: Andres Freund <andres(at)anarazel(dot)de>
Author: Andres Freund <andres(at)anarazel(dot)de>
Author: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Discussion: https://postgr.es/m/20210408001037.wfmk6jud36auhfqm@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/96540f80f8334a3f0f4a13f0d42e4565d8fa9eb7

Modified Files
--------------
src/backend/replication/slot.c | 221 +++++++++++++++++++++++++++--------------
1 file changed, 144 insertions(+), 77 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2021-06-11 18:24:11 pgsql: Optimize creation of slots for FDW bulk inserts
Previous Message Michael Paquier 2021-06-11 06:56:34 pgsql: Improve psql tab completion for options of subcriptions and publ