/*
* xactStartTimestamp is the value of transaction_timestamp().
* stmtStartTimestamp is the value of statement_timestamp().
- * xactStopTimestamp is the time at which we log a commit or abort WAL record.
+ * xactStopTimestamp is the time at which we log a commit / abort WAL record,
+ * or if that was skipped, the time of the first subsequent
+ * GetCurrentTransactionStopTimestamp() call.
+ *
* These do not change as we enter and exit subtransactions, so we don't
* keep them inside the TransactionState stack.
*/
/*
* GetCurrentTransactionStopTimestamp
*
- * We return current time if the transaction stop time hasn't been set
- * (which can happen if we decide we don't need to log an XLOG record).
+ * If the transaction stop time hasn't already been set, which can happen if
+ * we decided we don't need to log an XLOG record, set xactStopTimestamp.
*/
TimestampTz
GetCurrentTransactionStopTimestamp(void)
{
- if (xactStopTimestamp != 0)
- return xactStopTimestamp;
- return GetCurrentTimestamp();
+ TransactionState s PG_USED_FOR_ASSERTS_ONLY = CurrentTransactionState;
+
+ /* should only be called after commit / abort processing */
+ Assert(s->state == TRANS_DEFAULT ||
+ s->state == TRANS_COMMIT ||
+ s->state == TRANS_ABORT ||
+ s->state == TRANS_PREPARE);
+
+ if (xactStopTimestamp == 0)
+ xactStopTimestamp = GetCurrentTimestamp();
+
+ return xactStopTimestamp;
}
/*
Assert(stmtStartTimestamp != 0);
}
-/*
- * SetCurrentTransactionStopTimestamp
- */
-static inline void
-SetCurrentTransactionStopTimestamp(void)
-{
- xactStopTimestamp = GetCurrentTimestamp();
-}
-
/*
* GetCurrentTransactionNestLevel
*
START_CRIT_SECTION();
MyProc->delayChkptFlags |= DELAY_CHKPT_START;
- SetCurrentTransactionStopTimestamp();
-
- XactLogCommitRecord(xactStopTimestamp,
+ XactLogCommitRecord(GetCurrentTransactionStopTimestamp(),
nchildren, children, nrels, rels,
ndroppedstats, droppedstats,
nmsgs, invalMessages,
*/
if (!replorigin || replorigin_session_origin_timestamp == 0)
- replorigin_session_origin_timestamp = xactStopTimestamp;
+ replorigin_session_origin_timestamp = GetCurrentTransactionStopTimestamp();
TransactionTreeSetCommitTsData(xid, nchildren, children,
replorigin_session_origin_timestamp,
xact_time = GetCurrentTimestamp();
else
{
- SetCurrentTransactionStopTimestamp();
- xact_time = xactStopTimestamp;
+ xact_time = GetCurrentTransactionStopTimestamp();
}
XactLogAbortRecord(xact_time,