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

Commit503299b

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 parentd17a3a4 commit503299b

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);
@@ -127,17 +128,24 @@ TransactionIdInRecentPast(FullTransactionId fxid, TransactionId *extracted_xid)
127128
Assert(LWLockHeldByMe(XactTruncationLock));
128129

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

143151
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp