Re: system views for walsender activity

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Josh Berkus <josh(at)agliodbs(dot)com>, Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: system views for walsender activity
Date: 2011-01-13 17:43:35
Message-ID: AANLkTinMO-Cg-JbAOLthdtAGkyQFHuEPfuwuJxEFxz0k@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 13, 2011 at 11:08 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Wed, Jan 12, 2011 at 03:03, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> On Tue, Jan 11, 2011 at 7:24 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>>> No, do this at top
>>>>
>>>> if (walsnd->state == state)
>>>>  return;
>>>>
>>>> Keep spinlocks when actually setting it.
>>
>> I think this is safe...
>>
>>> Aha. Thanks for the pointers, pfa a new version.
>>
>> ...but I think you also need to take the spinlock when reading the value.
>
> Even when it can only ever be set by one process (the owning
> walsender), and the variable is atomic (as it should be, since it's a
> single enum/int)?

The fact that it can only be modified by one process makes it safe for
*that process* to read it without taking the lock, but another process
that wants to read it still needs the lock, I believe - otherwise you
might get a slightly stale value. That's probably not a *huge* deal
in this case, but I think it'd be better to get it right because
people tend to copy these sorts of things elsewhere, and it'd be bad
if it got copied into some place more critical.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2011-01-13 17:48:04 Re: pg_depend explained
Previous Message Bruce Momjian 2011-01-13 17:32:47 Re: C++ keywords in headers (was Re: [GENERAL] #include <funcapi.h>)