MCPcopy Create free account
hub / github.com/apache/cloudberry / ProcessXLogDataMsg

Function ProcessXLogDataMsg

src/bin/pg_basebackup/receivelog.c:1047–1172  ·  view source on GitHub ↗

* Process XLogData message. */

Source from the content-addressed store, hash-verified

1045 * Process XLogData message.
1046 */
1047static bool
1048ProcessXLogDataMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
1049 XLogRecPtr *blockpos)
1050{
1051 int xlogoff;
1052 int bytes_left;
1053 int bytes_written;
1054 int hdr_len;
1055
1056 /*
1057 * Once we've decided we don't want to receive any more, just ignore any
1058 * subsequent XLogData messages.
1059 */
1060 if (!(still_sending))
1061 return true;
1062
1063 /*
1064 * Read the header of the XLogData message, enclosed in the CopyData
1065 * message. We only need the WAL location field (dataStart), the rest of
1066 * the header is ignored.
1067 */
1068 hdr_len = 1; /* msgtype 'w' */
1069 hdr_len += 8; /* dataStart */
1070 hdr_len += 8; /* walEnd */
1071 hdr_len += 8; /* sendTime */
1072 if (len < hdr_len)
1073 {
1074 pg_log_error("streaming header too small: %d", len);
1075 return false;
1076 }
1077 *blockpos = fe_recvint64(&copybuf[1]);
1078
1079 /* Extract WAL location for this block */
1080 xlogoff = XLogSegmentOffset(*blockpos, WalSegSz);
1081
1082 /*
1083 * Verify that the initial location in the stream matches where we think
1084 * we are.
1085 */
1086 if (walfile == NULL)
1087 {
1088 /* No file open yet */
1089 if (xlogoff != 0)
1090 {
1091 pg_log_error("received write-ahead log record for offset %u with no file open",
1092 xlogoff);
1093 return false;
1094 }
1095 }
1096 else
1097 {
1098 /* More data in existing segment */
1099 if (stream->walmethod->get_current_pos(walfile) != xlogoff)
1100 {
1101 pg_log_error("got WAL data offset %08x, expected %08x",
1102 xlogoff, (int) stream->walmethod->get_current_pos(walfile));
1103 return false;
1104 }

Callers 1

HandleCopyStreamFunction · 0.85

Calls 7

fe_recvint64Function · 0.85
open_walfileFunction · 0.85
close_walfileFunction · 0.85
PQputCopyEndFunction · 0.85
PQflushFunction · 0.85
PQerrorMessageFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected