@@ -99,8 +99,6 @@ ReplicationSlot *MyReplicationSlot = NULL;
99
99
int max_replication_slots = 0 ; /* the maximum number of replication
100
100
* slots */
101
101
102
- static int ReplicationSlotAcquireInternal (ReplicationSlot * slot ,
103
- const char * name , SlotAcquireBehavior behavior );
104
102
static void ReplicationSlotDropAcquired (void );
105
103
static void ReplicationSlotDropPtr (ReplicationSlot * slot );
106
104
@@ -374,34 +372,16 @@ SearchNamedReplicationSlot(const char *name, bool need_lock)
374
372
/*
375
373
* Find a previously created slot and mark it as used by this process.
376
374
*
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.
382
377
*/
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 )
400
380
{
401
381
ReplicationSlot * s ;
402
382
int active_pid ;
403
383
404
- AssertArg (( slot == NULL ) ^ ( name == NULL ) );
384
+ AssertArg (name != NULL );
405
385
406
386
retry :
407
387
Assert (MyReplicationSlot == NULL );
@@ -412,17 +392,15 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name,
412
392
* Search for the slot with the specified name if the slot to acquire is
413
393
* not given. If the slot is not found, we either return -1 or error out.
414
394
*/
415
- s = slot ? slot : SearchNamedReplicationSlot (name , false);
395
+ s = SearchNamedReplicationSlot (name , false);
416
396
if (s == NULL || !s -> in_use )
417
397
{
418
398
LWLockRelease (ReplicationSlotControlLock );
419
399
420
- if (behavior == SAB_Inquire )
421
- return -1 ;
422
400
ereport (ERROR ,
423
401
(errcode (ERRCODE_UNDEFINED_OBJECT ),
424
402
errmsg ("replication slot \"%s\" does not exist" ,
425
- name ? name : NameStr ( slot -> data . name ) )));
403
+ name )));
426
404
}
427
405
428
406
/*
@@ -436,7 +414,7 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name,
436
414
* (We may end up not sleeping, but we don't want to do this while
437
415
* holding the spinlock.)
438
416
*/
439
- if (behavior == SAB_Block )
417
+ if (! nowait )
440
418
ConditionVariablePrepareToSleep (& s -> active_cv );
441
419
442
420
SpinLockAcquire (& s -> mutex );
@@ -456,31 +434,26 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name,
456
434
*/
457
435
if (active_pid != MyProcPid )
458
436
{
459
- if (behavior == SAB_Error )
437
+ if (! nowait )
460
438
ereport (ERROR ,
461
439
(errcode (ERRCODE_OBJECT_IN_USE ),
462
440
errmsg ("replication slot \"%s\" is active for PID %d" ,
463
441
NameStr (s -> data .name ), active_pid )));
464
- else if (behavior == SAB_Inquire )
465
- return active_pid ;
466
442
467
443
/* Wait here until we get signaled, and then restart */
468
444
ConditionVariableSleep (& s -> active_cv ,
469
445
WAIT_EVENT_REPLICATION_SLOT_DROP );
470
446
ConditionVariableCancelSleep ();
471
447
goto retry ;
472
448
}
473
- else if (behavior == SAB_Block )
449
+ else if (! nowait )
474
450
ConditionVariableCancelSleep (); /* no sleep needed after all */
475
451
476
452
/* Let everybody know we've modified this slot */
477
453
ConditionVariableBroadcast (& s -> active_cv );
478
454
479
455
/* We made this slot active, so it's ours now. */
480
456
MyReplicationSlot = s ;
481
-
482
- /* success */
483
- return 0 ;
484
457
}
485
458
486
459
/*
@@ -588,7 +561,7 @@ ReplicationSlotDrop(const char *name, bool nowait)
588
561
{
589
562
Assert (MyReplicationSlot == NULL );
590
563
591
- ( void ) ReplicationSlotAcquire (name , nowait ? SAB_Error : SAB_Block );
564
+ ReplicationSlotAcquire (name , nowait );
592
565
593
566
ReplicationSlotDropAcquired ();
594
567
}
@@ -1271,8 +1244,8 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlot *s, XLogRecPtr oldestLSN)
1271
1244
WAIT_EVENT_REPLICATION_SLOT_DROP );
1272
1245
1273
1246
/*
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
1276
1249
* meantime).
1277
1250
*/
1278
1251
LWLockAcquire (ReplicationSlotControlLock , LW_SHARED );
0 commit comments