pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Simon Riggs <simon@2ndQuadrant.com>
To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [COMMITTERS] pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop
Date: Mon, 19 Apr 2010 09:05:32 +0100
Message-ID: <1271664332.8305.17430.camel@ebony> (raw)
In-Reply-To: <4BCC07F1.6040405@enterprisedb.com>
References: <20100418180608.16F067541D1@cvs.postgresql.org>
	<4BCC07F1.6040405@enterprisedb.com>

On Mon, 2010-04-19 at 10:36 +0300, Heikki Linnakangas wrote:
> Simon Riggs wrote:
> > Log Message:
> > -----------
> > Tune GetSnapshotData() during Hot Standby by avoiding loop
> > through normal backends. Makes code clearer also, since we
> > avoid various Assert()s. Performance of snapshots taken
> > during recovery no longer depends upon number of read-only
> > backends.
> 
> I think there's a little race condition there.
> snapshot->takenDuringRecovery is set before acquiring ProcArrayLock, so
> it's possible that by the time we acquire the lock, we're no longer in
> recovery. So this can happen:
> 
> 1. Backend A starts to take a snapshot, while we're still in recovery.
> takenDuringRecovery is assigned true.
> 2. Recovery ends, and a normal transaction X begins in backend B.
> 3. A skips scanning ProcArray because takenDuringRecovery is true.
> 
> The snapshot doesn't include X, so any changes done in that transaction
> will not be visible to the snapshot while the transaction is still
> running, but will be after it commits.
> 
> Of course, it's highly improbable for 2. to happen, but it's there.

The order of events is as you say, though I don't see the problem. The
new xids will be beyond xmax and would be filtered out even if we did
scan the procs, so they will be treated as running, which they are. Xmax
will not have advanced since that relies on completed transactions, not
started ones.

-- 
 Simon Riggs           www.2ndQuadrant.com




view thread (12+ messages)  latest in thread

Message-ID: <1271664332.8305.17430.camel@ebony>
Permalink:  ../1271664332.8305.17430.camel@ebony/
Also on:    postgresql.org/message-id/1271664332.8305.17430.camel@ebony

 · 

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: simon@2ndQuadrant.com, heikki.linnakangas@enterprisedb.com
  Subject: Re: [COMMITTERS] pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop
  In-Reply-To: <1271664332.8305.17430.camel@ebony>

* 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