diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index d48d101..95da328 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -41,6 +41,7 @@ #include #include +#include "access/commit_ts.h" #include "access/htup_details.h" #include "access/subtrans.h" #include "access/transam.h" @@ -56,6 +57,7 @@ #include "miscadmin.h" #include "pg_trace.h" #include "pgstat.h" +#include "replication/origin.h" #include "replication/walsender.h" #include "replication/syncrep.h" #include "storage/fd.h" @@ -2087,6 +2089,7 @@ RecordTransactionCommitPrepared(TransactionId xid, bool initfileinval) { XLogRecPtr recptr; + TimestampTz committs = GetCurrentTimestamp(); START_CRIT_SECTION(); @@ -2094,13 +2097,34 @@ RecordTransactionCommitPrepared(TransactionId xid, MyPgXact->delayChkpt = true; /* Emit the XLOG commit record */ - recptr = XactLogCommitRecord(GetCurrentTimestamp(), + recptr = XactLogCommitRecord(committs, nchildren, children, nrels, rels, ninvalmsgs, invalmsgs, initfileinval, false, xid); /* + * Record plain commit ts if not replaying remote actions, or if no + * timestamp is configured. + */ + if (replorigin_sesssion_origin == InvalidRepOriginId || + replorigin_sesssion_origin == DoNotReplicateId || + replorigin_sesssion_origin_timestamp == 0) + replorigin_sesssion_origin_timestamp = committs; + else + replorigin_session_advance(replorigin_sesssion_origin_lsn, + XactLastRecEnd); + + /* + * We don't need to WAL log origin or timestamp here, the commit + * record contains all the necessary information and will redo the SET + * action during replay. + */ + TransactionTreeSetCommitTsData(xid, nchildren, children, + replorigin_sesssion_origin_timestamp, + replorigin_sesssion_origin, false); + + /* * We don't currently try to sleep before flush here ... nor is there any * support for async commit of a prepared xact (the very idea is probably * a contradiction) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index b53d95f..6ef876d 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -1119,6 +1119,9 @@ AtSubStart_ResourceOwner(void) * * Returns latest XID among xact and its children, or InvalidTransactionId * if the xact has no XID. (We compute that here just because it's easier.) + * + * Note: if you change this functions you should also look at + * RecordTransactionCommitPrepared in twophase.c. */ static TransactionId RecordTransactionCommit(void)