pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Get rid of the dedicated latch for signaling the startup process
9+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2020-11-04 113d3591b8 Fix segmentation fault that commit ac22929a26 caused.
* pgsql: Get rid of the dedicated latch for signaling the startup process
@ 2020-11-04 07:44 Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
0 siblings, 1 reply; 9+ messages in thread
From: Fujii Masao @ 2020-11-04 07:44 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Get rid of the dedicated latch for signaling the startup process.
This commit gets rid of the dedicated latch for signaling the startup
process in favor of using its procLatch, since that comports better
with possible generic signal handlers using that latch.
Commit 1e53fe0e70 changed background processes so that they use standard
SIGHUP handler. Like that, this commit also makes the startup process use
standard SIGHUP handler to simplify the code.
Author: Fujii Masao
Reviewed-by: Bharath Rupireddy, Michael Paquier
Discussion: https://postgr.es/m/CALj2ACXPorUqePswDtOeM_s82v9RW32E1fYmOPZ5NuE+TWKj_A@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ac22929a2613e122708bd0172508ac863c51c1cc
Modified Files
--------------
src/backend/access/transam/xlog.c | 29 ++++++++++++++---------------
src/backend/postmaster/startup.c | 24 +++++-------------------
2 files changed, 19 insertions(+), 34 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
@ 2020-11-04 10:27 ` Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
0 siblings, 1 reply; 9+ messages in thread
From: Heikki Linnakangas @ 2020-11-04 10:27 UTC (permalink / raw)
To: Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
On 04/11/2020 09:44, Fujii Masao wrote:
> Get rid of the dedicated latch for signaling the startup process.
>
> This commit gets rid of the dedicated latch for signaling the startup
> process in favor of using its procLatch, since that comports better
> with possible generic signal handlers using that latch.
>
> Commit 1e53fe0e70 changed background processes so that they use standard
> SIGHUP handler. Like that, this commit also makes the startup process use
> standard SIGHUP handler to simplify the code.
This seems to have made buildfarm member 'elver' to segfault. I've got a
hunch that setting recoveryWakeupLatch to NULL, when WakeupRecovery()
doesn't check for NULL, is not OK. It's surprising that we're only
seeing this on 'elver', though.
- Heikki
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
@ 2020-11-04 11:20 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 12:03 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
0 siblings, 1 reply; 9+ messages in thread
From: Fujii Masao @ 2020-11-04 11:20 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnaka@iki.fi>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
On 2020/11/04 19:27, Heikki Linnakangas wrote:
> On 04/11/2020 09:44, Fujii Masao wrote:
>> Get rid of the dedicated latch for signaling the startup process.
>>
>> This commit gets rid of the dedicated latch for signaling the startup
>> process in favor of using its procLatch, since that comports better
>> with possible generic signal handlers using that latch.
>>
>> Commit 1e53fe0e70 changed background processes so that they use standard
>> SIGHUP handler. Like that, this commit also makes the startup process use
>> standard SIGHUP handler to simplify the code.
>
> This seems to have made buildfarm member 'elver' to segfault. I've got a hunch that setting recoveryWakeupLatch to NULL, when WakeupRecovery() doesn't check for NULL, is not OK. It's surprising that we're only seeing this on 'elver', though.
Thanks for the report! The latch is reset to NULL after ShutdownWalRcv(). So I thought that there are no processes setting the latch (i.e., walreceiver has already exited) after it's reset to NULL. But this is not true. There seem a window between ShutdownWalRcv() and the actual exit of walreceiver. If a signal is sent during that window, the segmentation fault would happen. This would be the reason why segv happened in some platforms, but not in others.
I'm thinking to remove the following code to fix this issue. Thought?
/*
* We don't need the latch anymore. It's not strictly necessary to reset
* it to NULL, but let's do it for the sake of tidiness.
*/
if (ArchiveRecoveryRequested)
XLogCtl->recoveryWakeupLatch = NULL;
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
@ 2020-11-04 12:03 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 13:17 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
0 siblings, 1 reply; 9+ messages in thread
From: Fujii Masao @ 2020-11-04 12:03 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnaka@iki.fi>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
On 2020/11/04 20:20, Fujii Masao wrote:
>
>
> On 2020/11/04 19:27, Heikki Linnakangas wrote:
>> On 04/11/2020 09:44, Fujii Masao wrote:
>>> Get rid of the dedicated latch for signaling the startup process.
>>>
>>> This commit gets rid of the dedicated latch for signaling the startup
>>> process in favor of using its procLatch, since that comports better
>>> with possible generic signal handlers using that latch.
>>>
>>> Commit 1e53fe0e70 changed background processes so that they use standard
>>> SIGHUP handler. Like that, this commit also makes the startup process use
>>> standard SIGHUP handler to simplify the code.
>>
>> This seems to have made buildfarm member 'elver' to segfault. I've got a hunch that setting recoveryWakeupLatch to NULL, when WakeupRecovery() doesn't check for NULL, is not OK. It's surprising that we're only seeing this on 'elver', though.
>
> Thanks for the report! The latch is reset to NULL after ShutdownWalRcv(). So I thought that there are no processes setting the latch (i.e., walreceiver has already exited) after it's reset to NULL. But this is not true. There seem a window between ShutdownWalRcv() and the actual exit of walreceiver. If a signal is sent during that window, the segmentation fault would happen. This would be the reason why segv happened in some platforms, but not in others.
>
> I'm thinking to remove the following code to fix this issue. Thought?
>
> /*
> * We don't need the latch anymore. It's not strictly necessary to reset
> * it to NULL, but let's do it for the sake of tidiness.
> */
> if (ArchiveRecoveryRequested)
> XLogCtl->recoveryWakeupLatch = NULL;
Or ISTM that WakeupRecovery() should set the latch only when the latch
has not been reset to NULL yet.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 12:03 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
@ 2020-11-04 13:17 ` Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 20:36 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
0 siblings, 1 reply; 9+ messages in thread
From: Heikki Linnakangas @ 2020-11-04 13:17 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@oss.nttdata.com>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
On 04/11/2020 14:03, Fujii Masao wrote:
>> I'm thinking to remove the following code to fix this issue. Thought?
>>
>> /*
>> * We don't need the latch anymore. It's not strictly necessary to reset
>> * it to NULL, but let's do it for the sake of tidiness.
>> */
>> if (ArchiveRecoveryRequested)
>> XLogCtl->recoveryWakeupLatch = NULL;
That should work, but it seems a bit sloppy to leave it pointing to a
latch that belongs to a random process though.
> 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.
- Heikki
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 12:03 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 13:17 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
@ 2020-11-04 20:36 ` Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 21:02 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
0 siblings, 1 reply; 9+ messages in thread
From: Heikki Linnakangas @ 2020-11-04 20:36 UTC (permalink / raw)
To: Fujii Masao <masao.fujii@oss.nttdata.com>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
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. Maybe
it's simpler to just not reset it to NULL, after all.
- Heikki
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 12:03 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 13:17 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 20:36 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
@ 2020-11-04 21:02 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-05 14:32 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
0 siblings, 1 reply; 9+ messages in thread
From: Fujii Masao @ 2020-11-04 21:02 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnaka@iki.fi>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
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. Maybe it's simpler to just not reset it to NULL, after all.
Yes, you're right. I agree it's simpler to remove the code resetting
the latch to NULL. Also as the comment for that code explains,
basically it's not necessary to reset it to NULL.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 12:03 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 13:17 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 20:36 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 21:02 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
@ 2020-11-05 14:32 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-12-17 09:17 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
0 siblings, 1 reply; 9+ messages in thread
From: Fujii Masao @ 2020-11-05 14:32 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnaka@iki.fi>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
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?
> Maybe it's simpler to just not reset it to NULL, after all.
>
> Yes, you're right. I agree it's simpler to remove the code resetting
> the latch to NULL. Also as the comment for that code explains,
> basically it's not necessary to reset it to NULL.
On second thought, your comment in upthread "it seems a bit sloppy to
leave it pointing to a latch that belongs to a random process though."
seems right. So I'm inclined to avoid this approach, for now.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Attachments:
fix_possible_segfault_v1.patch (text/plain, 3.1K) download
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a1078a7cfc..fc8ae318fd 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7488,11 +7488,15 @@ StartupXLOG(void)
ResetUnloggedRelations(UNLOGGED_RELATION_INIT);
/*
- * We don't need the latch anymore. It's not strictly necessary to reset
- * it to NULL, but let's do it for the sake of tidiness.
+ * Reset recoveryWakeupLatch to NULL to prevent us from leaving it
+ * pointing to the latch that might belong to other process later.
*/
if (ArchiveRecoveryRequested)
+ {
+ SpinLockAcquire(&XLogCtl->info_lck);
XLogCtl->recoveryWakeupLatch = NULL;
+ SpinLockRelease(&XLogCtl->info_lck);
+ }
/*
* We are now done reading the xlog from stream. Turn off streaming
@@ -12669,12 +12673,24 @@ CheckPromoteSignal(void)
/*
* Wake up startup process to replay newly arrived WAL, or to notice that
* failover has been requested.
+ *
+ * use_lock: if true, acquire spinlock to fetch the latch pointer. This
+ * should be true if walreceiver has already been marked as inactive.
+ * Because the startup process might reset the latch to NULL concurrently
+ * in that case.
*/
void
-WakeupRecovery(void)
+WakeupRecovery(bool use_lock)
{
- if (XLogCtl->recoveryWakeupLatch)
- SetLatch(XLogCtl->recoveryWakeupLatch);
+ Latch *latch;
+
+ if (use_lock)
+ SpinLockAcquire(&XLogCtl->info_lck);
+ latch = XLogCtl->recoveryWakeupLatch;
+ if (use_lock)
+ SpinLockRelease(&XLogCtl->info_lck);
+ if (latch)
+ SetLatch(latch);
}
/*
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index bb1d44ccb7..c89757ec69 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -666,7 +666,7 @@ WalRcvWaitForStartPosition(XLogRecPtr *startpoint, TimeLineID *startpointTLI)
* nudge startup process to notice that we've stopped streaming and are
* now waiting for instructions.
*/
- WakeupRecovery();
+ WakeupRecovery(false);
for (;;)
{
ResetLatch(walrcv->latch);
@@ -803,7 +803,7 @@ WalRcvDie(int code, Datum arg)
walrcv_disconnect(wrconn);
/* Wake up the startup process to notice promptly that we're gone */
- WakeupRecovery();
+ WakeupRecovery(true);
}
/* SIGHUP: set flag to re-read config file at next convenient time */
@@ -1025,7 +1025,7 @@ XLogWalRcvFlush(bool dying)
SpinLockRelease(&walrcv->mutex);
/* Signal the startup process and walsender that new WAL has arrived */
- WakeupRecovery();
+ WakeupRecovery(false);
if (AllowCascadeReplication())
WalSndWakeup();
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 221af87e71..43cd047250 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -343,7 +343,7 @@ extern void RemovePromoteSignalFiles(void);
extern bool PromoteIsTriggered(void);
extern bool CheckPromoteSignal(void);
-extern void WakeupRecovery(void);
+extern void WakeupRecovery(bool use_lock);
extern void SetWalWriterSleeping(bool sleeping);
extern void StartupRequestWalReceiverRestart(void);
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Get rid of the dedicated latch for signaling the startup process
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 12:03 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 13:17 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 20:36 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 21:02 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-05 14:32 ` Re: pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <masao.fujii@oss.nttdata.com>
@ 2020-12-17 09:17 ` Fujii Masao <masao.fujii@oss.nttdata.com>
0 siblings, 0 replies; 9+ messages in thread
From: Fujii Masao @ 2020-12-17 09:17 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnaka@iki.fi>; Fujii Masao <fujii@postgresql.org>; pgsql-committers@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2020-12-17 09:17 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04 07:44 pgsql: Get rid of the dedicated latch for signaling the startup process Fujii Masao <fujii@postgresql.org>
2020-11-04 10:27 ` Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 11:20 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 12:03 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-04 13:17 ` Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 20:36 ` Heikki Linnakangas <hlinnaka@iki.fi>
2020-11-04 21:02 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-11-05 14:32 ` Fujii Masao <masao.fujii@oss.nttdata.com>
2020-12-17 09:17 ` Fujii Masao <masao.fujii@oss.nttdata.com>
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