Re: Persist slot invalidations before publishing them

From: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(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-05 09:52:53
Message-ID: CAE9k0P=aea5vARHSEuDh5MRkUheqFHc_MV7CFgv96Ai8-Xuu3A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Sun, Oct 4, 2026 at 11:30 AM Bertrand Drouvot
<bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
>
> Hi,
>
> On Wed, Sep 30, 2026 at 03:50:30PM +0530, Ashutosh Sharma wrote:
> > Hi,
> >
> > On Mon, Sep 28, 2026 at 9:16 PM Bertrand Drouvot
> > <bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
> > >
> > > The patch needed a rebase, so at the same time I went ahead with the proposed
> > > changes above (plus the one in the commit message suggested by Rui in [1]).
> > >
> >
> > Thanks for reporting the problem and providing a patch for it. The
> > approach looks good to me, but I have a few comments to share:
>
> Thanks for looking at it!
>
> >
> > I think it would be good to add a comment above
> > InvalidatePossiblyObsoleteSlot() explaining the reason for this change
> > in the usual slot update pattern.
>
> What about something like?
>
> "
> Unlike normal replication slot updates, persist the invalidation before
> publishing it in shared memory. Publishing it first could allow resource
> horizon computations to remove resources required by the slot before the
> invalidation reaches disk. If saving then failed, a restart could restore
> the old valid slot. Keeping the shared slot valid until the invalidated
> image is durable avoids that state.
> "

Looks clear to me.

>
> >
> > 2)
> >
> > + {
> > + SaveSlotToPath(slot, path, ERROR, cause, clear_restart_lsn);
> > + }
> >
> > Do we need to pass clear_restart_lsn here? Cause can be used to
> > determine the restart lsn value later, no?
>
> I don't think so. InvalidatePossiblyObsoleteSlot() clears restart_lsn for
> RS_INVAL_WAL_REMOVED, while slotsync must preserve the local restart_lsn
> when copying the same invalidation cause. So the cause alone is not enough to
> determine the desired behavior.
>

Okay got it, then it does make sense to have this clear restart lsn flag.

> > 3)
> >
> > The current patch changes the interface for SaveSlotToPath() (), isn't
> > it possible to keep it unchanged, that would probably also reduce some
> > amount of complexity.
>
> Yeah, that seems worthwhile. I'll change it that way.
>

Thanks. I'll review again once the updated patch is posted.

--
With Regards,
Ashutosh Sharma.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexandre Felipe 2026-10-05 09:59:16 Re: WAL segment file descriptor leak on read errors can PANIC the server
Previous Message Hunaid Sohail 2026-10-05 09:39:47 Re: Proposal: SELECT * EXCLUDE (...) command