Skip to content

Commit b4a5fe8

Browse files
committed
Advance replorigin during prepare
1 parent 6761fc9 commit b4a5fe8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/backend/access/transam/twophase.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,10 @@ EndPrepare(GlobalTransaction gxact)
10251025
xl_xact_origin xl_origin;
10261026
xl_xact_xinfo xl_xinfo;
10271027
uint8 info = XLOG_XACT_PREPARE;
1028+
bool replorigin;
1029+
1030+
replorigin = (replorigin_session_origin != InvalidRepOriginId &&
1031+
replorigin_session_origin != DoNotReplicateId);
10281032

10291033
/* Add the end sentinel to the list of 2PC records */
10301034
RegisterTwoPhaseRecord(TWOPHASE_RM_END_ID, 0,
@@ -1089,6 +1093,12 @@ EndPrepare(GlobalTransaction gxact)
10891093
XLogIncludeOrigin();
10901094

10911095
gxact->prepare_end_lsn = XLogInsert(RM_XACT_ID, info);
1096+
1097+
if (replorigin)
1098+
/* Move LSNs forward for this replication origin */
1099+
replorigin_session_advance(replorigin_session_origin_lsn,
1100+
XactLastRecEnd);
1101+
10921102
XLogFlush(gxact->prepare_end_lsn);
10931103

10941104
/* If we crash now, we have prepared: WAL replay will fix things */

src/backend/access/transam/xact.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5657,9 +5657,20 @@ xact_redo(XLogReaderState *record)
56575657
}
56585658
else if (info == XLOG_XACT_PREPARE)
56595659
{
5660+
xl_xact_parsed_prepare parsed;
5661+
5662+
ParsePrepareRecord(XLogRecGetXid(record), XLogRecGetData(record), &parsed);
5663+
56605664
/* the record contents are exactly the 2PC file */
56615665
RecreateTwoPhaseFile(XLogRecGetXid(record),
56625666
XLogRecGetData(record), XLogRecGetDataLen(record));
5667+
5668+
if (parsed.xinfo & XACT_XINFO_HAS_ORIGIN)
5669+
{
5670+
/* recover apply progress */
5671+
replorigin_advance(XLogRecGetOrigin(record), parsed.origin_lsn,
5672+
record->EndRecPtr, false /* backward */ , false /* WAL */ );
5673+
}
56635674
}
56645675
else if (info == XLOG_XACT_ASSIGNMENT)
56655676
{

0 commit comments

Comments
 (0)