aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlogreader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/transam/xlogreader.c')
-rw-r--r--src/backend/access/transam/xlogreader.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index 41dae916b46..33ccfc15531 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -26,6 +26,7 @@
#include "replication/origin.h"
#ifndef FRONTEND
+#include "miscadmin.h"
#include "utils/memutils.h"
#endif
@@ -1443,3 +1444,37 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
return true;
}
+
+#ifndef FRONTEND
+
+/*
+ * Extract the FullTransactionId from a WAL record.
+ */
+FullTransactionId
+XLogRecGetFullXid(XLogReaderState *record)
+{
+ TransactionId xid,
+ next_xid;
+ uint32 epoch;
+
+ /*
+ * This function is only safe during replay, because it depends on the
+ * replay state. See AdvanceNextFullTransactionIdPastXid() for more.
+ */
+ Assert(AmStartupProcess() || !IsUnderPostmaster);
+
+ xid = XLogRecGetXid(record);
+ next_xid = XidFromFullTransactionId(ShmemVariableCache->nextFullXid);
+ epoch = EpochFromFullTransactionId(ShmemVariableCache->nextFullXid);
+
+ /*
+ * If xid is numerically greater than next_xid, it has to be from the
+ * last epoch.
+ */
+ if (unlikely(xid > next_xid))
+ --epoch;
+
+ return FullTransactionIdFromEpochAndXid(epoch, xid);
+};
+
+#endif