diff options
| author | Simon Riggs <simon@2ndQuadrant.com> | 2012-05-11 14:38:53 +0100 |
|---|---|---|
| committer | Simon Riggs <simon@2ndQuadrant.com> | 2012-05-11 14:38:53 +0100 |
| commit | 67ff11b42b2811c18fc9dfa54ded02303a082f7c (patch) | |
| tree | f76cc0d84cf7dded49bdfc60cf396f5da7bec180 /src/backend/access/transam/xact.c | |
| parent | b149d1f90e7d42f719babc0c26addaeffa18df8c (diff) | |
Ensure age() returns a stable value rather than the latest value
Diffstat (limited to 'src/backend/access/transam/xact.c')
| -rw-r--r-- | src/backend/access/transam/xact.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 750725a43af..df790c0693e 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -388,6 +388,28 @@ GetCurrentTransactionIdIfAny(void) /* + * GetStableLatestTransactionIdIfAny + * + * Get the latest XID once and then return same value for rest of transaction. + * Acts as a useful reference point for maintenance tasks. + */ +TransactionId +GetStableLatestTransactionId(void) +{ + static LocalTransactionId lxid = InvalidLocalTransactionId; + static TransactionId stablexid = InvalidTransactionId; + + if (lxid != MyProc->lxid || + !TransactionIdIsValid(stablexid)) + { + lxid = MyProc->lxid; + stablexid = ReadNewTransactionId(); + } + + return stablexid; +} + +/* * AssignTransactionId * * Assigns a new permanent XID to the given TransactionState. |
