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

Commitd44060c

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 parent3ba1793 commitd44060c

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@ TransactionIdInRecentPast(uint64 xid_with_epoch, TransactionId *extracted_xid)
116116
{
117117
uint32xid_epoch= (uint32) (xid_with_epoch >>32);
118118
TransactionIdxid= (TransactionId)xid_with_epoch;
119+
FullTransactionIdfxid;
119120
uint32now_epoch;
120121
TransactionIdnow_epoch_next_xid;
121122
FullTransactionIdnow_fullxid;
123+
TransactionIdoldest_xid;
124+
FullTransactionIdoldest_fxid;
122125

126+
fxid=FullTransactionIdFromEpochAndXid(xid_epoch,xid);
123127
now_fullxid=ReadNextFullTransactionId();
124128
now_epoch_next_xid=XidFromFullTransactionId(now_fullxid);
125129
now_epoch=EpochFromFullTransactionId(now_fullxid);
@@ -151,17 +155,24 @@ TransactionIdInRecentPast(uint64 xid_with_epoch, TransactionId *extracted_xid)
151155
Assert(LWLockHeldByMe(CLogTruncationLock));
152156

153157
/*
154-
* If the transaction ID has wrapped around, it's definitely too old to
155-
* determine the commit status. Otherwise, we can compare it to
156-
* ShmemVariableCache->oldestClogXid to determine whether the relevant
157-
* CLOG entry is guaranteed to still exist.
158+
* If fxid is not older than ShmemVariableCache->oldestClogXid, the
159+
* relevant CLOG entry is guaranteed to still exist. Convert
160+
* ShmemVariableCache->oldestClogXid into a FullTransactionId to compare
161+
* it with fxid. Determine the right epoch knowing that oldest_fxid
162+
* shouldn't be more than 2^31 older than now_fullxid.
158163
*/
159-
if (xid_epoch+1<now_epoch
160-
|| (xid_epoch+1==now_epoch&&xid<now_epoch_next_xid)
161-
||TransactionIdPrecedes(xid,ShmemVariableCache->oldestClogXid))
162-
return false;
163-
164-
return true;
164+
oldest_xid=ShmemVariableCache->oldestClogXid;
165+
Assert(TransactionIdPrecedesOrEquals(oldest_xid,now_epoch_next_xid));
166+
if (oldest_xid <=now_epoch_next_xid)
167+
{
168+
oldest_fxid=FullTransactionIdFromEpochAndXid(now_epoch,oldest_xid);
169+
}
170+
else
171+
{
172+
Assert(now_epoch>0);
173+
oldest_fxid=FullTransactionIdFromEpochAndXid(now_epoch-1,oldest_xid);
174+
}
175+
return !FullTransactionIdPrecedes(fxid,oldest_fxid);
165176
}
166177

167178
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp