Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4efaf4b

Browse files
committed
Fix wrong logic in TransactionIdInRecentPast()
The TransactionIdInRecentPast() should return false for all the transactionsolder than TransamVariables->oldestClogXid. However, the function containsa bug in comparison FullTransactionId to TransactionID allowing fulltransactions between nextXid - 2^32 and oldestClogXid - 2^31.This commit fixes TransactionIdInRecentPast() by turning the oldestClogXid intoFullTransactionId first, then performing the comparison.Backpatch to all supported versions.Reported-by: Egor ChindyaskinBug: 18212Discussion:https://postgr.es/m/18212-547307f8adf57262%40postgresql.orgAuthor: Karina LitskevichReviewed-by: Kyotaro HoriguchiBackpatch-through: 12
1 parentb3b2bf3 commit4efaf4b

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

‎src/backend/utils/adt/xid8funcs.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ typedef struct
9090
staticbool
9191
TransactionIdInRecentPast(FullTransactionIdfxid,TransactionId*extracted_xid)
9292
{
93-
uint32xid_epoch=EpochFromFullTransactionId(fxid);
9493
TransactionIdxid=XidFromFullTransactionId(fxid);
9594
uint32now_epoch;
9695
TransactionIdnow_epoch_next_xid;
9796
FullTransactionIdnow_fullxid;
97+
TransactionIdoldest_xid;
98+
FullTransactionIdoldest_fxid;
9899

99100
now_fullxid=ReadNextFullTransactionId();
100101
now_epoch_next_xid=XidFromFullTransactionId(now_fullxid);
@@ -128,17 +129,24 @@ TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid)
128129
Assert(LWLockHeldByMe(XactTruncationLock));
129130

130131
/*
131-
* If the transaction ID has wrapped around, it's definitely too old to
132-
* determine the commit status. Otherwise, we can compare it to
133-
* ShmemVariableCache->oldestClogXid to determine whether the relevant
134-
* CLOG entry is guaranteed to still exist.
132+
* If fxid is not older than ShmemVariableCache->oldestClogXid, the
133+
* relevant CLOG entry is guaranteed to still exist. Convert
134+
* ShmemVariableCache->oldestClogXid into a FullTransactionId to compare
135+
* it with fxid. Determine the right epoch knowing that oldest_fxid
136+
* shouldn't be more than 2^31 older than now_fullxid.
135137
*/
136-
if (xid_epoch+1<now_epoch
137-
|| (xid_epoch+1==now_epoch&&xid<now_epoch_next_xid)
138-
||TransactionIdPrecedes(xid,ShmemVariableCache->oldestClogXid))
139-
return false;
140-
141-
return true;
138+
oldest_xid=ShmemVariableCache->oldestClogXid;
139+
Assert(TransactionIdPrecedesOrEquals(oldest_xid,now_epoch_next_xid));
140+
if (oldest_xid <=now_epoch_next_xid)
141+
{
142+
oldest_fxid=FullTransactionIdFromEpochAndXid(now_epoch,oldest_xid);
143+
}
144+
else
145+
{
146+
Assert(now_epoch>0);
147+
oldest_fxid=FullTransactionIdFromEpochAndXid(now_epoch-1,oldest_xid);
148+
}
149+
return !FullTransactionIdPrecedes(fxid,oldest_fxid);
142150
}
143151

144152
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp