Skip to content

Commit a42f515

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 7865280 commit a42f515

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
@@ -1578,6 +1578,9 @@ FullTransactionIdFromXidAndCtx(TransactionId xid, const HeapCheckContext *ctx)
15781578
{
15791579
uint32 epoch;
15801580

1581+
Assert(TransactionIdIsNormal(ctx->next_xid));
1582+
Assert(FullTransactionIdIsNormal(ctx->next_fxid));
1583+
15811584
if (!TransactionIdIsNormal(xid))
15821585
return FullTransactionIdFromEpochAndXid(0, xid);
15831586
epoch = EpochFromFullTransactionId(ctx->next_fxid);
@@ -1599,8 +1602,8 @@ update_cached_xid_range(HeapCheckContext *ctx)
15991602
LWLockRelease(XidGenLock);
16001603

16011604
/* And compute alternate versions of the same */
1602-
ctx->oldest_fxid = FullTransactionIdFromXidAndCtx(ctx->oldest_xid, ctx);
16031605
ctx->next_xid = XidFromFullTransactionId(ctx->next_fxid);
1606+
ctx->oldest_fxid = FullTransactionIdFromXidAndCtx(ctx->oldest_xid, ctx);
16041607
}
16051608

16061609
/*

0 commit comments

Comments
 (0)