Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Always treat a standby returning an an invalid flush location as async
authorMagnus Hagander <magnus@hagander.net>
Wed, 4 Jul 2012 13:10:46 +0000 (15:10 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 4 Jul 2012 13:24:17 +0000 (15:24 +0200)
This ensures that a standby such as pg_receivexlog will not be selected
as sync standby - which would cause the master to block waiting for
a location that could never happen.

Fujii Masao

src/backend/replication/syncrep.c
src/backend/replication/walreceiver.c
src/backend/replication/walsender.c

index d475e0383d4060274de5453d3eea1938660d3f0a..10af4e85c1302c5e3d2ad472c9f876bd7db104fa 100644 (file)
@@ -379,10 +379,12 @@ SyncRepReleaseWaiters(void)
    /*
     * If this WALSender is serving a standby that is not on the list of
     * potential standbys then we have nothing to do. If we are still starting
-    * up or still running base backup, then leave quickly also.
+    * up, still running base backup or the current flush position is still
+    * invalid, then leave quickly also.
     */
    if (MyWalSnd->sync_standby_priority == 0 ||
-       MyWalSnd->state < WALSNDSTATE_STREAMING)
+       MyWalSnd->state < WALSNDSTATE_STREAMING ||
+       XLogRecPtrIsInvalid(MyWalSnd->flush))
        return;
 
    /*
@@ -402,7 +404,8 @@ SyncRepReleaseWaiters(void)
            walsnd->state == WALSNDSTATE_STREAMING &&
            walsnd->sync_standby_priority > 0 &&
            (priority == 0 ||
-            priority > walsnd->sync_standby_priority))
+            priority > walsnd->sync_standby_priority) &&
+           !XLogRecPtrIsInvalid(walsnd->flush))
        {
            priority = walsnd->sync_standby_priority;
            syncWalSnd = walsnd;
index 18b4727fa81fc661129440466d3b9d1061134fff..7058b888ca3c0015cac30ce80e253672d2e15a51 100644 (file)
@@ -276,6 +276,11 @@ WalReceiverMain(void)
    walrcv_connect(conninfo, startpoint);
    DisableWalRcvImmediateExit();
 
+   /* Initialize LogstreamResult, reply_message and feedback_message */
+   LogstreamResult.Write = LogstreamResult.Flush = GetXLogReplayRecPtr();
+   MemSet(&reply_message, 0, sizeof(reply_message));
+   MemSet(&feedback_message, 0, sizeof(feedback_message));
+
    /* Loop until end-of-streaming or error */
    for (;;)
    {
index 32cc52dbfd74b44e3cadbd993cb14296d4952d9e..1648eedf90d19a0319834d35f7a5128d0054e065 100644 (file)
@@ -1443,12 +1443,19 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
 
        if (walsnd->pid != 0)
        {
-           sync_priority[i] = walsnd->sync_standby_priority;
+           /*
+            * Treat a standby such as a pg_basebackup background process
+            * which always returns an invalid flush location, as an
+            * asynchronous standby.
+            */
+           sync_priority[i] = XLogRecPtrIsInvalid(walsnd->flush) ?
+               0 : walsnd->sync_standby_priority;
 
            if (walsnd->state == WALSNDSTATE_STREAMING &&
                walsnd->sync_standby_priority > 0 &&
                (priority == 0 ||
-                priority > walsnd->sync_standby_priority))
+                priority > walsnd->sync_standby_priority) &&
+               !XLogRecPtrIsInvalid(walsnd->flush))
            {
                priority = walsnd->sync_standby_priority;
                sync_standby = i;