mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
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
This commit is contained in:
@ -228,7 +228,7 @@ CreateInitDecodingContext(char *plugin,
|
|||||||
elog(ERROR, "cannot initialize logical decoding without a specified plugin");
|
elog(ERROR, "cannot initialize logical decoding without a specified plugin");
|
||||||
|
|
||||||
/* Make sure the passed slot is suitable. These are user facing errors. */
|
/* Make sure the passed slot is suitable. These are user facing errors. */
|
||||||
if (slot->data.database == InvalidOid)
|
if (SlotIsPhysical(slot))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||||
errmsg("cannot use physical replication slot for logical decoding")));
|
errmsg("cannot use physical replication slot for logical decoding")));
|
||||||
@ -377,7 +377,7 @@ CreateDecodingContext(XLogRecPtr start_lsn,
|
|||||||
elog(ERROR, "cannot perform logical decoding without an acquired slot");
|
elog(ERROR, "cannot perform logical decoding without an acquired slot");
|
||||||
|
|
||||||
/* make sure the passed slot is suitable, these are user facing errors */
|
/* make sure the passed slot is suitable, these are user facing errors */
|
||||||
if (slot->data.database == InvalidOid)
|
if (SlotIsPhysical(slot))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||||
(errmsg("cannot use physical replication slot for logical decoding"))));
|
(errmsg("cannot use physical replication slot for logical decoding"))));
|
||||||
|
@ -693,7 +693,7 @@ ReplicationSlotsComputeLogicalRestartLSN(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* we're only interested in logical slots */
|
/* we're only interested in logical slots */
|
||||||
if (s->data.database == InvalidOid)
|
if (!SlotIsLogical(s))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* read once, it's ok if it increases while we're checking */
|
/* read once, it's ok if it increases while we're checking */
|
||||||
@ -740,8 +740,8 @@ ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive)
|
|||||||
if (!s->in_use)
|
if (!s->in_use)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* not database specific, skip */
|
/* only logical slots are database specific, skip */
|
||||||
if (s->data.database == InvalidOid)
|
if (!SlotIsLogical(s))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* not our database, skip */
|
/* not our database, skip */
|
||||||
|
@ -514,7 +514,7 @@ StartReplication(StartReplicationCmd *cmd)
|
|||||||
if (cmd->slotname)
|
if (cmd->slotname)
|
||||||
{
|
{
|
||||||
ReplicationSlotAcquire(cmd->slotname);
|
ReplicationSlotAcquire(cmd->slotname);
|
||||||
if (MyReplicationSlot->data.database != InvalidOid)
|
if (SlotIsLogical(MyReplicationSlot))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||||
(errmsg("cannot use a logical replication slot for physical replication"))));
|
(errmsg("cannot use a logical replication slot for physical replication"))));
|
||||||
@ -1564,7 +1564,7 @@ ProcessStandbyReplyMessage(void)
|
|||||||
*/
|
*/
|
||||||
if (MyReplicationSlot && flushPtr != InvalidXLogRecPtr)
|
if (MyReplicationSlot && flushPtr != InvalidXLogRecPtr)
|
||||||
{
|
{
|
||||||
if (MyReplicationSlot->data.database != InvalidOid)
|
if (SlotIsLogical(MyReplicationSlot))
|
||||||
LogicalConfirmReceivedLocation(flushPtr);
|
LogicalConfirmReceivedLocation(flushPtr);
|
||||||
else
|
else
|
||||||
PhysicalConfirmReceivedLocation(flushPtr);
|
PhysicalConfirmReceivedLocation(flushPtr);
|
||||||
|
@ -125,6 +125,9 @@ typedef struct ReplicationSlot
|
|||||||
XLogRecPtr candidate_restart_lsn;
|
XLogRecPtr candidate_restart_lsn;
|
||||||
} ReplicationSlot;
|
} ReplicationSlot;
|
||||||
|
|
||||||
|
#define SlotIsPhysical(slot) (slot->data.database == InvalidOid)
|
||||||
|
#define SlotIsLogical(slot) (slot->data.database != InvalidOid)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shared memory control area for all of replication slots.
|
* Shared memory control area for all of replication slots.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user