mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Merge copies of converting an XID to a FullTransactionId.
Assume twophase.c is the performance-sensitive caller, and preserve its choice of unlikely() branch hint. Add some retrospective rationale for that choice. Back-patch to v17, for the next commit to use it. Reviewed (in earlier versions) by Michael Paquier. Discussion: https://postgr.es/m/17821-dd8c334263399284@postgresql.org Discussion: https://postgr.es/m/20250116010051.f3.nmisch@google.com
This commit is contained in:
@@ -929,32 +929,16 @@ TwoPhaseGetDummyProc(TransactionId xid, bool lock_held)
|
||||
/*
|
||||
* Compute the FullTransactionId for the given TransactionId.
|
||||
*
|
||||
* The wrap logic is safe here because the span of active xids cannot exceed one
|
||||
* epoch at any given time.
|
||||
* This is safe if the xid has not yet reached COMMIT PREPARED or ROLLBACK
|
||||
* PREPARED. After those commands, concurrent vac_truncate_clog() may make
|
||||
* the xid cease to qualify as allowable. XXX Not all callers limit their
|
||||
* calls accordingly.
|
||||
*/
|
||||
static inline FullTransactionId
|
||||
AdjustToFullTransactionId(TransactionId xid)
|
||||
{
|
||||
FullTransactionId nextFullXid;
|
||||
TransactionId nextXid;
|
||||
uint32 epoch;
|
||||
|
||||
Assert(TransactionIdIsValid(xid));
|
||||
|
||||
LWLockAcquire(XidGenLock, LW_SHARED);
|
||||
nextFullXid = TransamVariables->nextXid;
|
||||
LWLockRelease(XidGenLock);
|
||||
|
||||
nextXid = XidFromFullTransactionId(nextFullXid);
|
||||
epoch = EpochFromFullTransactionId(nextFullXid);
|
||||
if (unlikely(xid > nextXid))
|
||||
{
|
||||
/* Wraparound occurred, must be from a prev epoch. */
|
||||
Assert(epoch > 0);
|
||||
epoch--;
|
||||
}
|
||||
|
||||
return FullTransactionIdFromEpochAndXid(epoch, xid);
|
||||
return FullTransactionIdFromAllowableAt(ReadNextFullTransactionId(), xid);
|
||||
}
|
||||
|
||||
static inline int
|
||||
|
||||
@@ -2166,28 +2166,14 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
|
||||
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(TransamVariables->nextXid);
|
||||
epoch = EpochFromFullTransactionId(TransamVariables->nextXid);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
return FullTransactionIdFromAllowableAt(TransamVariables->nextXid,
|
||||
XLogRecGetXid(record));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user