From d8f68fbce06bb9af4e6c15d3260e0266a46555ea Mon Sep 17 00:00:00 2001 From: Maxim Orlov Date: Fri, 27 Feb 2026 14:25:21 +0300 Subject: [PATCH 1/3] Swicth TransamVariables->oldestClogXid to FullTransactionId This commit refactors the code as a step to FullTransactionId in clog. --- contrib/amcheck/verify_heapam.c | 4 +--- src/backend/access/transam/varsup.c | 10 +++++++--- src/backend/utils/adt/xid8funcs.c | 20 +++++--------------- src/include/access/transam.h | 3 ++- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c index 31e19fbc69..e4a654e0ad 100644 --- a/contrib/amcheck/verify_heapam.c +++ b/contrib/amcheck/verify_heapam.c @@ -2157,9 +2157,7 @@ get_xid_status(TransactionId xid, HeapCheckContext *ctx, *status = XID_COMMITTED; LWLockAcquire(XactTruncationLock, LW_SHARED); - clog_horizon = - FullTransactionIdFromXidAndCtx(TransamVariables->oldestClogXid, - ctx); + clog_horizon = TransamVariables->oldestClogXid; if (FullTransactionIdPrecedesOrEquals(clog_horizon, fxid)) { if (TransactionIdIsCurrentTransactionId(xid)) diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 3e95d4cfd1..3e08c308d0 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -354,11 +354,15 @@ AdvanceNextFullTransactionIdPastXid(TransactionId xid) void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid) { + FullTransactionId oldest_datfrozenfxid = + FullTransactionIdFromAllowableAt(ReadNextFullTransactionId(), + oldest_datfrozenxid); + LWLockAcquire(XactTruncationLock, LW_EXCLUSIVE); - if (TransactionIdPrecedes(TransamVariables->oldestClogXid, - oldest_datfrozenxid)) + if (FullTransactionIdPrecedes(TransamVariables->oldestClogXid, + oldest_datfrozenfxid)) { - TransamVariables->oldestClogXid = oldest_datfrozenxid; + TransamVariables->oldestClogXid = oldest_datfrozenfxid; } LWLockRelease(XactTruncationLock); } diff --git a/src/backend/utils/adt/xid8funcs.c b/src/backend/utils/adt/xid8funcs.c index c607e78d9a..7c37b40b41 100644 --- a/src/backend/utils/adt/xid8funcs.c +++ b/src/backend/utils/adt/xid8funcs.c @@ -97,25 +97,18 @@ StaticAssertDecl(MAX_BACKENDS * 2 <= PG_SNAPSHOT_MAX_NXIP, static bool TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid) { - TransactionId xid = XidFromFullTransactionId(fxid); - FullTransactionId now_fullxid; - TransactionId oldest_clog_xid; - FullTransactionId oldest_clog_fxid; - - now_fullxid = ReadNextFullTransactionId(); - if (extracted_xid != NULL) - *extracted_xid = xid; + *extracted_xid = XidFromFullTransactionId(fxid); - if (!TransactionIdIsValid(xid)) + if (!FullTransactionIdIsValid(fxid)) return false; /* For non-normal transaction IDs, we can ignore the epoch. */ - if (!TransactionIdIsNormal(xid)) + if (!FullTransactionIdIsNormal(fxid)) return true; /* If the transaction ID is in the future, throw an error. */ - if (!FullTransactionIdPrecedes(fxid, now_fullxid)) + if (!FullTransactionIdPrecedes(fxid, ReadNextFullTransactionId())) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("transaction ID %" PRIu64 " is in the future", @@ -141,10 +134,7 @@ TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid) * advancement reinstated the usual oldestClogXid==oldestXid. Whether or * not that happened, oldestClogXid is allowable relative to now_fullxid. */ - oldest_clog_xid = TransamVariables->oldestClogXid; - oldest_clog_fxid = - FullTransactionIdFromAllowableAt(now_fullxid, oldest_clog_xid); - return !FullTransactionIdPrecedes(fxid, oldest_clog_fxid); + return !FullTransactionIdPrecedes(fxid, TransamVariables->oldestClogXid); } /* diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 6fa91bfcdc..f08362898c 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -250,7 +250,8 @@ typedef struct TransamVariablesData /* * These fields are protected by XactTruncationLock */ - TransactionId oldestClogXid; /* oldest it's safe to look up in clog */ + FullTransactionId oldestClogXid; /* oldest it's safe to look up in + * clog */ } TransamVariablesData; -- 2.43.0