From: | Michael Paquier <michael(at)paquier(dot)xyz> |
---|---|
To: | Justin Pryzby <pryzby(at)telsasoft(dot)com> |
Cc: | Julien Rouhaud <rjuju123(at)gmail(dot)com>, Sergei Kornilov <sk(at)zsrv(dot)org>, Guillaume Lelarge <guillaume(at)lelarge(dot)info>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Expose lock group leader pid in pg_stat_activity |
Date: | 2020-03-16 06:02:31 |
Message-ID: | 20200316060231.GD2331@paquier.xyz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Suraj Kharage | 2020-03-16 06:03:23 | Re: backup manifests |
Previous Message | Justin Pryzby | 2020-03-16 05:43:41 | Re: Expose lock group leader pid in pg_stat_activity |