Re: [HACKERS] make async slave to wait for lsn to be replayed

From: Anna Akenteva <a(dot)akenteva(at)postgrespro(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [HACKERS] make async slave to wait for lsn to be replayed
Date: 2020-03-21 10:51:13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2020-03-17 15:47, Kartyshov Ivan wrote:
> Synopsis
> ==========
> WAIT FOR [ANY | SOME | ALL] event [, event ...]
I'm confused as to what SOME would mean in this
command's syntax, but I can see you removed it
from gram.y since the last patch. Did you
decide to not implement it after all?

Also, I had a look at the code and tested it a bit.

If I specify many events, here's what happens:

For WAIT_FOR_ALL strategy, it chooses
- maximum LSN
- maximum delay
and waits for the resulting event.

For WAIT_FOR_ANY strategy - same, but it uses
minimal LSN/delay.

In other words, statements
LSN '7F97208' TIMEOUT 11,
LSN '3002808' TIMEOUT 50;
LSN '7F97208' TIMEOUT 11,
LSN '3002808' TIMEOUT 50;
are essentially equivalent to:
(1) WAIT FOR LSN '7F97208' TIMEOUT 50;
(2) WAIT FOR LSN '3002808' TIMEOUT 11;

It seems a bit counter-intuitive to me, because
I expected events to be treated independently.
Is this the expected behaviour?

In utility.c:
if (event->delay < time_val)
time_val = event->delay / 1000;

Since event->delay is an int, the result will
be zero for any delay value less than 1000.
I suggest either dividing by 1000.0 or
explicitly converting int to float.

Also, shouldn't event->delay be divided
by 1000 in the 'if' part as well?

You compare two LSN-s using pg_lsn_cmp():
res = DatumGetUInt32(
lsn, trg_lsn));

As far as I understand, it'd be enough to use
operators such as "<=", as you do in wait.c:
/* If LSN has been replayed */
if (trg_lsn <= cur_lsn)

Anna Akenteva
Postgres Professional:
The Russian Postgres Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2020-03-21 11:03:37 Re: GiST secondary split
Previous Message Nikita Glukhov 2020-03-21 10:07:35 Re: SQL/JSON: functions