| From: | Alexander Korotkov <aekorotkov(at)gmail(dot)com> |
|---|---|
| To: | Xuneng Zhou <xunengzhou(at)gmail(dot)com> |
| Cc: | Zsolt Parragi <zsolt(dot)parragi(at)percona(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-12-03 20:28:51 |
| Message-ID: | CAPpHfduxs46VJNuxnQdL7z7kSgPgWAN3v2TE75WEeoniDWNHdQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Xuneng,
Hi Zsolt,
On Thu, Nov 26, 2026 at 2:22 PM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
>
> 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.
I've checked the path. The documentation changes look good to me.
The calculations using page header sizes in tap tests look a bit
awkward to me, especially given those sizes aren't directly available.
I propose the following changes in v2.
* In sections 1, 3 and 7b-7d, the standby mode checks take the target
from pg_current_wal_flush_lsn() instead of
pg_current_wal_insert_lsn(). The commit is flushed by then, and the
flush LSN never points into a page header, so WAIT doesn't remap the
target and the checks stay exact.
* For primary_flush (sections 3 and 7e), the flush LSN would already
be reached, so the target is the return value of
pg_logical_emit_message(false, ..., false). That is the end of a
record that isn't flushed yet, so WAIT really has to wait, and a
record end never points into a page header.
* In section 11, if a frozen replay or flush position lands on a page
start, the test writes more WAL and freezes again. This replaces the
"+41" step, so current + 1 is always a real fencepost.
* Section 11d takes the target from pg_current_wal_flush_lsn(), as in
v1, with the comment moved next to that query.
* The wait_target_lsn() helper is removed, so the test doesn't need to
know page header sizes. Section 11e remains the only test of targets
past a page header.
------
Regards,
Alexander Korotkov
Supabase
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-WAIT-docs-and-tests-for-targets-past-a-WAL-pa.patch | application/octet-stream | 13.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David Rowley | 2026-12-03 20:58:40 | Re: Add sortsupport to money_ops, pg_lsn_ops and xid8_ops |
| Previous Message | Masahiko Sawada | 2026-12-03 20:25:38 | Re: Add a hook for handling logical decoding messages on subscribers. |