Ensure backwards compatibility for GetStableLatestTransactionId()
authorSimon Riggs <simon@2ndQuadrant.com>
Sat, 12 May 2012 12:24:15 +0000 (13:24 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Sat, 12 May 2012 12:24:15 +0000 (13:24 +0100)
src/backend/access/transam/xact.c

index df790c0693e3e327e666b58ff6ae300b9e29cb77..d1cebeb86db9f4f977a26d4dddeb23756016f00c 100644 (file)
@@ -386,11 +386,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
@@ -399,13 +398,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;
 }