Re: pgsql: Implement pg_wal_replay_wait() stored procedure
Alexander Korotkov <aekorotkov@gmail.com>
From: Alexander Korotkov <aekorotkov@gmail.com>
To: Pavel Borisov <pashkin.elfe@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>,
Michael Paquier <michael@paquier.xyz>, pgsql-committers@lists.postgresql.org
Date: 2024-10-22T20:12:27Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Revert pg_wal_replay_wait() stored procedure
- 3a7ae6b3d91e 18.0 landed
-
Add 'no_error' argument to pg_wal_replay_wait()
- e546989a269d 18.0 landed
-
Refactor WaitForLSNReplay() to return the result of waiting
- 73da6b8d1b3e 18.0 landed
-
Make WaitForLSNReplay() issue FATAL on postmaster death
- 6cfebfe88b9a 18.0 landed
-
Move LSN waiting declarations and definitions to better place
- 5035172e4ab5 18.0 landed
-
Update oid for pg_wal_replay_wait() procedure
- e658038772f5 18.0 landed
-
Move pg_wal_replay_wait() to xlogfuncs.c
- 014f9f34d252 18.0 landed
-
Implement pg_wal_replay_wait() stored procedure
- 3c5db1d6b016 18.0 cited
Attachments
- v6-0001-Move-LSN-waiting-declarations-and-definitions-to-.patch (application/octet-stream) patch v6-0001
- v6-0004-Add-no_error-argument-to-pg_wal_replay_wait.patch (application/octet-stream) patch v6-0004
- v6-0002-Make-WaitForLSNReplay-issue-FATAL-on-postmaster-d.patch (application/octet-stream) patch v6-0002
- v6-0003-Refactor-WaitForLSNReplay-to-return-the-result-of.patch (application/octet-stream) patch v6-0003
Hi, Pavel! Thank you for your review. On Tue, Oct 22, 2024 at 4:30 PM Pavel Borisov <pashkin.elfe@gmail.com> wrote: > On Tue, 22 Oct 2024 at 13:26, Alexander Korotkov <aekorotkov@gmail.com> wrote: >> >> On Wed, Oct 16, 2024 at 11:20 PM Alexander Korotkov >> <aekorotkov@gmail.com> wrote: >> > >> > On Wed, Oct 16, 2024 at 10:35 PM Peter Eisentraut <peter@eisentraut.org> wrote: >> > > On 02.09.24 01:55, Alexander Korotkov wrote: >> > > > On Mon, Sep 2, 2024 at 2:28 AM Michael Paquier <michael@paquier.xyz> wrote: >> > > >> On Sun, Sep 01, 2024 at 10:35:27PM +0300, Alexander Korotkov wrote: >> > > >>> This path hasn't changes since the patch revision when it was a >> > > >>> utility command. I agree that this doesn't look like proper path for >> > > >>> stored procedure. But I don't think src/backend/utils/adt is >> > > >>> appropriate path either, because it's not really about data type. >> > > >>> pg_wal_replay_wait() looks a good neighbor for >> > > >>> pg_wal_replay_pause()/pg_wal_replay_resume() and other WAL-related >> > > >>> functions. So, what about moving it to src/backend/access/transam? >> > > >> >> > > >> Moving the new function to xlogfuncs.c while publishing >> > > >> WaitForLSNReplay() makes sense to me. >> > > > >> > > > Thank you for proposal. I like this. >> > > > >> > > > Could you, please, check the attached patch? >> > > >> > > We still have stuff in src/backend/commands/waitlsn.c that is nothing >> > > like a "command". You have moved some stuff elsewhere, but what are you >> > > planning to do with the rest? >> > >> > Thank you for spotting this another time. What about moving that >> > somewhere like src/backend/access/transam/xlogwait.c ? >> >> Implemented this as a separate patch (0001). Also rebased other >> pending patches on that. 0004 now revises header comment of >> xlogwait.c with new procedure signature. > > > I've looked at v5 of a patchset. > > 0001: > Looks completely ok. > > 0002: > > As stated in latch.c > > - WL_POSTMASTER_DEATH: Wait for postmaster to die > - WL_EXIT_ON_PM_DEATH: Exit immediately if the postmaster dies > > * wakeEvents must include either WL_EXIT_ON_PM_DEATH for automatic exit > * if the postmaster dies or WL_POSTMASTER_DEATH for a flag set in the > * return value if the postmaster dies > > It's not completely clear to me if these comments need some clarification (not related to the patchset), or if we should look for WL_EXIT_ON_PM_DEATH for immediately FATAL. Or waiting for postmaster to die on WL_POSTMASTER_DEATH instead of just fatal immediately? As I get from the code, WL_EXIT_ON_PM_DEATH cause process to just proc_exit(1) without throwing FATAL. So, in the most of situations we do throw FATAL after seeing WL_POSTMASTER_DEATH event. So, it's reasonable to do the same here. But indeed, this is a question (not related to this patch) whether WL_EXIT_ON_PM_DEATH should cause process to throw FATAL. > 0003: > Besides refactor it looks that deleteLSNWaiter() is added in WaitForLSNReplay. Maybe it's worth mentioning in the commit message. > Maybe refactoring for loop for assigning result variable and breaking a loop instead of immediate return would look better and lead to natural call of after the loop before returning. I don't think we would get much simplicity/readability by breaking loop instead of immediate return. However, I reflected the changes in the commit message. Also I reflected that we don't distinguish any more seeing !RecoveryInProgress() in different places. > 0004: > > Comment: > + * Waits until recovery replays the target LSN with optional timeout. Throw > + * an error on failure. > may need mentioning "Unless no_error provided throws an error on failure" Changed as you proposed. > Otherwise the patch looks good. Thanks! ------ Regards, Alexander Korotkov Supabase