Skip to content

Commit 37edecf

Browse files
Ensure backwards compatibility for GetStableLatestTransactionId()
1 parent 329ee80 commit 37edecf

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
@@ -386,11 +386,10 @@ GetCurrentTransactionIdIfAny(void)
386386
return CurrentTransactionState->transactionId;
387387
}
388388

389-
390389
/*
391-
* GetStableLatestTransactionIdIfAny
390+
* GetStableLatestTransactionId
392391
*
393-
* Get the latest XID once and then return same value for rest of transaction.
392+
* Get the XID once and then return same value for rest of transaction.
394393
* Acts as a useful reference point for maintenance tasks.
395394
*/
396395
TransactionId
@@ -399,13 +398,16 @@ GetStableLatestTransactionId(void)
399398
static LocalTransactionId lxid = InvalidLocalTransactionId;
400399
static TransactionId stablexid = InvalidTransactionId;
401400

402-
if (lxid != MyProc->lxid ||
403-
!TransactionIdIsValid(stablexid))
401+
if (lxid != MyProc->lxid)
404402
{
405403
lxid = MyProc->lxid;
406-
stablexid = ReadNewTransactionId();
404+
stablexid = GetTopTransactionIdIfAny();
405+
if (!TransactionIdIsValid(stablexid))
406+
stablexid = ReadNewTransactionId();
407407
}
408408

409+
Assert(TransactionIdIsValid(stablexid));
410+
409411
return stablexid;
410412
}
411413

0 commit comments

Comments
 (0)