]> granicus.if.org Git - postgresql/commitdiff
Fix LagTrackerRead() for timeline increments
authorSimon Riggs <simon@2ndQuadrant.com>
Sun, 23 Apr 2017 20:35:41 +0000 (21:35 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Sun, 23 Apr 2017 20:35:41 +0000 (21:35 +0100)
Bug was masked by error in running 004_timeline_switch.pl that was
fixed recently in 7d68f2281a.

Detective work by Alvaro Herrera and Tom Lane

Author: Thomas Munro

src/backend/replication/walsender.c

index 26090738fc347e701cbc71a5313c254d2495d5fe..064cf5ee28b1009496f99fbd2d6c90e1affd2954 100644 (file)
@@ -3328,7 +3328,16 @@ LagTrackerRead(int head, XLogRecPtr lsn, TimestampTz now)
                        WalTimeSample prev = LagTracker.last_read[head];
                        WalTimeSample next = LagTracker.buffer[LagTracker.read_heads[head]];
 
-                       Assert(lsn >= prev.lsn);
+                       if (lsn < prev.lsn)
+                       {
+                               /*
+                                * Reported LSNs shouldn't normally go backwards, but it's
+                                * possible when there is a timeline change.  Treat as not
+                                * found.
+                                */
+                               return -1;
+                       }
+
                        Assert(prev.lsn < next.lsn);
 
                        if (prev.time > next.time)