Re: Deduplicate code updating ControleFile's DBState. - Mailing list pgsql-hackers

From Amul Sul
Subject Re: Deduplicate code updating ControleFile's DBState.
Date
Msg-id CAAJ_b94bQa_PZeaKd+0NnBxhq=omPzw2+HYrX1MQD-SKB6w0zg@mail.gmail.com
Whole thread Raw
In response to Re: Deduplicate code updating ControleFile's DBState.  (Michael Paquier <michael@paquier.xyz>)
List pgsql-hackers
On Thu, Sep 16, 2021 at 5:17 AM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Wed, Sep 15, 2021 at 10:49:39PM +0000, Bossart, Nathan wrote:
> > Ah, I was missing this context.  Perhaps this should be included in
> > the patch set for the other thread, especially if it will need to be
> > exported.
>
> This part of the patch is mentioned at the top of the thread:
> -   LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
> -   ControlFile->state = DB_IN_PRODUCTION;
> -   ControlFile->time = (pg_time_t) time(NULL);
> -
> +   SetControlFileDBState(DB_IN_PRODUCTION);
>     SpinLockAcquire(&XLogCtl->info_lck);
>     XLogCtl->SharedRecoveryState = RECOVERY_STATE_DONE;
>     SpinLockRelease(&XLogCtl->info_lck);
>
> There is an assumption in this code to update SharedRecoveryState
> *while* holding ControlFileLock.  For example, see the following
> comment in xlog.c, ReadRecord():
> /*
>  * We update SharedRecoveryState while holding the lock on
>  * ControlFileLock so both states are consistent in shared
>  * memory.
>  */

Ok, understood, let's do that update with ControlFileLock, thanks.

Regards,
Amul



pgsql-hackers by date:

Previous
From: Kevin Burke
Date:
Subject: Coding guidelines for braces + spaces - link 404's
Next
From: Antonin Houska
Date:
Subject: Re: POC: Cleaning up orphaned files using undo logs