Skip to content

Commit 436af24

Browse files
Ensure backwards compatibility for GetStableLatestTransactionId()
1 parent 2c1382d commit 436af24

File tree

1 file changed

+8
-6
lines changed
  • src/backend/access/transam

1 file changed

+8
-6
lines changed

src/backend/access/transam/xact.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,10 @@ GetCurrentTransactionIdIfAny(void)
392392
return CurrentTransactionState->transactionId;
393393
}
394394

395-
396395
/*
397-
* GetStableLatestTransactionIdIfAny
396+
* GetStableLatestTransactionId
398397
*
399-
* Get the latest XID once and then return same value for rest of transaction.
398+
* Get the XID once and then return same value for rest of transaction.
400399
* Acts as a useful reference point for maintenance tasks.
401400
*/
402401
TransactionId
@@ -405,13 +404,16 @@ GetStableLatestTransactionId(void)
405404
static LocalTransactionId lxid = InvalidLocalTransactionId;
406405
static TransactionId stablexid = InvalidTransactionId;
407406

408-
if (lxid != MyProc->lxid ||
409-
!TransactionIdIsValid(stablexid))
407+
if (lxid != MyProc->lxid)
410408
{
411409
lxid = MyProc->lxid;
412-
stablexid = ReadNewTransactionId();
410+
stablexid = GetTopTransactionIdIfAny();
411+
if (!TransactionIdIsValid(stablexid))
412+
stablexid = ReadNewTransactionId();
413413
}
414414

415+
Assert(TransactionIdIsValid(stablexid));
416+
415417
return stablexid;
416418
}
417419

0 commit comments

Comments
 (0)