Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d2jEh-00060j-56 for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Apr 2017 19:01:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d2jEg-0006i8-HY for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Apr 2017 19:01:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d2jDB-000421-3j for pgsql-hackers@postgresql.org; Mon, 24 Apr 2017 18:59:49 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d2jD8-0004Nf-D5 for pgsql-hackers@postgresql.org; Mon, 24 Apr 2017 18:59:47 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id AD9EC2131F; Mon, 24 Apr 2017 14:59:45 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Mon, 24 Apr 2017 14:59:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=c8c6LtmvKHL7f1OP9K eiJecS92Gz6SlCmDTOny4thWA=; b=sBnlgESSy0qfIc6bVSye6MSMRQuGJgsWmM cxG/TLQV5hm/JBAoq5laXgeBrpkETyy2d/WHjavCgMatfMCHP17Pvpevvkf3+PyQ WjWhfnyW3a6EmwmrCoRqkEWSIS4zlpDUtH7N4L+cU8qrqJnBpkkn8bo4EvFbJivG qzGWL+3/TVKSJzp3X4h7CwaqhebyB0uUY6ulcSoTm5nD1Ugl6Bin6JDtbdDifzgw CBmCKNi1ILtG+6hQ+o5CNhEAGVr5JGfHQKjKuGVZ14ZLUhxQj/ge/+nC6onIQHV4 vyUKC3YaDr7s6rqNbU+2VLyuyfqRD7edDQaQQIhGCo/YRJw9DIWQ== X-ME-Sender: X-Sasl-enc: dJOkvRTsILZ4clubcB+MTEapWot2KFv7Lc+flZk/UYbL 1493060385 Received: from intern.anarazel.de (unknown [208.72.138.107]) by mail.messagingengine.com (Postfix) with ESMTPA id 1CC3B7E766; Mon, 24 Apr 2017 14:59:45 -0400 (EDT) Date: Mon, 24 Apr 2017 11:59:44 -0700 From: Andres Freund To: Simon Riggs Cc: Tom Lane , PostgreSQL-development Subject: Re: StandbyRecoverPreparedTransactions recovers subtrans links incorrectly Message-ID: <20170424185944.bjpb3yizeybv75hd@alap3.anarazel.de> References: <20110.1492905318@sss.pgh.pa.us> <20170423001931.wk4os4x6dwtdfwgd@alap3.anarazel.de> <20170423232504.o454vbowwvivkuyn@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2017-04-24 13:29:11 +0100, Simon Riggs wrote: > On 24 April 2017 at 00:25, Andres Freund 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