pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Simon Riggs <simon@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: StandbyRecoverPreparedTransactions recovers subtrans links incorrectly
Date: Mon, 24 Apr 2017 11:59:44 -0700
Message-ID: <20170424185944.bjpb3yizeybv75hd@alap3.anarazel.de> (raw)
In-Reply-To: <CANP8+j+vcrgv6-KaY_1bdgF7nE2G0r12c398g=7QyazVXem3xg@mail.gmail.com>
References: <20110.1492905318@sss.pgh.pa.us>
	<20170423001931.wk4os4x6dwtdfwgd@alap3.anarazel.de>
	<CANP8+jLy1VdopsdCi3c0=msJCfu-oHAhgPJgtKJ84fFN_8EmOw@mail.gmail.com>
	<20170423232504.o454vbowwvivkuyn@alap3.anarazel.de>
	<CANP8+j+vcrgv6-KaY_1bdgF7nE2G0r12c398g=7QyazVXem3xg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 2017-04-24 13:29:11 +0100, Simon Riggs wrote:
> On 24 April 2017 at 00:25, Andres Freund <andres@anarazel.de> wrote:
> > if the subxid->xid mapping doesn't actually exist - as it's the case
> > with this bug afaics - we'll not get the correct toplevel
> > transaction.
> 
> The nature of the corruption is that in some cases
> * a subxid will point to nothing (even though in most cases it was
> already set correctly)
> * the parent will point to a subxid

Right. Those cases aren't that different from the point of trying to
find the parent of an subxid.


> > Which'll mean the following block:
> >                 /*
> >                  * We now have either a top-level xid higher than xmin or an
> >                  * indeterminate xid. We don't know whether it's top level or subxact
> >                  * but it doesn't matter. If it's present, the xid is visible.
> >                  */
> >                 for (j = 0; j < snapshot->subxcnt; j++)
> >                 {
> >                         if (TransactionIdEquals(xid, snapshot->subxip[j]))
> >                                 return true;
> >                 }
> > won't work correctly if suboverflowed.
> 
> Your example of snapshots taken during recovery is not correct.

Oh?


> Note that SubTransGetTopmostTransaction() returns a valid, running
> xid, even though it is the wrong one.

Sure.


> Snapshots work differently on standbys - we store all known running
> xids, so the test still passes correctly, even when overflowed.

I don't think that's generally true.  Isn't that precisely what
ProcArrayStruct->lastOverflowedXid is about?  If we have a snapshot
that's suboverflowed due to the lastOverflowedXid cutoff, then we the
subxip array does *not* contain all known running xids anymore, we rely
on pg_subtrans to only guarantee that toplevel xids are stored in the
KnownAssignedXids machinery.

See:
 * When we throw away subXIDs from KnownAssignedXids, we need to keep track of
 * that, similarly to tracking overflow of a PGPROC's subxids array.  We do
 * that by remembering the lastOverflowedXID, ie the last thrown-away subXID.
 * As long as that is within the range of interesting XIDs, we have to assume
 * that subXIDs are missing from snapshots.  (Note that subXID overflow occurs
 * on primary when 65th subXID arrives, whereas on standby it occurs when 64th
 * subXID arrives - that is not an error.)

	/*
	 * Highest subxid that has been removed from KnownAssignedXids array to
	 * prevent overflow; or InvalidTransactionId if none.  We track this for
	 * similar reasons to tracking overflowing cached subxids in PGXACT
	 * entries.  Must hold exclusive ProcArrayLock to change this, and shared
	 * lock to read it.
	 */
	TransactionId lastOverflowedXid;


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



view thread (23+ messages)  latest in thread

Message-ID: <20170424185944.bjpb3yizeybv75hd@alap3.anarazel.de>
Permalink:  ../20170424185944.bjpb3yizeybv75hd@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20170424185944.bjpb3yizeybv75hd@alap3.anarazel.de

 · 

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 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-hackers@postgresql.org
  Cc: andres@anarazel.de, simon@2ndquadrant.com, tgl@sss.pgh.pa.us
  Subject: Re: StandbyRecoverPreparedTransactions recovers subtrans links incorrectly
  In-Reply-To: <20170424185944.bjpb3yizeybv75hd@alap3.anarazel.de>
  References: <20110.1492905318@sss.pgh.pa.us> <20170423001931.wk4os4x6dwtdfwgd@alap3.anarazel.de> <CANP8+jLy1VdopsdCi3c0=msJCfu-oHAhgPJgtKJ84fFN_8EmOw@mail.gmail.com> <20170423232504.o454vbowwvivkuyn@alap3.anarazel.de> <CANP8+j+vcrgv6-KaY_1bdgF7nE2G0r12c398g=7QyazVXem3xg@mail.gmail.com> <20170424185944.bjpb3yizeybv75hd@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