]> granicus.if.org Git - postgresql/commitdiff
Ensure backwards compatibility for GetStableLatestTransactionId()
authorSimon Riggs <simon@2ndQuadrant.com>
Sat, 12 May 2012 12:26:10 +0000 (13:26 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Sat, 12 May 2012 12:26:10 +0000 (13:26 +0100)
src/backend/access/transam/xact.c

index 1654a0e5c739e56f742ad094fd422633d8896c9d..c71a10e4ea21fbeee273f6f8065b29b3312609ae 100644 (file)
@@ -390,11 +390,10 @@ GetCurrentTransactionIdIfAny(void)
        return CurrentTransactionState->transactionId;
 }
 
-
 /*
- *     GetStableLatestTransactionIdIfAny
+ *     GetStableLatestTransactionId
  *
- * Get the latest XID once and then return same value for rest of transaction.
+ * Get the XID once and then return same value for rest of transaction.
  * Acts as a useful reference point for maintenance tasks.
  */
 TransactionId
@@ -403,13 +402,16 @@ GetStableLatestTransactionId(void)
        static LocalTransactionId lxid = InvalidLocalTransactionId;
        static TransactionId stablexid = InvalidTransactionId;
 
-       if (lxid != MyProc->lxid ||
-               !TransactionIdIsValid(stablexid))
+       if (lxid != MyProc->lxid)
        {
                lxid = MyProc->lxid;
-               stablexid = ReadNewTransactionId();
+               stablexid = GetTopTransactionIdIfAny();
+               if (!TransactionIdIsValid(stablexid))
+                       stablexid = ReadNewTransactionId();
        }
 
+       Assert(TransactionIdIsValid(stablexid));
+
        return stablexid;
 }