Re: SyncRepLock acquired exclusively in default configuration - Mailing list pgsql-hackers

From Masahiko Sawada
Subject Re: SyncRepLock acquired exclusively in default configuration
Date
Msg-id CA+fd4k5D7F-3j67zFGHj+-FB4=NKkamzU_-e7-Mmovpk_cGCGQ@mail.gmail.com
Whole thread Raw
In response to Re: SyncRepLock acquired exclusively in default configuration  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On Tue, 7 Apr 2020 at 06:14, Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
> On 2020-04-06 11:51:06 -0700, Ashwin Agrawal wrote:
> > On Mon, Apr 6, 2020 at 1:52 AM Masahiko Sawada <
> > masahiko.sawada@2ndquadrant.com> wrote:
> > > On Mon, 6 Apr 2020 at 14:04, Andres Freund <andres@anarazel.de> wrote:
> > > > I'm really not ok with unneccessarily adding an exclusive lock
> > > > acquisition to such a crucial path.
> > > >
> > >
> > > I think we can acquire SyncRepLock in share mode once to check
> > > WalSndCtl->sync_standbys_defined and if it's true then check it again
> > > after acquiring it in exclusive mode. But it in turn ends up with
> > > adding one extra LWLockAcquire and LWLockRelease in sync rep path.
>
> That's still too much. Adding another lwlock acquisition, where the same
> lock is acquired by all backends (contrasting e.g. to buffer locks), to
> the commit path, for the benefit of a feature that the vast majority of
> people aren't going to use, isn't good.

Agreed.

In this case it seems okay to read WalSndCtl->sync_standbys_defined
without SyncRepLock before we acquire SyncRepLock in exclusive mode.
While changing WalSndCtl->sync_standbys_defined to true, in the
current code a backend who reached SyncRepWaitForLSN() waits on
SyncRepLock, see sync_standbys_defined is true and enqueue itself.
With this change, since we don't acquire SyncRepLock to read
WalSndCtl->sync_standbys_defined these backends return without waiting
for the change of WalSndCtl->sync_standbys_defined but it would not be
a problem. Similarly, I've considered the case where changing to
false, but I think there is no problem.

Regards,

--
Masahiko Sawada            http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: PATCH: logical_work_mem and logical streaming of largein-progress transactions
Next
From: Andres Freund
Date:
Subject: Re: Catalog invalidations vs catalog scans vs ScanPgRelation()