diff options
| author | Alvaro Herrera | 2020-03-02 21:19:51 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2020-03-02 21:19:51 +0000 |
| commit | 2f9661311b83dc481fc19f6e3bda015392010a40 (patch) | |
| tree | 9a1aabe1d15ac894f7badbc886ae33f16bbfc3b6 /src/backend/replication | |
| parent | 7b425a5283cb2c8a452c2e79d6218e41373fd641 (diff) | |
Represent command completion tags as structs
The backend was using strings to represent command tags and doing string
comparisons in multiple places, but that's slow and unhelpful. Create a
new command list with a supporting structure to use instead; this is
stored in a tag-list-file that can be tailored to specific purposes with
a caller-definable C macro, similar to what we do for WAL resource
managers. The first first such uses are a new CommandTag enum and a
CommandTagBehavior struct.
Replace numerous occurrences of char *completionTag with a
QueryCompletion struct so that the code no longer stores information
about completed queries in a cstring. Only at the last moment, in
EndCommand(), does this get converted to a string.
EventTriggerCacheItem no longer holds an array of palloc’d tag strings
in sorted order, but rather just a Bitmapset over the CommandTags.
Author: Mark Dilger, with unsolicited help from Álvaro Herrera
Reviewed-by: John Naylor, Tom Lane
Discussion: https://postgr.es/m/981A9DB4-3F0C-4DA5-88AD-CB9CFF4D6CAD@enterprisedb.com
Diffstat (limited to 'src/backend/replication')
| -rw-r--r-- | src/backend/replication/logical/decode.c | 2 | ||||
| -rw-r--r-- | src/backend/replication/walsender.c | 18 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c index 0ddc707def..c2e5e3abf8 100644 --- a/src/backend/replication/logical/decode.c +++ b/src/backend/replication/logical/decode.c @@ -100,7 +100,7 @@ LogicalDecodingProcessRecord(LogicalDecodingContext *ctx, XLogReaderState *recor buf.record = record; /* cast so we get a warning when new rmgrs are added */ - switch ((RmgrIds) XLogRecGetRmid(record)) + switch ((RmgrId) XLogRecGetRmid(record)) { /* * Rmgrs we care about for logical decoding. Add new rmgrs in diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index abb533b9d0..ae4a9cbe11 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1074,8 +1074,11 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) static void DropReplicationSlot(DropReplicationSlotCmd *cmd) { + QueryCompletion qc; + ReplicationSlotDrop(cmd->slotname, !cmd->wait); - EndCommand("DROP_REPLICATION_SLOT", DestRemote); + SetQueryCompletion(&qc, CMDTAG_DROP_REPLICATION_SLOT, 0); + EndCommand(&qc, DestRemote, false); } /* @@ -1086,6 +1089,7 @@ static void StartLogicalReplication(StartReplicationCmd *cmd) { StringInfoData buf; + QueryCompletion qc; /* make sure that our requirements are still fulfilled */ CheckLogicalDecodingRequirements(); @@ -1160,7 +1164,8 @@ StartLogicalReplication(StartReplicationCmd *cmd) WalSndSetState(WALSNDSTATE_STARTUP); /* Get out of COPY mode (CommandComplete). */ - EndCommand("COPY 0", DestRemote); + SetQueryCompletion(&qc, CMDTAG_COPY, 0); + EndCommand(&qc, DestRemote, false); } /* @@ -1464,6 +1469,7 @@ exec_replication_command(const char *cmd_string) Node *cmd_node; MemoryContext cmd_context; MemoryContext old_context; + QueryCompletion qc; /* * If WAL sender has been told that shutdown is getting close, switch its @@ -1614,7 +1620,8 @@ exec_replication_command(const char *cmd_string) MemoryContextDelete(cmd_context); /* Send CommandComplete message */ - EndCommand("SELECT", DestRemote); + SetQueryCompletion(&qc, CMDTAG_SELECT, 0); + EndCommand(&qc, DestRemote, true); /* Report to pgstat that this process is now idle */ pgstat_report_activity(STATE_IDLE, NULL); @@ -2867,8 +2874,11 @@ WalSndDone(WalSndSendDataCallback send_data) if (WalSndCaughtUp && sentPtr == replicatedPtr && !pq_is_send_pending()) { + QueryCompletion qc; + /* Inform the standby that XLOG streaming is done */ - EndCommand("COPY 0", DestRemote); + SetQueryCompletion(&qc, CMDTAG_COPY, 0); + EndCommand(&qc, DestRemote, false); pq_flush(); proc_exit(0); |
