Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uiuLT-00HUJm-Ko for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 12:31:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uiuLS-0018Zw-Kr for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 12:31:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uiuLS-0018Zo-5l for pgsql-hackers@lists.postgresql.org; Mon, 04 Aug 2025 12:31:14 +0000 Received: from fhigh-b2-smtp.messagingengine.com ([202.12.124.153]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uiuLO-000hU1-0r for pgsql-hackers@lists.postgresql.org; Mon, 04 Aug 2025 12:31:13 +0000 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id E7F8E7A0601; Mon, 4 Aug 2025 08:31:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Mon, 04 Aug 2025 08:31:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm1; t=1754310668; x= 1754397068; bh=jiaAveRivUaX/HmrG+AkLGbJeIuBr5TyY2mnusIL5Wc=; b=e tPxFJUX/g6rJQ0SZF1PZTY92iPCPaih+lpvz0LJP+HnNROm8LS35tp1EVCRd8eXP Dk4r9j0QWWXv5qaH4oaE9Bg3mk2c2XArPiWT5HV41MhhvGyT+ulhf/kSqjBupihB 0UYQafDJDIaRcYYI0PZF/ZTtiQ342qw+TJ9Zq5g0uEbw1mMztoUseYHpaI6HQfDh 1hRfl1B7bOWyo2Ryh/rI2IywQ1hYpEV7Yg3Ajay4KIdQppI9/bI1oo0GirSSxK+t s8wZ5scV8FIdcpYDZUEW55YQQARzxEYgCeWPbsxeaxKM14bzVIjGF/xvzenLpc2j UcuG4q0uD6+dRnGjmvf+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1754310668; x=1754397068; bh=j iaAveRivUaX/HmrG+AkLGbJeIuBr5TyY2mnusIL5Wc=; b=n0NIpt8zVyIZeQZVh s3GblWm8zZdSKkgOufL/9ir/Pze1ciuUtGavilb14Q6H+1wQggIYQ4TYu02LVVFr whlidNcF7MWHsq078ISqJwmb0kMFhbM5XdRpHKzWzn9mlnVT4YyGSpyHdoFAAzcK WMBSLt3STIAMRTgucnrS/czpIK9yXn3R8hdRrFiNuLQ/DfWhI9jrSI7JPwkyPFVN 01nQPzl6vsEmyePCITAZy2HDMLvSdO9I8OF7CiZXYU0CFcX4HslSU6cYMp0IGrCO mk8n0IoL1Fnfe06ga6NTNbXksemgDHOskgq4ZTzyj/bEQrQq6QmOFhEKcqkwDdsf J1REA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduuddvfedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkgggtugfgjgesmhekreertddtjeenucfhrhhomheplmhlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtf frrghtthgvrhhnpeegudetudejheduveevgeehjeegleevveevvdeutdejtdekuefhheeh geevtdejteenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgv sehkuhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopeegpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehjrggtohgsrdgthhgrmhhpihhonhesvghnthgvrhhprhhishgv uggsrdgtohhmpdhrtghpthhtohepuggrvhgvtghrrghmvghrsehgmhgrihhlrdgtohhmpd hrtghpthhtohepnhgrthhhrghnuggsohhsshgrrhhtsehgmhgrihhlrdgtohhmpdhrtghp thhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrd horhhg X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Aug 2025 08:31:07 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1754310665; bh=4vT2Xaz4Neg0y8qiTLgwHybVp3EFkKaBeOTLY6U2GE4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=oiAKb50sYnF9a0xtBsmtSPHn2yuxgnsmyMFBWbL3IVe+pmMUer13tDtRNI2P5pBzM ixhSOmHLcycXjydUQCk4UG0bToYzGHYp251ExjXFoNpBPo7CDK7KxL0OT01giT3MdZ 3Nl0Xnu6R01XJsWWQRjZGRv2lycEo57MN7locBCqGE+JXu9MnhB/7mQ7EhuDUJy3+o qOg4Jso8ZHVEOo9QY0CNHURV5pvKJRnGEREQSCrJjOaa0+fAGdNlx2/7sttdxJ38rH Bw04xsNjI9sGrahWHbUIlaQa0odNfYzHtGLdDZ8UxkuaOCepeR1LlrkyHcy8Vpx5s7 nXi+w+1mDfbvA== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id A65A390; Mon, 4 Aug 2025 14:31:05 +0200 (CEST) Date: Mon, 4 Aug 2025 14:31:05 +0200 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Dave Cramer Cc: Nathan Bossart , Jacob Champion , PostgreSQL Hackers Subject: Re: More protocol.h replacements this time into walsender.c Message-ID: <202508041231.myxuzx2udlze@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="xzp4x5iyxxpxanwz" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --xzp4x5iyxxpxanwz Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2025-Jul-28, Dave Cramer wrote: > I chose PqReplMsg patch attached I think you sent a patch that applied on top of your previous patch instead of a patch on top of master. Here it is as a standalone patch. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ --xzp4x5iyxxpxanwz Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v3-0001-Replace-protocol-replication-constants-with-named.patch" Content-Transfer-Encoding: 8bit From b21aa102999bf26ee20bf9eb916ea6aeee3e1edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Mon, 4 Aug 2025 14:27:53 +0200 Subject: [PATCH v3] Replace protocol replication constants with named constants from protocol.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: Dave Cramer Reviewed-by: Nathan Bossart Reviewed-by: Jacob Champion Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/aIECfYfevCUpenBT@nathan --- src/backend/replication/logical/worker.c | 10 +++++----- src/backend/replication/walreceiver.c | 4 ++-- src/backend/replication/walsender.c | 18 +++++++++--------- src/include/libpq/protocol.h | 13 +++++++++++++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 89e241c8392..4594db65fec 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -3994,7 +3994,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) c = pq_getmsgbyte(&s); - if (c == 'w') + if (c == PqReplMsg_WALData) { XLogRecPtr start_lsn; XLogRecPtr end_lsn; @@ -4016,7 +4016,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) maybe_advance_nonremovable_xid(&rdt_data, false); } - else if (c == 'k') + else if (c == PqReplMsg_PrimaryKeepAlive) { XLogRecPtr end_lsn; TimestampTz timestamp; @@ -4035,7 +4035,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) UpdateWorkerStats(last_received, timestamp, true); } - else if (c == 's') /* Primary status update */ + else if (c == PqReplMsg_PrimaryStatusUpdate) /* Primary status update */ { rdt_data.remote_lsn = pq_getmsgint64(&s); rdt_data.remote_oldestxid = FullTransactionIdFromU64((uint64) pq_getmsgint64(&s)); @@ -4267,7 +4267,7 @@ send_feedback(XLogRecPtr recvpos, bool force, bool requestReply) else resetStringInfo(reply_message); - pq_sendbyte(reply_message, 'r'); + pq_sendbyte(reply_message, PqReplMsg_StandbyStatus); pq_sendint64(reply_message, recvpos); /* write */ pq_sendint64(reply_message, flushpos); /* flush */ pq_sendint64(reply_message, writepos); /* apply */ @@ -4438,7 +4438,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, PqReplMsg_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..82798f2aedb 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, PqReplMsg_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, PqReplMsg_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..b19a7551b9f 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, PqReplMsg_WALData); 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 PqReplMsg_StandbyStatus: ProcessStandbyReplyMessage(); break; - case 'h': + case PqReplMsg_HotStandbyFeedback: ProcessStandbyHSFeedbackMessage(); break; - case 'p': + case PqReplMsg_RequestPrimaryStatus: ProcessStandbyPSRequestMessage(); break; @@ -2752,7 +2752,7 @@ ProcessStandbyPSRequestMessage(void) /* construct the message... */ resetStringInfo(&output_message); - pq_sendbyte(&output_message, 's'); + pq_sendbyte(&output_message, PqReplMsg_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, PqReplMsg_WALData); 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, PqReplMsg_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..ce37e11c3a3 100644 --- a/src/include/libpq/protocol.h +++ b/src/include/libpq/protocol.h @@ -86,4 +86,17 @@ #define AUTH_REQ_SASL_FIN 12 /* Final SASL message */ #define AUTH_REQ_MAX AUTH_REQ_SASL_FIN /* maximum AUTH_REQ_* value */ +/* Replication Protocol, sent by the primary */ + +#define PqReplMsg_WALData 'w' +#define PqReplMsg_PrimaryKeepAlive 'k' +#define PqReplMsg_PrimaryStatusUpdate 's' + +/* Replication Protocol, sent by the standby */ + +#define PqReplMsg_StandbyStatus 'r' +#define PqReplMsg_HotStandbyFeedback 'h' +#define PqReplMsg_RequestPrimaryStatus 'p' + + #endif /* PROTOCOL_H */ -- 2.39.5 --xzp4x5iyxxpxanwz--