Re: Implement waiting for wal lsn replay: reloaded

From: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
To: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Michael Paquier <michael(at)paquier(dot)xyz>, jian he <jian(dot)universality(at)gmail(dot)com>, Tomas Vondra <tomas(at)vondra(dot)me>, Yura Sokolov <y(dot)sokolov(at)postgrespro(dot)ru>
Subject: Re: Implement waiting for wal lsn replay: reloaded
Date: 2026-08-17 10:23:43
Message-ID: CAPpHfdvn-tE+He3TjHubsRUDPQNuBLHVV4Ghc6Tebej0XK_NhA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Aug 15, 2026 at 6:11 PM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
>
> On Sat, Aug 15, 2026 at 11:01 AM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
> >
> > On Sat, Aug 15, 2026 at 8:01 AM Alexander Korotkov <aekorotkov(at)gmail(dot)com> wrote:
> >
> > > The patchset looks good to me. I made some minor corrections.
> > >
> > > 0003 Removed extra check in WaitLSNCleanup() as deleteLSNWaiter()
> > > already does it.
> > > 0005 Improved comment about the situation on when LSN can go backwards.
> >
> > Thanks for the corrections! LGTM.
>
> + * This cannot spin. Once we are back in the heap, targetLSN is above
> + * the position we just read, so a waker can only remove us again
> + * after the position genuinely reaches the target, and then the check
> + * above ends the loop. The timeout and interrupt checks below are
> + * thus deferred by at most one iteration.
>
> After thinking more about this, it seems that repeated stale wakeups
> could turn this into spinning theoretically. I am not sure about the
> possibility of this in practice. But for cautiousness, does it make
> sense to reorder the re-registration and the timeout/interrupt
> checking?

Yes, this makes sense. I also think it's better to calculate delay_ms
just before WaitLatch().

> > For patch 0005, I was initially
> > hesitant to add a new test module because it may seem somewhat heavy
> > just to test this issue. I ended up adding it after realizing that it
> > could also be reused to test another, as-yet-unreported issue.
> >
> > I'm still wondering when it is appropriate to introduce a new test
> > module like this. I'm also not quite sure when a TAP test is warranted
> > instead of just providing a reproducer, since I spent a lot of time
> > designing this test. I'd like to hear your thoughts on them.

I think it's OK to introduce modules when test scenario can't be
reliably reached just with SQL queries. So, it must be eligible for
this case.

> > BTW, there are a few potential issues I've been investigating for a
> > while, but the fixes and constraints are still not entirely clear to
> > me, so I plan to send an off-list email about them later.

Sure, share what you have in mind off-list or on-list at your preferrence.

------
Regards,
Alexander Korotkov
Supabase

Attachment Content-Type Size
v8-0001-Add-wait-for-lsn-process-exit-cleanup-callback.patch application/octet-stream 3.5 KB
v8-0005-Re-register-LSN-waiters-after-stale-wakeups.patch application/octet-stream 15.2 KB
v8-0003-Avoid-locking-when-an-LSN-waiter-is-already-remov.patch application/octet-stream 2.7 KB
v8-0002-Fix-WAIT-FOR-LSN-documentation-examples.patch application/octet-stream 2.9 KB
v8-0004-Clarify-LSN-waiter-cleanup-after-wakeup.patch application/octet-stream 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2026-08-17 10:27:24 Re: MERGE/SPLIT PARTITIONS issues/questions
Previous Message Fujii Masao 2026-08-17 09:53:10 Re: Correct some doc items due to the REPACK