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

Function HandleEndOfCopyStream

src/bin/pg_basebackup/receivelog.c:1177–1213  ·  view source on GitHub ↗

* Handle end of the copy stream. */

Source from the content-addressed store, hash-verified

1175 * Handle end of the copy stream.
1176 */
1177static PGresult *
1178HandleEndOfCopyStream(PGconn *conn, StreamCtl *stream, char *copybuf,
1179 XLogRecPtr blockpos, XLogRecPtr *stoppos)
1180{
1181 PGresult *res = PQgetResult(conn);
1182
1183 /*
1184 * The server closed its end of the copy stream. If we haven't closed
1185 * ours already, we need to do so now, unless the server threw an error,
1186 * in which case we don't.
1187 */
1188 if (still_sending)
1189 {
1190 if (!close_walfile(stream, blockpos))
1191 {
1192 /* Error message written in close_walfile() */
1193 PQclear(res);
1194 return NULL;
1195 }
1196 if (PQresultStatus(res) == PGRES_COPY_IN)
1197 {
1198 if (PQputCopyEnd(conn, NULL) <= 0 || PQflush(conn))
1199 {
1200 pg_log_error("could not send copy-end packet: %s",
1201 PQerrorMessage(conn));
1202 PQclear(res);
1203 return NULL;
1204 }
1205 res = PQgetResult(conn);
1206 }
1207 still_sending = false;
1208 }
1209 if (copybuf != NULL)
1210 PQfreemem(copybuf);
1211 *stoppos = blockpos;
1212 return res;
1213}
1214
1215/*
1216 * Check if we should continue streaming, or abort at this point.

Callers 1

HandleCopyStreamFunction · 0.85

Calls 8

PQgetResultFunction · 0.85
close_walfileFunction · 0.85
PQclearFunction · 0.85
PQresultStatusFunction · 0.85
PQputCopyEndFunction · 0.85
PQflushFunction · 0.85
PQerrorMessageFunction · 0.85
PQfreememFunction · 0.85

Tested by

no test coverage detected