Re: Sending notifications from the master to the standby - Mailing list pgsql-hackers

From Joachim Wieland
Subject Re: Sending notifications from the master to the standby
Date
Msg-id CACw0+125_0X9yp6pGR3nOW_vrrbNd=U_Z4ex-MeqaXSDHNyBvg@mail.gmail.com
Whole thread Raw
In response to Re: Sending notifications from the master to the standby  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Sending notifications from the master to the standby
List pgsql-hackers
On Tue, Jan 10, 2012 at 11:55 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Simon Riggs <simon@2ndQuadrant.com> writes:
> [ Tom sketches a design ]
> Seems a bit overcomplicated.  I was just thinking of having walreceiver
> note the WAL endpoint at the instant of receipt of a notify message,
> and not release the notify message to the slave ring buffer until WAL
> replay has advanced that far.

How about this: We mark a notify message specially if it is the last
message sent by a transaction and also add a flag to
commit/abort-records, indicating whether or not the transaction has
sent notifys. Now if such a last message is being put into the regular
ring buffer on the standby and the xid is known to have committed or
aborted, signal the backends. Also signal from a commit/abort-record
if the flag is set.

If the notify messages make it to the standby first, we just put
messages of a not-yet-committed transaction into the queue, just as on
the master. Listeners will get signaled when the commit record
arrives. If the commit record arrives first, we signal, but the
listeners won't find anything (at least not the latest notifications).
When the last notify of that transaction finally arrives, the
transaction is known to have committed and the listeners will get
signaled.

What could still happen is that the standby receives notifys, the
commit message and more notifys. Listeners would still eventually get
all the messages but potentially not all of them at once. Is this a
problem? If so, then we could add a special "stop reading"-record into
the queue before we write the notifys, that we subsequently change
into a "continue reading"-record once all notifications are in the
queue. Readers would treat a "stop reading" record just like a
not-yet-committed transaction and ignore a "continue reading" record.


>> Suggest we add something to initial handshake from standby to say
>> "please send me notify traffic",
>
> +1 on that.

From what you said I imagined this walsender listener as a regular
listener that listens on the union of all sets of channels that
anybody is listening on on the standby, with the LISTEN transaction on
the standby return from commit once the listener is known to have been
set up on the master.


Joachim


pgsql-hackers by date:

Previous
From: Jan-Benedict Glaw
Date:
Subject: Re: pgsphere
Next
From: Euler Taveira de Oliveira
Date:
Subject: Re: log messages for archive recovery progress