XidEpoch++ if wraparound during checkpoint.
authorSimon Riggs
Sun, 2 Dec 2012 15:02:28 +0000 (15:02 +0000)
committerSimon Riggs
Sun, 2 Dec 2012 15:02:28 +0000 (15:02 +0000)
If wal_level = hot_standby we update the checkpoint nextxid,
though in the case where a wraparound occurred half-way through
a checkpoint we would neglect updating the epoch also. Updating
the nextxid is arguably the wrong thing to do, but changing that
may introduce subtle bugs into hot standby startup, while updating
the value doesn't cause any known bugs yet. Minimal fix now to
HEAD and backbranches, wider fix later in HEAD.

Bug reported in #6291 by Daniel Farina and slightly differently in

Cause analysis and recommended fixes from Tom Lane and Andres Freund.

Applied patch is minimal version of Andres Freund's work.

src/backend/access/transam/xlog.c

index cf33062f77f28c6f43c1fa6afe771c25b9154d58..2c17e9088a81cd32eeb67bad94e07288ec0274df 100644 (file)
@@ -7423,10 +7423,17 @@ CreateCheckPoint(int flags)
     * If we are shutting down, or Startup process is completing crash
     * recovery we don't need to write running xact data.
     *
-    * Update checkPoint.nextXid since we have a later value
+    * Update checkPoint.nextXid since we may have a later value. If we
+    * do update the value, and we have wrapped, increment epoch also.
     */
    if (!shutdown && XLogStandbyInfoActive())
+   {
+       TransactionId prevXid = checkPoint.nextXid;
+
        LogStandbySnapshot(&checkPoint.nextXid);
+       if (checkPoint.nextXid < prevXid)
+           checkPoint.nextXidEpoch++;
+   }
 
    START_CRIT_SECTION();