Skip to content

Commit 093d0c8

Browse files
committed
Introduce macros determining if a replication slot is physical or logical.
These make the code a bit easier to read, and make it easier to add a more explicit notion of a slot's type at some point in the future. Author: Gurjeet Singh Discussion: CABwTF4Wh_dBCzTU=49pFXR6coR4NW1ynb+vBqT+Po=7fuq5iCw@mail.gmail.com
1 parent 3b425b7 commit 093d0c8

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/backend/replication/logical/logical.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ CreateInitDecodingContext(char *plugin,
228228
elog(ERROR, "cannot initialize logical decoding without a specified plugin");
229229

230230
/* Make sure the passed slot is suitable. These are user facing errors. */
231-
if (slot->data.database == InvalidOid)
231+
if (SlotIsPhysical(slot))
232232
ereport(ERROR,
233233
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
234234
errmsg("cannot use physical replication slot for logical decoding")));
@@ -377,7 +377,7 @@ CreateDecodingContext(XLogRecPtr start_lsn,
377377
elog(ERROR, "cannot perform logical decoding without an acquired slot");
378378

379379
/* make sure the passed slot is suitable, these are user facing errors */
380-
if (slot->data.database == InvalidOid)
380+
if (SlotIsPhysical(slot))
381381
ereport(ERROR,
382382
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
383383
(errmsg("cannot use physical replication slot for logical decoding"))));

src/backend/replication/slot.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ ReplicationSlotsComputeLogicalRestartLSN(void)
693693
continue;
694694

695695
/* we're only interested in logical slots */
696-
if (s->data.database == InvalidOid)
696+
if (!SlotIsLogical(s))
697697
continue;
698698

699699
/* read once, it's ok if it increases while we're checking */
@@ -740,8 +740,8 @@ ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive)
740740
if (!s->in_use)
741741
continue;
742742

743-
/* not database specific, skip */
744-
if (s->data.database == InvalidOid)
743+
/* only logical slots are database specific, skip */
744+
if (!SlotIsLogical(s))
745745
continue;
746746

747747
/* not our database, skip */

src/backend/replication/walsender.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ StartReplication(StartReplicationCmd *cmd)
514514
if (cmd->slotname)
515515
{
516516
ReplicationSlotAcquire(cmd->slotname);
517-
if (MyReplicationSlot->data.database != InvalidOid)
517+
if (SlotIsLogical(MyReplicationSlot))
518518
ereport(ERROR,
519519
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
520520
(errmsg("cannot use a logical replication slot for physical replication"))));
@@ -1564,7 +1564,7 @@ ProcessStandbyReplyMessage(void)
15641564
*/
15651565
if (MyReplicationSlot && flushPtr != InvalidXLogRecPtr)
15661566
{
1567-
if (MyReplicationSlot->data.database != InvalidOid)
1567+
if (SlotIsLogical(MyReplicationSlot))
15681568
LogicalConfirmReceivedLocation(flushPtr);
15691569
else
15701570
PhysicalConfirmReceivedLocation(flushPtr);

src/include/replication/slot.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ typedef struct ReplicationSlot
125125
XLogRecPtr candidate_restart_lsn;
126126
} ReplicationSlot;
127127

128+
#define SlotIsPhysical(slot) (slot->data.database == InvalidOid)
129+
#define SlotIsLogical(slot) (slot->data.database != InvalidOid)
130+
128131
/*
129132
* Shared memory control area for all of replication slots.
130133
*/

0 commit comments

Comments
 (0)