aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/time
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/time')
-rw-r--r--src/backend/utils/time/snapmgr.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index ef9fc15ac36..d07ca1b0b24 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -957,6 +957,36 @@ xmin_cmp(const pairingheap_node *a, const pairingheap_node *b, void *arg)
}
/*
+ * Get current RecentGlobalXmin value, as a FullTransactionId.
+ */
+FullTransactionId
+GetFullRecentGlobalXmin(void)
+{
+ FullTransactionId nextxid_full;
+ uint32 nextxid_epoch;
+ TransactionId nextxid_xid;
+ uint32 epoch;
+
+ Assert(TransactionIdIsNormal(RecentGlobalXmin));
+
+ /*
+ * Compute the epoch from the next XID's epoch. This relies on the fact
+ * that RecentGlobalXmin must be within the 2 billion XID horizon from the
+ * next XID.
+ */
+ nextxid_full = ReadNextFullTransactionId();
+ nextxid_epoch = EpochFromFullTransactionId(nextxid_full);
+ nextxid_xid = XidFromFullTransactionId(nextxid_full);
+
+ if (RecentGlobalXmin > nextxid_xid)
+ epoch = nextxid_epoch - 1;
+ else
+ epoch = nextxid_epoch;
+
+ return FullTransactionIdFromEpochAndXid(epoch, RecentGlobalXmin);
+}
+
+/*
* SnapshotResetXmin
*
* If there are no more snapshots, we can reset our PGXACT->xmin to InvalidXid.