From 008ec88995b2ae1d851033222bfbd8dfebd7a368 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 8 May 2018 11:49:08 -0300 Subject: [PATCH 2/2] simplify baroque coding --- src/backend/replication/slot.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index a43f402214..664bf2e3ad 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -99,7 +99,6 @@ ReplicationSlot *MyReplicationSlot = NULL; int max_replication_slots = 0; /* the maximum number of replication * slots */ -static void ReplicationSlotDropAcquired(void); static void ReplicationSlotDropPtr(ReplicationSlot *slot); /* internal persistency functions */ @@ -434,7 +433,8 @@ ReplicationSlotRelease(void) * fail, all that may happen is an incomplete cleanup of the on-disk * data. */ - ReplicationSlotDropAcquired(); + ReplicationSlotDropPtr(MyReplicationSlot); + MyReplicationSlot = NULL; } /* @@ -520,23 +520,10 @@ ReplicationSlotDrop(const char *name, bool nowait) ReplicationSlotAcquire(name, nowait); - ReplicationSlotDropAcquired(); -} + ReplicationSlotDropPtr(MyReplicationSlot); -/* - * Permanently drop the currently acquired replication slot. - */ -static void -ReplicationSlotDropAcquired(void) -{ - ReplicationSlot *slot = MyReplicationSlot; - - Assert(MyReplicationSlot != NULL); - - /* slot isn't acquired anymore */ + /* no longer my slot */ MyReplicationSlot = NULL; - - ReplicationSlotDropPtr(slot); } /* @@ -923,7 +910,7 @@ restart: if (s->data.database != dboid) continue; - /* acquire slot, so ReplicationSlotDropAcquired can be reused */ + /* acquire slot */ SpinLockAcquire(&s->mutex); /* can't change while ReplicationSlotControlLock is held */ slotname = NameStr(s->data.name); @@ -949,16 +936,17 @@ restart: slotname, active_pid))); /* - * To avoid duplicating ReplicationSlotDropAcquired() and to avoid - * holding ReplicationSlotControlLock over filesystem operations, - * release ReplicationSlotControlLock and use - * ReplicationSlotDropAcquired. + * To avoid holding ReplicationSlotControlLock over filesystem + * operations, release ReplicationSlotControlLock while we drop + * the slot. * * As that means the set of slots could change, restart scan from the * beginning each time we release the lock. */ LWLockRelease(ReplicationSlotControlLock); - ReplicationSlotDropAcquired(); + ReplicationSlotDropPtr(MyReplicationSlot); + /* no longer my slot */ + MyReplicationSlot = NULL; goto restart; } LWLockRelease(ReplicationSlotControlLock); -- 2.11.0