Re: test: avoid redundant standby catchup in 049_wait_for_lsn

From: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
To: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
Cc: Alexander Korotkov <aekorotkov(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Jobin Augustine <jobin(dot)augustine(at)percona(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>
Subject: Re: test: avoid redundant standby catchup in 049_wait_for_lsn
Date: 2026-11-26 12:22:23
Message-ID: CABPTF7V3hej-2ZvPNkGMRsLPzjmdYzMA_CLBdqJ41qnokzATAw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Zsolt,

On Thu, Nov 26, 2026 at 5:41 PM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
>
> Hello
>
> CFBot reported a failure for my patch, but it turned out to be an
> unrelated failure in this [1]:
>
> 65/438 postgresql:recovery / recovery/049_wait_for_lsn
> ERROR 24.94s exit status 1
>
> # Failed test 'multiple primary_flush waiters: primary flushed WAL
> up to target LSN'
> # at .../src/test/recovery/t/049_wait_for_lsn.pl line 774.
>
> Seems like 049 can fail when the last record before one of its checks
> ends exactly at a WAL page boundary.
>
> The target there was 0/0301A014, the page start + the 20 byte short
> page header on 32-bit. WAIT maps it to 0/0301A000 and returns, but the
> check after it still compares pg_current_wal_flush_lsn() with the raw
> target, which no longer has to hold. Simple repro on a primary:
>
> SELECT pg_logical_emit_message(false, 'p', 'x', false);
> SELECT pg_switch_wal();
> SELECT pg_current_wal_insert_lsn() AS target \gset
> WAIT FOR LSN :'target' WITH (MODE 'primary_flush', timeout '3s', no_throw);
> SELECT pg_lsn_cmp(pg_current_wal_flush_lsn(), :'target');
>
> WAIT returns success, and the comparison returns -1.
>
> This seems like a direct consequence of the latest fix in 24723e7cf39:
> because of that, the code and the docs/tests disagree.
>
> The same assumption is in a few more places in the test. I/Claude made
> a modification that pads the WAL so a given statement ends exactly at
> a page boundary, and with that the following places also could fail on
> 64 bit:
>
> - the position checks after WAIT in sections 1, 3 and 7b-7e (7e is the
> cfbot failure)
> - 11d dies with "standby_write waiter did not register": the waiter
> registers the page start, and test_wait_lsn_waiter_is_registered()
> compares that with the raw target
> - if the frozen position in 11a/11b is at a page start, current + 1
> points into the header, so both "target == current + 1 times out"
> checks fail, and then 11c dies with "Boundary waiter did not sleep"
>
> And then I assumed that the current code behavior is intended, and the
> test and the documentation should be updated instead.
>
> The attached patch compares with the target the same way WAIT sees it
> in the checks. It uses a 40 byte bound everywhere, I didn't want to
> replicate the exact header sizes in perl.
>
> [1]: https://github.com/postgres/postgres-cfbot/actions/runs/45648478265/job/139326733557

The problem and analysis seem sound to me. Personally, I'm not quite
sure about the fix in the tests, though -- it kinda makes them
somewhat harder to understand. Exposing a new function like
pg_current_wal_insert_end_lsn() and making the tests use it (I
proposed earlier) seem simpler and more readable, at the cost of
introducing an additional function(maybe useful for itself). I am also
not sure if that's doable for v19.

--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2026-11-26 12:35:51 Re: reltuples kept decreasing with each autovacuum run Re: BUG #18773
Previous Message Tomas Vondra 2026-11-26 12:13:32 Re: Unify parallel worker handling for index builds and instrumentation