Re: hot_standby_feedback doesn't work on busy servers in 9.3+

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: PostgreSQL Bugs <pgsql-bugs(at)postgresql(dot)org>, Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Subject: Re: hot_standby_feedback doesn't work on busy servers in 9.3+
Date: 2014-01-16 04:56:51
Message-ID: CAA4eK1K-pXw7jEFQ8dzMpX9_fUjhKn2rOvjfiL1rD94km63v0g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Jan 15, 2014 at 6:31 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> Hello,
>
> In 9.3+, when the primary is busy hot_standby_feedback doesn't properly
> work with symptoms like a) spurious query cancels because no feedback
> messages have been sent yet, b) bloat on the primary because we don't
> regularly send feedback leading to stale xmins on the primary.
>
> The relevant code is in walreceiver.c's WalReceiverMain():
>
> len = walrcv_receive(NAPTIME_PER_CYCLE, &buf);
> if (len != 0)
> {
> ...
> /* Let the master know that we received some data. */
> XLogWalRcvSendReply(false, false);
>
> /*
> * If we've written some records, flush them to disk and
> * let the startup process and primary server know about
> * them.
> */
> XLogWalRcvFlush(false);
> }
> else
> {
> ...
> XLogWalRcvSendReply(requestReply, requestReply);
> XLogWalRcvSendHSFeedback(false);
> }
>
> So, when the connection always has data, we'll not send feedback. That's
> pretty easy to demonstrate by running pgbench -jc 8 or so against the
> primary.
>
> Looking into this I also noticed that the busy path is odd, because a)
> why are we sending a reply before flushing things to disk? b)
> XLogWalRcvFlush() will do it's own XLogWalRcvSendReply().

I think call to reply in XLogWalRcvFlush() might not actually send
reply because of time difference of last Reply message which we
sent before flush call.

The only point that occurs to me for having such a code is that
incase flush call fails due to disk space or some other such issue,
it can atleast send the correct write position to primary.

>
> To a good part that seems to have been introduced in
> 6f60fdd7015b032bf49273c99f80913d57eac284.

I don't see that above commit has introduced this behaviour, as
the code in question seems to be there without commit as well,
means that HS feedback is only sent when we don't receive data in WAL
receiver.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2014-01-16 08:44:27 Re: hot_standby_feedback doesn't work on busy servers in 9.3+
Previous Message Day, David 2014-01-15 14:22:33 pg_restore - table restoration options - odd behaivors.