From 936e6b7ec334b57d3b1482729fee3189afdfddad Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Thu, 24 Jul 2025 14:38:03 -0400 Subject: [PATCH] replace protocol replication constants with named constants from protocol.h --- src/backend/replication/logical/worker.c | 10 +++++----- src/backend/replication/walreceiver.c | 4 ++-- src/backend/replication/walsender.c | 18 +++++++++--------- src/include/libpq/protocol.h | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index b59221c4d06..46d69da88d5 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -3851,7 +3851,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) c = pq_getmsgbyte(&s); - if (c == 'w') + if (c == PqMsg_XlogData) { XLogRecPtr start_lsn; XLogRecPtr end_lsn; @@ -3873,7 +3873,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) maybe_advance_nonremovable_xid(&rdt_data, false); } - else if (c == 'k') + else if (c == PqMsg_PrimaryKeepAlive) { XLogRecPtr end_lsn; TimestampTz timestamp; @@ -3892,7 +3892,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) UpdateWorkerStats(last_received, timestamp, true); } - else if (c == 's') /* Primary status update */ + else if (c == PqMsg_PrimaryStatusUpdate) /* Primary status update */ { rdt_data.remote_lsn = pq_getmsgint64(&s); rdt_data.remote_oldestxid = FullTransactionIdFromU64((uint64) pq_getmsgint64(&s)); @@ -4124,7 +4124,7 @@ send_feedback(XLogRecPtr recvpos, bool force, bool requestReply) else resetStringInfo(reply_message); - pq_sendbyte(reply_message, 'r'); + pq_sendbyte(reply_message, PqMsg_StandbyStatus); pq_sendint64(reply_message, recvpos); /* write */ pq_sendint64(reply_message, flushpos); /* flush */ pq_sendint64(reply_message, writepos); /* apply */ @@ -4295,7 +4295,7 @@ request_publisher_status(RetainDeadTuplesData *rdt_data) * Send the current time to update the remote walsender's latest reply * message received time. */ - pq_sendbyte(request_message, 'p'); + pq_sendbyte(request_message, PqMsg_RequestPrimaryStatus); pq_sendint64(request_message, GetCurrentTimestamp()); elog(DEBUG2, "sending publisher status request message"); diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index b6281101711..a138e9c3556 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1130,7 +1130,7 @@ XLogWalRcvSendReply(bool force, bool requestReply) applyPtr = GetXLogReplayRecPtr(NULL); resetStringInfo(&reply_message); - pq_sendbyte(&reply_message, 'r'); + pq_sendbyte(&reply_message, PqMsg_StandbyStatus); pq_sendint64(&reply_message, writePtr); pq_sendint64(&reply_message, flushPtr); pq_sendint64(&reply_message, applyPtr); @@ -1234,7 +1234,7 @@ XLogWalRcvSendHSFeedback(bool immed) /* Construct the message and send it. */ resetStringInfo(&reply_message); - pq_sendbyte(&reply_message, 'h'); + pq_sendbyte(&reply_message, PqMsg_HotStandbyFeedback); pq_sendint64(&reply_message, GetCurrentTimestamp()); pq_sendint32(&reply_message, xmin); pq_sendint32(&reply_message, xmin_epoch); diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index ee911394a23..e00bc74e68f 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1534,7 +1534,7 @@ WalSndPrepareWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi resetStringInfo(ctx->out); - pq_sendbyte(ctx->out, 'w'); + pq_sendbyte(ctx->out, PqMsg_XlogData); pq_sendint64(ctx->out, lsn); /* dataStart */ pq_sendint64(ctx->out, lsn); /* walEnd */ @@ -2292,7 +2292,7 @@ ProcessRepliesIfAny(void) switch (firstchar) { /* - * 'd' means a standby reply wrapped in a CopyData packet. + * standby reply wrapped in a CopyData packet. */ case PqMsg_CopyData: ProcessStandbyMessage(); @@ -2315,7 +2315,7 @@ ProcessRepliesIfAny(void) break; /* - * 'X' means that the standby is closing down the socket. + * the standby is closing down the socket. */ case PqMsg_Terminate: proc_exit(0); @@ -2350,15 +2350,15 @@ ProcessStandbyMessage(void) switch (msgtype) { - case 'r': + case PqMsg_StandbyStatus: ProcessStandbyReplyMessage(); break; - case 'h': + case PqMsg_HotStandbyFeedback: ProcessStandbyHSFeedbackMessage(); break; - case 'p': + case PqMsg_RequestPrimaryStatus: ProcessStandbyPSRequestMessage(); break; @@ -2752,7 +2752,7 @@ ProcessStandbyPSRequestMessage(void) /* construct the message... */ resetStringInfo(&output_message); - pq_sendbyte(&output_message, 's'); + pq_sendbyte(&output_message, PqMsg_PrimaryStatusUpdate); pq_sendint64(&output_message, lsn); pq_sendint64(&output_message, (int64) U64FromFullTransactionId(fullOldestXidInCommit)); pq_sendint64(&output_message, (int64) U64FromFullTransactionId(nextFullXid)); @@ -3364,7 +3364,7 @@ XLogSendPhysical(void) * OK to read and send the slice. */ resetStringInfo(&output_message); - pq_sendbyte(&output_message, 'w'); + pq_sendbyte(&output_message, PqMsg_XlogData); pq_sendint64(&output_message, startptr); /* dataStart */ pq_sendint64(&output_message, SendRqstPtr); /* walEnd */ @@ -4135,7 +4135,7 @@ WalSndKeepalive(bool requestReply, XLogRecPtr writePtr) /* construct the message... */ resetStringInfo(&output_message); - pq_sendbyte(&output_message, 'k'); + pq_sendbyte(&output_message, PqMsg_PrimaryKeepAlive); pq_sendint64(&output_message, XLogRecPtrIsInvalid(writePtr) ? sentPtr : writePtr); pq_sendint64(&output_message, GetCurrentTimestamp()); pq_sendbyte(&output_message, requestReply ? 1 : 0); diff --git a/src/include/libpq/protocol.h b/src/include/libpq/protocol.h index b0bcb3cdc26..06653a7c2c6 100644 --- a/src/include/libpq/protocol.h +++ b/src/include/libpq/protocol.h @@ -68,6 +68,24 @@ /* These are the codes sent by parallel workers to leader processes. */ #define PqMsg_Progress 'P' +/* Replication Protocol sent by the primary */ + +#define PqMsg_XlogData 'w' +#define PqMsg_PrimaryKeepAlive 'k' +#define PqMsg_PrimaryStatusUpdate 's' + + +/* Replication Protocol sent by the standby */ + +#define PqMsg_StandbyStatus 'r' +#define PqMsg_HotStandbyFeedback 'h' +#define PqMsg_RequestPrimaryStatus 'p' + +/* These are the codes sent by the frontend and backend. */ + +#define PqMsg_PasswordMessage 'p' + +/* These are the codes sent by the frontend and backend. */ /* These are the authentication request codes sent by the backend. */ -- 2.39.5 (Apple Git-154)