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

Commit67ff11b

Browse files
Ensure age() returns a stable value rather than the latest value
1 parentb149d1f commit67ff11b

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,28 @@ GetCurrentTransactionIdIfAny(void)
387387
}
388388

389389

390+
/*
391+
*GetStableLatestTransactionIdIfAny
392+
*
393+
* Get the latest XID once and then return same value for rest of transaction.
394+
* Acts as a useful reference point for maintenance tasks.
395+
*/
396+
TransactionId
397+
GetStableLatestTransactionId(void)
398+
{
399+
staticLocalTransactionIdlxid=InvalidLocalTransactionId;
400+
staticTransactionIdstablexid=InvalidTransactionId;
401+
402+
if (lxid!=MyProc->lxid||
403+
!TransactionIdIsValid(stablexid))
404+
{
405+
lxid=MyProc->lxid;
406+
stablexid=ReadNewTransactionId();
407+
}
408+
409+
returnstablexid;
410+
}
411+
390412
/*
391413
* AssignTransactionId
392414
*

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include"access/transam.h"
2020
#include"access/xact.h"
2121
#include"libpq/pqformat.h"
22+
#include"storage/proc.h"
2223
#include"utils/builtins.h"
2324

2425
#definePG_GETARG_TRANSACTIONID(n)DatumGetTransactionId(PG_GETARG_DATUM(n))
@@ -87,16 +88,13 @@ xideq(PG_FUNCTION_ARGS)
8788
}
8889

8990
/*
90-
*xid_age- compute age of an XID (relative tocurrent xact)
91+
*xid_age- compute age of an XID (relative tolatest stable xid)
9192
*/
9293
Datum
9394
xid_age(PG_FUNCTION_ARGS)
9495
{
9596
TransactionIdxid=PG_GETARG_TRANSACTIONID(0);
96-
TransactionIdnow=GetTopTransactionIdIfAny();
97-
98-
if (!TransactionIdIsValid(now))
99-
now=ReadNewTransactionId();
97+
TransactionIdnow=GetStableLatestTransactionId();
10098

10199
/* Permanent XIDs are always infinitely old */
102100
if (!TransactionIdIsNormal(xid))

‎src/include/access/xact.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ extern TransactionId GetTopTransactionId(void);
177177
externTransactionIdGetTopTransactionIdIfAny(void);
178178
externTransactionIdGetCurrentTransactionId(void);
179179
externTransactionIdGetCurrentTransactionIdIfAny(void);
180+
externTransactionIdGetStableLatestTransactionId(void);
180181
externSubTransactionIdGetCurrentSubTransactionId(void);
181182
externCommandIdGetCurrentCommandId(boolused);
182183
externTimestampTzGetCurrentTransactionStartTimestamp(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp