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

Function ProcessKeepaliveMsg

src/bin/pg_basebackup/receivelog.c:990–1042  ·  view source on GitHub ↗

* Process the keepalive message. */

Source from the content-addressed store, hash-verified

988 * Process the keepalive message.
989 */
990static bool
991ProcessKeepaliveMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
992 XLogRecPtr blockpos, TimestampTz *last_status)
993{
994 int pos;
995 bool replyRequested;
996 TimestampTz now;
997
998 /*
999 * Parse the keepalive message, enclosed in the CopyData message. We just
1000 * check if the server requested a reply, and ignore the rest.
1001 */
1002 pos = 1; /* skip msgtype 'k' */
1003 pos += 8; /* skip walEnd */
1004 pos += 8; /* skip sendTime */
1005
1006 if (len < pos + 1)
1007 {
1008 pg_log_error("streaming header too small: %d", len);
1009 return false;
1010 }
1011 replyRequested = copybuf[pos];
1012
1013 /* If the server requested an immediate reply, send one. */
1014 if (replyRequested && still_sending)
1015 {
1016 if (reportFlushPosition && lastFlushPosition < blockpos &&
1017 walfile != NULL)
1018 {
1019 /*
1020 * If a valid flush location needs to be reported, flush the
1021 * current WAL file so that the latest flush location is sent back
1022 * to the server. This is necessary to see whether the last WAL
1023 * data has been successfully replicated or not, at the normal
1024 * shutdown of the server.
1025 */
1026 if (stream->walmethod->sync(walfile) != 0)
1027 {
1028 pg_log_fatal("could not fsync file \"%s\": %s",
1029 current_walfile_name, stream->walmethod->getlasterror());
1030 exit(1);
1031 }
1032 lastFlushPosition = blockpos;
1033 }
1034
1035 now = feGetCurrentTimestamp();
1036 if (!sendFeedback(conn, blockpos, now, false))
1037 return false;
1038 *last_status = now;
1039 }
1040
1041 return true;
1042}
1043
1044/*
1045 * Process XLogData message.

Callers 1

HandleCopyStreamFunction · 0.85

Calls 2

feGetCurrentTimestampFunction · 0.85
sendFeedbackFunction · 0.70

Tested by

no test coverage detected