From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Heikki Linnakangas <hlinnaka@iki.fi>
To: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Get rid of the dedicated latch for signaling the startup process
Date: Thu, 17 Dec 2020 18:17:54 +0900
Message-ID: <5dd3bbe0-3845-52d4-ce69-083102ba0094@oss.nttdata.com> (raw)
In-Reply-To: <ee9eeaec-a45f-f821-e0d6-fd3846c515ec@oss.nttdata.com>
References: <E1kaDSl-0001GJ-05@gemulon.postgresql.org>
<5c1f8a85-747c-7bf9-241e-dd467d8a3586@iki.fi>
<c50bee3b-f7b6-1052-c161-699ec83fdf85@oss.nttdata.com>
<d1260696-30a2-f386-633d-dafd6bc46bd9@oss.nttdata.com>
<b3265f23-f47c-6ab1-e0e7-2df0c3e4e9e1@iki.fi>
<3d3c42ca-c1bd-605d-71cf-8cd6353e895b@iki.fi>
<8f02685c-4029-c038-8bbb-99fe22d09379@oss.nttdata.com>
<ee9eeaec-a45f-f821-e0d6-fd3846c515ec@oss.nttdata.com>
On 2020/11/05 23:32, Fujii Masao wrote:
>
>
> On 2020/11/05 6:02, Fujii Masao wrote:
>>
>>
>> On 2020/11/05 5:36, Heikki Linnakangas wrote:
>>> On 04/11/2020 15:17, Heikki Linnakangas wrote:
>>>> On 04/11/2020 14:03, Fujii Masao wrote:
>>>>> Or ISTM that WakeupRecovery() should set the latch only when the latch
>>>>> has not been reset to NULL yet.
>>>>
>>>> Got to be careful with race conditions, if the latch is set to NULL at
>>>> the same time that WakeupRecovery() is called.
>>>
>>> I don't think commit 113d3591b8 got this quite right:
>>>
>>>> void
>>>> WakeupRecovery(void)
>>>> {
>>>> if (XLogCtl->recoveryWakeupLatch)
>>>> SetLatch(XLogCtl->recoveryWakeupLatch);
>>>> }
>>>
>>> If XLogCtl->recoveryWakeupLatch is set to NULL between the if and the SetLatch, you'll still get a segfault. That's highly unlikely to happen in practice because the compiler will optimize that into a single load instruction, but could happen with -O0. I think you'd need to do the access only once, using a volatile pointer, to make that safe.
>
> On second thought, since fetching the latch pointer might not be atomic,
> maybe we need to use spinlock like WalRcvForceReply() does. But using
> spinlock in every calls of WakeupRecovery() might cause performance
> overhead. So I'm thinking to use spinlock only when it's necessary, i.e.,
> when the latch may be reset to NULL concurrently. Attached is the POC
> patch implementing that. Thought?
Previously I added this patch to next CommitFest. But I reverted the commit
ac22929a26 and 113d3591b8 because those changes have other issue. So this
patch is no longer necessary, and I dropped it from next CommitFest.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: masao.fujii@oss.nttdata.com, hlinnaka@iki.fi, fujii@postgresql.org
Subject: Re: pgsql: Get rid of the dedicated latch for signaling the startup process
In-Reply-To: <5dd3bbe0-3845-52d4-ce69-083102ba0094@oss.nttdata.com>
References: <E1kaDSl-0001GJ-05@gemulon.postgresql.org> <5c1f8a85-747c-7bf9-241e-dd467d8a3586@iki.fi> <c50bee3b-f7b6-1052-c161-699ec83fdf85@oss.nttdata.com> <d1260696-30a2-f386-633d-dafd6bc46bd9@oss.nttdata.com> <b3265f23-f47c-6ab1-e0e7-2df0c3e4e9e1@iki.fi> <3d3c42ca-c1bd-605d-71cf-8cd6353e895b@iki.fi> <8f02685c-4029-c038-8bbb-99fe22d09379@oss.nttdata.com> <ee9eeaec-a45f-f821-e0d6-fd3846c515ec@oss.nttdata.com> <5dd3bbe0-3845-52d4-ce69-083102ba0094@oss.nttdata.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox