Skip to content

Commit abc0910

Browse files
author
Amit Kapila
committed
Add logical change details to logical replication worker errcontext.
Previously, on the subscriber, we set the error context callback for the tuple data conversion failures. This commit replaces the existing error context callback with a comprehensive one so that it shows not only the details of data conversion failures but also the details of logical change being applied by the apply worker or table sync worker. The additional information displayed will be the command, transaction id, and timestamp. The error context is added to an error only when applying a change but not while doing other work like receiving data etc. This will help users in diagnosing the problems that occur during logical replication. It also can be used for future work that allows skipping a particular transaction on the subscriber. Author: Masahiko Sawada Reviewed-by: Hou Zhijie, Greg Nancarrow, Haiying Tang, Amit Kapila Tested-by: Haiying Tang Discussion: https://postgr.es/m/CAD21AoDeScrsHhLyEPYqN3sydg6PxAPVBboK=30xJfUVihNZDA@mail.gmail.com
1 parent 191dce1 commit abc0910

File tree

4 files changed

+235
-80
lines changed

4 files changed

+235
-80
lines changed

src/backend/replication/logical/proto.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,3 +1156,56 @@ logicalrep_read_stream_abort(StringInfo in, TransactionId *xid,
11561156
*xid = pq_getmsgint(in, 4);
11571157
*subxid = pq_getmsgint(in, 4);
11581158
}
1159+
1160+
/*
1161+
* Get string representing LogicalRepMsgType.
1162+
*/
1163+
char *
1164+
logicalrep_message_type(LogicalRepMsgType action)
1165+
{
1166+
switch (action)
1167+
{
1168+
case LOGICAL_REP_MSG_BEGIN:
1169+
return "BEGIN";
1170+
case LOGICAL_REP_MSG_COMMIT:
1171+
return "COMMIT";
1172+
case LOGICAL_REP_MSG_ORIGIN:
1173+
return "ORIGIN";
1174+
case LOGICAL_REP_MSG_INSERT:
1175+
return "INSERT";
1176+
case LOGICAL_REP_MSG_UPDATE:
1177+
return "UPDATE";
1178+
case LOGICAL_REP_MSG_DELETE:
1179+
return "DELETE";
1180+
case LOGICAL_REP_MSG_TRUNCATE:
1181+
return "TRUNCATE";
1182+
case LOGICAL_REP_MSG_RELATION:
1183+
return "RELATION";
1184+
case LOGICAL_REP_MSG_TYPE:
1185+
return "TYPE";
1186+
case LOGICAL_REP_MSG_MESSAGE:
1187+
return "MESSAGE";
1188+
case LOGICAL_REP_MSG_BEGIN_PREPARE:
1189+
return "BEGIN PREPARE";
1190+
case LOGICAL_REP_MSG_PREPARE:
1191+
return "PREPARE";
1192+
case LOGICAL_REP_MSG_COMMIT_PREPARED:
1193+
return "COMMIT PREPARED";
1194+
case LOGICAL_REP_MSG_ROLLBACK_PREPARED:
1195+
return "ROLLBACK PREPARED";
1196+
case LOGICAL_REP_MSG_STREAM_START:
1197+
return "STREAM START";
1198+
case LOGICAL_REP_MSG_STREAM_STOP:
1199+
return "STREAM STOP";
1200+
case LOGICAL_REP_MSG_STREAM_COMMIT:
1201+
return "STREAM COMMIT";
1202+
case LOGICAL_REP_MSG_STREAM_ABORT:
1203+
return "STREAM ABORT";
1204+
case LOGICAL_REP_MSG_STREAM_PREPARE:
1205+
return "STREAM PREPARE";
1206+
}
1207+
1208+
elog(ERROR, "invalid logical replication message type \"%c\"", action);
1209+
1210+
return NULL; /* keep compiler quiet */
1211+
}

0 commit comments

Comments
 (0)