@@ -99,8 +99,6 @@ ReplicationSlot *MyReplicationSlot = NULL;
9999int max_replication_slots = 0 ; /* the maximum number of replication
100100 * slots */
101101
102- static int ReplicationSlotAcquireInternal (ReplicationSlot * slot ,
103- const char * name , SlotAcquireBehavior behavior );
104102static void ReplicationSlotDropAcquired (void );
105103static void ReplicationSlotDropPtr (ReplicationSlot * slot );
106104
@@ -374,34 +372,16 @@ SearchNamedReplicationSlot(const char *name, bool need_lock)
374372/*
375373 * Find a previously created slot and mark it as used by this process.
376374 *
377- * The return value is only useful if behavior is SAB_Inquire, in which
378- * it's zero if we successfully acquired the slot, -1 if the slot no longer
379- * exists, or the PID of the owning process otherwise. If behavior is
380- * SAB_Error, then trying to acquire an owned slot is an error.
381- * If SAB_Block, we sleep until the slot is released by the owning process.
375+ * An error is raised if nowait is true and the slot is currently in use. If
376+ * nowait is false, we sleep until the slot is released by the owning process.
382377 */
383- int
384- ReplicationSlotAcquire (const char * name , SlotAcquireBehavior behavior )
385- {
386- return ReplicationSlotAcquireInternal (NULL , name , behavior );
387- }
388-
389- /*
390- * Mark the specified slot as used by this process.
391- *
392- * Only one of slot and name can be specified.
393- * If slot == NULL, search for the slot with the given name.
394- *
395- * See comments about the return value in ReplicationSlotAcquire().
396- */
397- static int
398- ReplicationSlotAcquireInternal (ReplicationSlot * slot , const char * name ,
399- SlotAcquireBehavior behavior )
378+ void
379+ ReplicationSlotAcquire (const char * name , bool nowait )
400380{
401381 ReplicationSlot * s ;
402382 int active_pid ;
403383
404- AssertArg (( slot == NULL ) ^ ( name == NULL ) );
384+ AssertArg (name != NULL );
405385
406386retry :
407387 Assert (MyReplicationSlot == NULL );
@@ -412,17 +392,15 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name,
412392 * Search for the slot with the specified name if the slot to acquire is
413393 * not given. If the slot is not found, we either return -1 or error out.
414394 */
415- s = slot ? slot : SearchNamedReplicationSlot (name , false);
395+ s = SearchNamedReplicationSlot (name , false);
416396 if (s == NULL || !s -> in_use )
417397 {
418398 LWLockRelease (ReplicationSlotControlLock );
419399
420- if (behavior == SAB_Inquire )
421- return -1 ;
422400 ereport (ERROR ,
423401 (errcode (ERRCODE_UNDEFINED_OBJECT ),
424402 errmsg ("replication slot \"%s\" does not exist" ,
425- name ? name : NameStr ( slot -> data . name ) )));
403+ name )));
426404 }
427405
428406 /*
@@ -436,7 +414,7 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name,
436414 * (We may end up not sleeping, but we don't want to do this while
437415 * holding the spinlock.)
438416 */
439- if (behavior == SAB_Block )
417+ if (! nowait )
440418 ConditionVariablePrepareToSleep (& s -> active_cv );
441419
442420 SpinLockAcquire (& s -> mutex );
@@ -456,31 +434,26 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name,
456434 */
457435 if (active_pid != MyProcPid )
458436 {
459- if (behavior == SAB_Error )
437+ if (! nowait )
460438 ereport (ERROR ,
461439 (errcode (ERRCODE_OBJECT_IN_USE ),
462440 errmsg ("replication slot \"%s\" is active for PID %d" ,
463441 NameStr (s -> data .name ), active_pid )));
464- else if (behavior == SAB_Inquire )
465- return active_pid ;
466442
467443 /* Wait here until we get signaled, and then restart */
468444 ConditionVariableSleep (& s -> active_cv ,
469445 WAIT_EVENT_REPLICATION_SLOT_DROP );
470446 ConditionVariableCancelSleep ();
471447 goto retry ;
472448 }
473- else if (behavior == SAB_Block )
449+ else if (! nowait )
474450 ConditionVariableCancelSleep (); /* no sleep needed after all */
475451
476452 /* Let everybody know we've modified this slot */
477453 ConditionVariableBroadcast (& s -> active_cv );
478454
479455 /* We made this slot active, so it's ours now. */
480456 MyReplicationSlot = s ;
481-
482- /* success */
483- return 0 ;
484457}
485458
486459/*
@@ -588,7 +561,7 @@ ReplicationSlotDrop(const char *name, bool nowait)
588561{
589562 Assert (MyReplicationSlot == NULL );
590563
591- ( void ) ReplicationSlotAcquire (name , nowait ? SAB_Error : SAB_Block );
564+ ReplicationSlotAcquire (name , nowait );
592565
593566 ReplicationSlotDropAcquired ();
594567}
@@ -1271,8 +1244,8 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlot *s, XLogRecPtr oldestLSN)
12711244 WAIT_EVENT_REPLICATION_SLOT_DROP );
12721245
12731246 /*
1274- * Re-acquire lock and start over; we expect to invalidate the slot
1275- * next time (unless another process acquires the slot in the
1247+ * Re-acquire lock and start over; we expect to invalidate the
1248+ * slot next time (unless another process acquires the slot in the
12761249 * meantime).
12771250 */
12781251 LWLockAcquire (ReplicationSlotControlLock , LW_SHARED );
0 commit comments