aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2023-07-25 08:50:37 +0530
committerAmit Kapila <akapila@postgresql.org>2023-07-25 08:50:37 +0530
commit2864eb977a6e49d4355b679d7e1e54f01a231b80 (patch)
treed3c64e0b06fbb9568b3d8289b8c76b1c88cea77f /src
parent3bb8b9342f8abe81af47ff7e5217865107cc15b3 (diff)
downloadpostgresql-2864eb977a6e49d4355b679d7e1e54f01a231b80.tar.gz
postgresql-2864eb977a6e49d4355b679d7e1e54f01a231b80.zip
Fix the display of UNKNOWN message type in apply worker.
We include the message type while displaying an error context in the apply worker. Now, while retrieving the message type string if the message type is unknown we throw an error that will hide the original error. So, instead, we need to simply return the string indicating an unknown message type. Reported-by: Ashutosh Bapat Author: Euler Taveira, Amit Kapila Reviewed-by: Ashutosh Bapat Backpatch-through: 15 Discussion: https://postgr.es/m/CAExHW5suAEDW-mBZt_qu4RVxWZ1vL54-L+ci2zreYWebpzxYsA@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/logical/proto.c13
-rw-r--r--src/backend/replication/logical/worker.c2
-rw-r--r--src/include/replication/logicalproto.h2
3 files changed, 12 insertions, 5 deletions
diff --git a/src/backend/replication/logical/proto.c b/src/backend/replication/logical/proto.c
index f5f2bc24d8f..a041937ce90 100644
--- a/src/backend/replication/logical/proto.c
+++ b/src/backend/replication/logical/proto.c
@@ -1194,9 +1194,11 @@ logicalrep_read_stream_abort(StringInfo in, TransactionId *xid,
/*
* Get string representing LogicalRepMsgType.
*/
-char *
+const char *
logicalrep_message_type(LogicalRepMsgType action)
{
+ static char err_unknown[20];
+
switch (action)
{
case LOGICAL_REP_MSG_BEGIN:
@@ -1239,7 +1241,12 @@ logicalrep_message_type(LogicalRepMsgType action)
return "STREAM PREPARE";
}
- elog(ERROR, "invalid logical replication message type \"%c\"", action);
+ /*
+ * This message provides context in the error raised when applying a
+ * logical message. So we can't throw an error here. Return an unknown
+ * indicator value so that the original error is still reported.
+ */
+ snprintf(err_unknown, sizeof(err_unknown), "??? (%d)", action);
- return NULL; /* keep compiler quiet */
+ return err_unknown;
}
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index cc6b079fcd6..dcc3fdf6c76 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -2579,7 +2579,7 @@ apply_dispatch(StringInfo s)
default:
ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
- errmsg("invalid logical replication message type \"%c\"", action)));
+ errmsg("invalid logical replication message type \"??? (%d)\"", action)));
}
/* Reset the current command */
diff --git a/src/include/replication/logicalproto.h b/src/include/replication/logicalproto.h
index 04e1cd89cf7..8cdc04a65f5 100644
--- a/src/include/replication/logicalproto.h
+++ b/src/include/replication/logicalproto.h
@@ -249,6 +249,6 @@ extern void logicalrep_write_stream_abort(StringInfo out, TransactionId xid,
TransactionId subxid);
extern void logicalrep_read_stream_abort(StringInfo in, TransactionId *xid,
TransactionId *subxid);
-extern char *logicalrep_message_type(LogicalRepMsgType action);
+extern const char *logicalrep_message_type(LogicalRepMsgType action);
#endif /* LOGICAL_PROTO_H */