]> granicus.if.org Git - postgresql/commitdiff
Init crash recovery using the latest available TLI
authorSimon Riggs <simon@2ndQuadrant.com>
Sun, 19 May 2013 16:31:07 +0000 (17:31 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Sun, 19 May 2013 16:31:07 +0000 (17:31 +0100)
This simplifies the handling of crashes after fast promotion and various
minor cases that can exist in short timing windows around that case.

Broad fix to bug reported by Michael Paquier on -hackers,
approach prompted by Heikki Linnakangas

src/backend/access/transam/xlog.c

index ceb20b79172d78456a06dcc1333072e37775951d..7d34218bef09ef6eb0b42b8dfb966b43c900d7ce 100644 (file)
@@ -4932,10 +4932,14 @@ StartupXLOG(void)
        RelationCacheInitFileRemove();
 
        /*
-        * Initialize on the assumption we want to recover to the same timeline
+        * Initialize on the assumption we want to recover to the latest timeline
         * that's active according to pg_control.
         */
-       recoveryTargetTLI = ControlFile->checkPointCopy.ThisTimeLineID;
+       if (ControlFile->minRecoveryPointTLI >
+               ControlFile->checkPointCopy.ThisTimeLineID)
+               recoveryTargetTLI = ControlFile->minRecoveryPointTLI;
+       else
+               recoveryTargetTLI = ControlFile->checkPointCopy.ThisTimeLineID;
 
        /*
         * Check for recovery control file, and if so set up state for offline
@@ -4972,22 +4976,6 @@ StartupXLOG(void)
                        ereport(LOG,
                                        (errmsg("starting archive recovery")));
        }
-       else if (ControlFile->minRecoveryPointTLI > 0)
-       {
-               /*
-                * If the minRecoveryPointTLI is set when not in Archive Recovery
-                * it means that we have crashed after ending recovery and
-                * yet before we wrote a new checkpoint on the new timeline.
-                * That means we are doing a crash recovery that needs to cross
-                * timelines to get to our newly assigned timeline again.
-                * The timeline we are headed for is exact and not 'latest'.
-                * As soon as we hit a checkpoint, the minRecoveryPointTLI is
-                * reset, so we will not enter crash recovery again.
-                */
-               Assert(ControlFile->minRecoveryPointTLI != 1);
-               recoveryTargetTLI = ControlFile->minRecoveryPointTLI;
-               recoveryTargetIsLatest = false;
-       }
 
        /*
         * Take ownership of the wakeup latch if we're going to sleep during