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

From Anna Akenteva
Subject Re: [HACKERS] make async slave to wait for lsn to be replayed
Date
Msg-id 06bfb1e542a25c3ebfc4232be4d49555@postgrespro.ru
Whole thread Raw
In response to Re: [HACKERS] make async slave to wait for lsn to be replayed  (Alexey Kondratov <a.kondratov@postgrespro.ru>)
Responses Re: [HACKERS] make async slave to wait for lsn to be replayed  (Alexander Korotkov <a.korotkov@postgrespro.ru>)
Re: [HACKERS] make async slave to wait for lsn to be replayed  (Kartyshov Ivan <i.kartyshov@postgrespro.ru>)
List pgsql-hackers
I did some code cleanup and added tests - both for the standalone WAIT 
FOR statement and for WAIT FOR as a part of BEGIN. The new patch is 
attached.

On 2020-04-03 17:29, Alexey Kondratov wrote:
> On 2020-04-01 02:26, Anna Akenteva wrote:
>> 
>> - WAIT FOR [ANY | ALL] event [, ...]
>> - BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ] [ WAIT FOR
>> [ANY | ALL] event [, ...]]
>> where event is one of:
>>     LSN value
>>     TIMEOUT number_of_milliseconds
>>     timestamp
>> 
>> Now, one event cannot contain both an LSN and a TIMEOUT.
>> 
> 
> In my understanding the whole idea of having TIMEOUT was to do
> something like 'Do wait for this LSN to be replicated, but no longer
> than TIMEOUT milliseconds'. What is the point of having plain TIMEOUT?
> It seems to be equivalent to pg_sleep, doesn't it?
> 

In the patch that I reviewed, you could do things like:
     WAIT FOR
         LSN lsn0,
         LSN lsn1 TIMEOUT time1,
         LSN lsn2 TIMEOUT time2;
and such a statement was in practice equivalent to
     WAIT FOR LSN(max(lsn0, lsn1, lsn2)) TIMEOUT (max(time1, time2))

As you can see, even though grammatically lsn1 is grouped with time1 and 
lsn2 is grouped with time2, both timeouts that we specified are not 
connected to their respective LSN-s, and instead they kinda act like 
global timeouts. Therefore, I didn't see a point in keeping TIMEOUT 
necessarily grammatically connected to LSN.

In the new syntax our statement would look like this:
     WAIT FOR LSN lsn0, LSN lsn1, LSN lsn2, TIMEOUT time1, TIMEOUT time2;
TIMEOUT-s are not forced to be grouped with LSN-s anymore, which makes 
it more clear that all specified TIMEOUTs will be global and will apply 
to all LSN-s at once.

The point of having TIMEOUT is still to let us limit the time of waiting 
for LSNs. It's just that with the new syntax, we can also use TIMEOUT 
without an LSN. You are right, such a case is equivalent to pg_sleep. 
One way to avoid that is to prohibit waiting for TIMEOUT without 
specifying an LSN. Do you think we should do that?

-- 
Anna Akenteva
Postgres Professional:
The Russian Postgres Company
http://www.postgrespro.com
Attachment

pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace onthe fly
Next
From: Andres Freund
Date:
Subject: Re: snapshot too old issues, first around wraparound and then more.