From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup.
Date: Tue, 19 Sep 2017 11:24:17 -0700
Message-ID: <20170919182417.mf7xalft7e7veddi@alap3.anarazel.de> (raw)
In-Reply-To: <19645.1505841328@sss.pgh.pa.us>
References: <20170918103213.nhlmfh5v3qrgoskg@alap3.anarazel.de>
<CA+TgmoYAPTmm1ZhvOb+iuJxsxWdXiO5LtcLFsMRQxHa8LpVxWA@mail.gmail.com>
<20170918180439.mgxvnbmxzb6br57t@alap3.anarazel.de>
<CA+TgmoZ+=ZMD9bBxJ2e42z1EGJYd9Zm+_g73Kn4CML6BU6bfRA@mail.gmail.com>
<20170919161012.i3j4ugktf2xkr4kb@alap3.anarazel.de>
<17513.1505838240@sss.pgh.pa.us>
<20170919165111.bsocu7ev2oaox4mx@alap3.anarazel.de>
<CA+TgmoZ=De8C4+MjY_DR5a7EnML=CO=_sNfm1PSK0tPsCUShSg@mail.gmail.com>
<20170919170821.drrwlt6wcoytlgup@alap3.anarazel.de>
<19645.1505841328@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 2017-09-19 13:15:28 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2017-09-19 13:00:33 -0400, Robert Haas wrote:
> >> You mean, in the postmaster?
>
> > Yes. We try to avoid touch shmem there, but it's not like we're
> > succeeding fully. See e.g. the pgstat_get_crashed_backend_activity()
> > calls (which do rely on shmem being ok to some extent), pmsignal,
> > BackgroundWorkerStateChange(), ...
>
> Well, the point is to avoid touching data structures that could be
> corrupted enough to confuse the postmaster. I don't have any problem with
> adding some more functionality to pmsignal, say.
Given that we're ok with reading pgstat shared memory entries, I think
adding a carefully coded variant of SendProcSignal() should be doable in
a safe manner.
Something roughly like
int
PostmasterSendProcSignal(pid_t pid, ProcSignalReason reason)
{
volatile ProcSignalSlot *slot;
/*
* As this is running in postmaster, be careful not to dereference
* any pointers from shared memory that could be corrupted, and to
* not to throw errors.
*/
for (i = 0; i < NumProcSignalSlots; i++)
{
slot = &ProcSignalSlots[i];
if (slot->pss_pid == pid)
{
/*
* The note about race conditions in SendProcSignal applies
* here, too
*/
/* Atomically set the proper flag */
slot->pss_signalFlags[reason] = true;
/* Send signal */
return kill(pid, SIGUSR1);
}
}
errno = ESRCH;
return -1;
}
As all the memory offsets are computed based on postmaster process-local
variables, this should be safe.
I'd rather like to avoid a copy of the procsignal infrastructure if we
don't need it...
Greetings,
Andres Freund
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
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: andres@anarazel.de, tgl@sss.pgh.pa.us, robertmhaas@gmail.com, pgsql-hackers@postgresql.org
Subject: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup.
In-Reply-To: <20170919182417.mf7xalft7e7veddi@alap3.anarazel.de>
References: <20170918103213.nhlmfh5v3qrgoskg@alap3.anarazel.de> <CA+TgmoYAPTmm1ZhvOb+iuJxsxWdXiO5LtcLFsMRQxHa8LpVxWA@mail.gmail.com> <20170918180439.mgxvnbmxzb6br57t@alap3.anarazel.de> <CA+TgmoZ+=ZMD9bBxJ2e42z1EGJYd9Zm+_g73Kn4CML6BU6bfRA@mail.gmail.com> <20170919161012.i3j4ugktf2xkr4kb@alap3.anarazel.de> <17513.1505838240@sss.pgh.pa.us> <20170919165111.bsocu7ev2oaox4mx@alap3.anarazel.de> <CA+TgmoZ=De8C4+MjY_DR5a7EnML=CO=_sNfm1PSK0tPsCUShSg@mail.gmail.com> <20170919170821.drrwlt6wcoytlgup@alap3.anarazel.de> <19645.1505841328@sss.pgh.pa.us> <20170919182417.mf7xalft7e7veddi@alap3.anarazel.de>
* 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