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

Function apply_handle_stream_commit

src/backend/replication/logical/worker.c:1003–1144  ·  view source on GitHub ↗

* Handle STREAM COMMIT message. */

Source from the content-addressed store, hash-verified

1001 * Handle STREAM COMMIT message.
1002 */
1003static void
1004apply_handle_stream_commit(StringInfo s)
1005{
1006 TransactionId xid;
1007 StringInfoData s2;
1008 int nchanges;
1009 char path[MAXPGPATH];
1010 char *buffer = NULL;
1011 LogicalRepCommitData commit_data;
1012 StreamXidHash *ent;
1013 MemoryContext oldcxt;
1014 BufFile *fd;
1015
1016 if (in_streamed_transaction)
1017 ereport(ERROR,
1018 (errcode(ERRCODE_PROTOCOL_VIOLATION),
1019 errmsg_internal("STREAM COMMIT message without STREAM STOP")));
1020
1021 xid = logicalrep_read_stream_commit(s, &commit_data);
1022
1023 elog(DEBUG1, "received commit for streamed transaction %u", xid);
1024
1025 /* Make sure we have an open transaction */
1026 begin_replication_step();
1027
1028 /*
1029 * Allocate file handle and memory required to process all the messages in
1030 * TopTransactionContext to avoid them getting reset after each message is
1031 * processed.
1032 */
1033 oldcxt = MemoryContextSwitchTo(TopTransactionContext);
1034
1035 /* open the spool file for the committed transaction */
1036 changes_filename(path, MyLogicalRepWorker->subid, xid);
1037 elog(DEBUG1, "replaying changes from file \"%s\"", path);
1038
1039 ent = (StreamXidHash *) hash_search(xidhash,
1040 (void *) &xid,
1041 HASH_FIND,
1042 NULL);
1043 if (!ent)
1044 ereport(ERROR,
1045 (errcode(ERRCODE_PROTOCOL_VIOLATION),
1046 errmsg_internal("transaction %u not found in stream XID hash table",
1047 xid)));
1048
1049 fd = BufFileOpenShared(ent->stream_fileset, path, O_RDONLY);
1050
1051 buffer = palloc(BLCKSZ);
1052 initStringInfo(&s2);
1053
1054 MemoryContextSwitchTo(oldcxt);
1055
1056 remote_final_lsn = commit_data.commit_lsn;
1057
1058 /*
1059 * Make sure the handle apply_dispatch methods are aware we're in a remote
1060 * transaction.

Callers 1

apply_dispatchFunction · 0.85

Calls 15

begin_replication_stepFunction · 0.85
MemoryContextSwitchToFunction · 0.85
changes_filenameFunction · 0.85
hash_searchFunction · 0.85
BufFileOpenSharedFunction · 0.85
initStringInfoFunction · 0.85
pgstat_report_activityFunction · 0.85
end_replication_stepFunction · 0.85
BufFileReadFunction · 0.85
resetStringInfoFunction · 0.85
appendBinaryStringInfoFunction · 0.85

Tested by

no test coverage detected