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

index be4905181e00e7aa7e8d4c0b1f3197d0eaf30aef..b34b418fd983907f8a373555a770bf2c3048c390 100644 (file)
@@ -392,11 +392,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
@@ -405,13 +404,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;
 }