Re: Persist slot invalidations before publishing them

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>
Cc: shveta malik <shveta(dot)malik(at)gmail(dot)com>, JoongHyuk Shin <sjh910805(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Rui Zhao <zhaorui126(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Persist slot invalidations before publishing them
Date: 2026-10-06 13:46:24
Message-ID: asT7sGOzzQL/8hJl@bdtpg
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Tue, Oct 06, 2026 at 03:46:24PM +0530, Ashutosh Sharma wrote:
> Hi,
>
> On Mon, Oct 5, 2026 at 6:54 PM Bertrand Drouvot
> <bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
> >
> > Hi,
> >
> > On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote:
> > > Thanks. I'll review again once the updated patch is posted.
> >
> > Thanks! Here it is.
>
> Thanks, the attached patch looks good overall.

Thanks for looking at it!

> I only have a couple of
> concerns as of now, feel free to disregard them if you do not think
> they are worth addressing.
>
> 1) Although assertions are useful, some appear redundant across the
> three layers of the slot invalidation path:
>
> - cause != RS_INVAL_NONE is asserted in both
> ReplicationSlotPersistInvalidation() and SaveInvalidatedSlotToPath().
> - I/O lock ownership is asserted in those two functions and
> conditionally in SaveSlotToPathInternal().
> - The clear_restart_lsn constraint is asserted in both the public and
> internal functions.
> - cause == RS_INVAL_NONE || elevel >= ERROR is already guaranteed by
> the wrapper functions, since SaveInvalidatedSlotToPath() always passes
> ERROR.
>
> I think some of these assertions could be removed, particularly the
> following ones:
>
> static void
> SaveInvalidatedSlotToPath(ReplicationSlot *slot, const char *dir,
> ReplicationSlotInvalidationCause cause,
> bool clear_restart_lsn)
> {
> Assert(cause != RS_INVAL_NONE);
> Assert(LWLockHeldByMeInMode(&slot->io_in_progress_lock, LW_EXCLUSIVE));

I'm inclined to keep them. They check the preconditions at different layers.
There are similar caller/callee examples in the tree, for example:

SnapBuildSnapDecRefcount() / SnapBuildFreeSnapshot()
MemoryContextReset() / MemoryContextResetOnly()
MemoryContextDelete() / MemoryContextDeleteOnly()
SyncRepWakeQueue() / SyncRepQueueIsOrderedByLSN()

In particular, the cause assertion prevents RS_INVAL_NONE from reaching the regular
save path and trying to acquire the lock already held by the caller.

>
> 2) SaveSlotToPathInternal() currently has several conditional branches
> distinguishing between the normal-save and invalidation-save paths. It
> might be worth considering whether this distinction can be simplified,
> making the function easier to follow.

I replied to a similar suggestion from Shveta in [1].

> Other than these points, the current patch set looks good to me. I
> will spend some more time reviewing it and report back if I find
> anything else worth mentioning.

Thanks!

[1]: https://www.postgresql.org/message-id/asSkN5GOEOKQZs9w%40bdtpg

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-10-06 13:53:12 Re: Parallel Apply
Previous Message Fujii Masao 2026-10-06 13:30:21 Re: Incremental backups report progress as if they were full backups