pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: Julien Rouhaud <rjuju123@gmail.com>
Cc: Sergei Kornilov <sk@zsrv.org>
Cc: Guillaume Lelarge <guillaume@lelarge.info>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Expose lock group leader pid in pg_stat_activity
Date: Mon, 16 Mar 2020 15:02:31 +0900
Message-ID: <20200316060231.GD2331@paquier.xyz> (raw)
In-Reply-To: <20200316054341.GG26184@telsasoft.com>
References: <20200116074912.GA98418@paquier.xyz>
	<CAOBaU_Z6WcT8FJfcCMU_Bp+PTzUpTEY9BfBQE4gbGKpE5wpfwQ@mail.gmail.com>
	<20200316042752.GE26184@telsasoft.com>
	<20200316054341.GG26184@telsasoft.com>

On Mon, Mar 16, 2020 at 12:43:41AM -0500, Justin Pryzby wrote:
> I think I see.  Julien's v3 patch did this:
> https://www.postgresql.org/message-id/attachment/106429/pgsa_leader_pid-v3.diff
> +				if (proc->lockGroupLeader)
> +					values[29] = Int32GetDatum(proc->lockGroupLeader->pid);
> 
> ..which is racy because a proc with a leader might die and be replaced by
> another proc without a leader between 1 and 2.
> 
> But the code since v4 does:
> 
> +				leader = proc->lockGroupLeader;
> +				if (leader)
> +                                       values[29] = Int32GetDatum(leader->pid);
> 
> ..which is safe because PROCs are allocated in shared memory, so leader is for
> sure a non-NULL pointer to a PROC.  leader->pid may be read inconsistently,
> which is what the comment says: "no extra lock is being held".

Yes, you have the correct answer here.  As shaped, the code relies on
the state of a PGPROC entry in shared memory.
--
Michael

Attachments:

  [application/pgp-signature] signature.asc (832B, ../20200316060231.GD2331@paquier.xyz/2-signature.asc)
  download

view thread (30+ messages)

Message-ID: <20200316060231.GD2331@paquier.xyz>
Permalink:  ../20200316060231.GD2331@paquier.xyz/
Also on:    postgresql.org/message-id/20200316060231.GD2331@paquier.xyz

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, pryzby@telsasoft.com, rjuju123@gmail.com, sk@zsrv.org, guillaume@lelarge.info, pgsql-hackers@lists.postgresql.org
  Subject: Re: Expose lock group leader pid in pg_stat_activity
  In-Reply-To: <20200316060231.GD2331@paquier.xyz>

* 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