Re: recovery modules

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: recovery modules
Date: 2023-02-14 00:55:58
Message-ID: 20230214005558.GA1145703@nathanxps13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Feb 13, 2023 at 03:37:33PM -0800, Andres Freund wrote:
> On 2023-02-13 14:56:47 -0800, Nathan Bossart wrote:
>> On Mon, Feb 13, 2023 at 04:37:10PM +0900, Michael Paquier wrote:
>> > + basic_archive_context = data->context;
>> > + if (CurrentMemoryContext == basic_archive_context)
>> > + MemoryContextSwitchTo(TopMemoryContext);
>> > +
>> > + if (MemoryContextIsValid(basic_archive_context))
>> > + MemoryContextDelete(basic_archive_context);
>> >
>> > This is a bit confusing, because it means that we enter in the
>> > shutdown callback with one context, but exit it under
>> > TopMemoryContext. Are you sure that this will be OK when there could
>> > be multiple callbacks piled up with before_shmem_exit()? shmem_exit()
>> > has nothing specific to memory contexts.
>> Well, we can't free the memory context while we are in it, so we have to
>> switch to another one. I agree that this is a bit confusing, though.
> Why would we be in that memory context? I'd just add an assert documenting
> we're not.
>> On second thought, I'm not sure it's important to make sure the state is
>> freed in the shutdown callback. It's only called just before the archiver
>> process exits, so we're not really at risk of leaking anything. I suppose
>> we might not always restart the archiver in this case, but I also don't
>> anticipate that behavior changing in the near future. I think this
>> callback is more useful for things like shutting down background workers.
> I think it's crucial. Otherwise we're just ossifying the design that there's
> just one archive module active at a time.
>> I went ahead and removed the shutdown callback from basic_archive and the
>> note about leaking from the documentation.
> -1

Okay. I've added it back in v12 with the suggested adjustment for the
memory context stuff.

Nathan Bossart
Amazon Web Services:

Attachment Content-Type Size
v12-0001-restructure-archive-modules-API.patch text/x-diff 21.6 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-02-14 01:02:37 Re: recovery modules
Previous Message Andres Freund 2023-02-14 00:55:37 Re: pg_walinspect memory leaks