Re: [HACKERS] make async slave to wait for lsn to be replayed - Mailing list pgsql-hackers

From Kartyshov Ivan
Subject Re: [HACKERS] make async slave to wait for lsn to be replayed
Date
Msg-id 80f267591b373db5588d580fdfb432f0@postgrespro.ru
Whole thread Raw
Responses Re: [HACKERS] make async slave to wait for lsn to be replayed  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
List pgsql-hackers
On 2018-03-06 14:50, Simon Riggs wrote:
> On 6 March 2018 at 11:24, Dmitry Ivanov <d.ivanov@postgrespro.ru> 
> wrote:
>>> In PG11, I propose the following command, sticking mostly to Ants'
>>> syntax, and allowing to wait for multiple events before it returns. 
>>> It
>>> doesn't hold snapshot and will not get cancelled by Hot Standby.
>>> 
>>> WAIT FOR event [, event ...] options
>>> 
>>> event is
>>> LSN value
>>> TIMESTAMP value
>>> 
>>> options
>>> TIMEOUT delay
>>> UNTIL TIMESTAMP timestamp
>>> (we have both, so people don't need to do math, they can use 
>>> whichever
>>> they have)
>> 
>> 
>> I have a (possibly) dumb question: if we have specified several 
>> events,
>> should WAIT finish if only one of them triggered? It's not immediately
>> obvious if we're waiting for ALL of them to trigger, or just one will
>> suffice (ANY). IMO the syntax could be extended to something like:
>> 
>> WAIT FOR [ANY | ALL] event [, event ...] options,
>> 
>> with ANY being the default variant.
> 
> +1

Here I made new patch of feature, discussed above.

WAIT FOR - wait statement to pause beneath statements
==========

Synopsis
==========
     WAIT FOR [ANY | SOME | ALL] event [, event ...] options
     and event is:
         LSN value
         TIMESTAMP value

     and options is:
         TIMEOUT delay
         UNTIL TIMESTAMP timestamp
Description
==========
WAIT FOR - make to wait statements (that are beneath) on sleep until
event happens (Don’t process new queries until an event happens).

How to use it
==========
WAIT FOR LSN ‘LSN’ [, timeout in ms];

#Wait until LSN 0/303EC60 will be replayed, or 10 second passed.
WAIT FOR ANY LSN ‘0/303EC60’, TIMEOUT 10000;

#Or same without timeout.
WAIT FOR LSN ‘0/303EC60’;

#Or wait for some timestamp.
WAIT FOR TIMESTAMP '2020-01-02 17:20:19.028161+03';

#Wait until ALL events occur: LSN to be replayed and timestamp
passed.
WAIT FOR ALL LSN ‘0/303EC60’, TIMESTAMP '2020-01-28 11:10:39.021341+03';

Notice: WAIT FOR will release on PostmasterDeath or Interruption events
if they come earlier then LSN or timeout.

Testing the implementation
======================
The implementation was tested with src/test/recovery/t/018_waitfor.pl

-- 
Ivan Kartyshov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Attachment

pgsql-hackers by date:

Previous
From: Aleksei Ivanov
Date:
Subject: Re: Proposal: PqSendBuffer removal
Next
From: Sebastian Kemper
Date:
Subject: [PATCH] Make pkg-config files cross-compile friendly