Skip to content

Commit 1632724

Browse files
committed
amcheck: Fix ordering bug in update_cached_xid_range()
The initialization order in update_cached_xid_range() was wrong, calling FullTransactionIdFromXidAndCtx() before setting ->next_xid. FullTransactionIdFromXidAndCtx() uses ->next_xid. In most situations this will not cause visible issues, because the next call to update_cached_xid_range() will use a less wrong ->next_xid. It's rare that xids advance fast enough for this to be a problem. Found while adding more asserts to the 64bit xid infrastructure. Reviewed-by: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://postgr.es/m/20230108002923.cyoser3ttmt63bfn@awork3.anarazel.de Backpatch: 14-, where heapam verification was introduced
1 parent 4e63301 commit 1632724

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

contrib/amcheck/verify_heapam.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,9 @@ FullTransactionIdFromXidAndCtx(TransactionId xid, const HeapCheckContext *ctx)
15761576
{
15771577
uint32 epoch;
15781578

1579+
Assert(TransactionIdIsNormal(ctx->next_xid));
1580+
Assert(FullTransactionIdIsNormal(ctx->next_fxid));
1581+
15791582
if (!TransactionIdIsNormal(xid))
15801583
return FullTransactionIdFromEpochAndXid(0, xid);
15811584
epoch = EpochFromFullTransactionId(ctx->next_fxid);
@@ -1597,8 +1600,8 @@ update_cached_xid_range(HeapCheckContext *ctx)
15971600
LWLockRelease(XidGenLock);
15981601

15991602
/* And compute alternate versions of the same */
1600-
ctx->oldest_fxid = FullTransactionIdFromXidAndCtx(ctx->oldest_xid, ctx);
16011603
ctx->next_xid = XidFromFullTransactionId(ctx->next_fxid);
1604+
ctx->oldest_fxid = FullTransactionIdFromXidAndCtx(ctx->oldest_xid, ctx);
16021605
}
16031606

16041607
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy