Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Properly initialize write, flush and replay locations in walsender slots
authorMagnus Hagander <magnus@hagander.net>
Sun, 13 Dec 2015 15:40:37 +0000 (16:40 +0100)
committerMagnus Hagander <magnus@hagander.net>
Sun, 13 Dec 2015 15:43:52 +0000 (16:43 +0100)
These would leak random xlog positions if a walsender used for backup would
a walsender slot previously used by a replication walsender.

In passing also fix a couple of cases where the xlog pointer is directly
compared to zero instead of using XLogRecPtrIsInvalid, noted by
Michael Paquier.

src/backend/replication/walsender.c

index df064d29a3b2244079d2bcdc88b5bbeeae85e7d7..a39f373fa1513b38d930d329ea46614886079c4b 100644 (file)
@@ -1957,6 +1957,9 @@ InitWalSenderSlot(void)
             */
            walsnd->pid = MyProcPid;
            walsnd->sentPtr = InvalidXLogRecPtr;
+           walsnd->write = InvalidXLogRecPtr;
+           walsnd->flush = InvalidXLogRecPtr;
+           walsnd->apply = InvalidXLogRecPtr;
            walsnd->state = WALSNDSTATE_STARTUP;
            SpinLockRelease(&walsnd->mutex);
            /* don't need the lock anymore */
@@ -2843,15 +2846,15 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
            values[1] = CStringGetTextDatum(WalSndGetStateString(state));
            values[2] = LSNGetDatum(sentPtr);
 
-           if (write == 0)
+           if (XLogRecPtrIsInvalid(write))
                nulls[3] = true;
            values[3] = LSNGetDatum(write);
 
-           if (flush == 0)
+           if (XLogRecPtrIsInvalid(flush))
                nulls[4] = true;
            values[4] = LSNGetDatum(flush);
 
-           if (apply == 0)
+           if (XLogRecPtrIsInvalid(apply))
                nulls[5] = true;
            values[5] = LSNGetDatum(apply);