Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 024449066CF for ; Thu, 7 Jun 2012 13:49:59 -0300 (ADT) Received: from moutng.kundenserver.de ([212.227.17.10]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ScfuH-0007zZ-K4 for pgsql-bugs@postgresql.org; Thu, 07 Jun 2012 16:49:59 +0000 Received: from awork2.localnet (p5DDC51F4.dip.t-dialin.net [93.220.81.244]) by mrelayeu.kundenserver.de (node=mrbap4) with ESMTP (Nemesis) id 0LnBin-1S2UXq3uO5-00gxzx; Thu, 07 Jun 2012 18:49:44 +0200 From: Andres Freund Organization: 2ndquadrant.com To: pgsql-bugs@postgresql.org Subject: Re: BUG #6661: out-of-order XID insertion in KnownAssignedXids Date: Thu, 7 Jun 2012 18:49:42 +0200 User-Agent: KMail/1.13.7 (Linux/3.4.0-andres; KDE/4.7.4; x86_64; ; ) Cc: Valentine Gogichashvili , Simon Riggs References: <201206071558.24877.andres@2ndquadrant.com> In-Reply-To: <201206071558.24877.andres@2ndquadrant.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_muN0P9hCt3LQSqA" Message-Id: <201206071849.42655.andres@2ndquadrant.com> X-Provags-ID: V02:K0:xidVyhAb3sntqO79SPYWliJhlXqpxaY8n1ZDf72s7z2 z1Eujz9ZvafGYmfr9d8cbRZ8nR1xfmew1orhCVW9YLH6ymkYdU bU/JESSlNBIZxAdHbr6ncU5JcQeV5f5NHgOep691OX4BlonuxY nvkSKqCH7xunAbDBTxx+rumwhrCcPXtGEYY4bDnl9SOP4W0LxJ 9Iw87MajKpV+T16B9dC6ygO34MH+Y3qkjcYZs0470ujBFnO/Na 4uK+TnbTaBbhxIO1UaJ1tB7g1cuAGI+nAxa2kCWJyNSwzDjoZR xnU5F9q8D9tYAUDp0mPtSMOY3g89KDZQVPKN34NshtKLVt3Vlb MKRr76P0Np1ZIrXSc+5ARKp0fLPgs4w5WtJZI5kfgOIXsuaGtM sHVazQGIV12rw== X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/54 X-Sequence-Number: 33281 --Boundary-00=_muN0P9hCt3LQSqA Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit On Thursday, June 07, 2012 03:58:24 PM Andres Freund wrote: > Hi, > > On Thursday, June 07, 2012 12:44:08 PM Valentine Gogichashvili wrote: > > I have the situation again, one of 3 slaves was slow to play all the WAL > > files and being about 10GB late it crashed with the same error again. > > > > I collected DEBUG4 output in this time: > > https://docs.google.com/open?id=0B2NMMrfiBQcLZjNDbU0xQ3lvWms > > Ok, I stared at this some time and I think I see what the problem is. Some > log excerpts that lead my reasoning: > ... > after that we start adding all currently running xids from the snapshot to > the KnownAssigned machinery. They are already recorded though, so we fail > in KnownAssignedXidsAdd with the OPs error. > > The simplest fix for that seems to be to simply reset the KnownAssignedXids > state in the above branch. Any arguments against that? A patch implementing that is attached. Unfortunately not really tested yet because its kinda hard to hit that code-path. Valentine, can you test that patch? Andres -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --Boundary-00=_muN0P9hCt3LQSqA Content-Type: text/x-patch; charset="UTF-8"; name="0001-Fix-a-bug-in-the-assembly-of-recovery-snapshots-in-H.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Fix-a-bug-in-the-assembly-of-recovery-snapshots-in-H.patch" =46rom 91c6b4195233c5dfeb794b983c97cef61d966e1b Mon Sep 17 00:00:00 2001 =46rom: Andres Freund Date: Thu, 7 Jun 2012 18:38:32 +0200 Subject: [PATCH] Fix a bug in the assembly of recovery snapshots in Hot Standby We previously failed if we read a non-overflowed snapshot after starting to incrementally assemble a snapshot after reading an overflowed one. Code add= ed in 10b7c686e52a6d1bb10194ebf9331ef06f044d46 added a fallback in that case to simply build a completely new snapshot if we have the necessary information= but forgot to cleanup the partial incremental one. Add and use a KnownAssignedXidsReset function for that. =2D-- src/backend/storage/ipc/procarray.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/= procarray.c index 26469c4..25bfefc 100644 =2D-- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -160,6 +160,7 @@ static int KnownAssignedXidsGetAndSetXmin(TransactionId= *xarray, TransactionId xmax); static TransactionId KnownAssignedXidsGetOldestXmin(void); static void KnownAssignedXidsDisplay(int trace_level); +static void KnownAssignedXidsReset(void); =20 /* * Report shared-memory space needed by CreateSharedProcArray. @@ -526,6 +527,11 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running) */ if (!running->subxid_overflow || running->xcnt =3D=3D 0) { + /* + * we already may have collected assigned xids, we need to throw + * that knowledge away to apply the recovery snapshot. + */ + KnownAssignedXidsReset(); standbyState =3D STANDBY_INITIALIZED; } else @@ -569,7 +575,8 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running) * xids to subtrans. If RunningXacts is overflowed then we don't have * enough information to correctly update subtrans anyway. */ =2D Assert(procArray->numKnownAssignedXids =3D=3D 0); + if(procArray->numKnownAssignedXids !=3D 0) + elog(ERROR, "the KnownAssignedXids machinery cannot be initialized when = applying a full recovery snapshot"); =20 /* * Allocate a temporary array to avoid modifying the array passed as @@ -3340,3 +3347,22 @@ KnownAssignedXidsDisplay(int trace_level) =20 pfree(buf.data); } + +/* + * KnownAssignedXidsReset + * Resets KnownAssignedXids to be empty + */ +static void +KnownAssignedXidsReset(void) +{ + /* use volatile pointer to prevent code rearrangement */ + volatile ProcArrayStruct *pArray =3D procArray; + + LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE); + + pArray->numKnownAssignedXids =3D 0; + pArray->tailKnownAssignedXids =3D 0; + pArray->headKnownAssignedXids =3D 0; + + LWLockRelease(ProcArrayLock); +} =2D-=20 1.7.10.rc3.3.g19a6c.dirty --Boundary-00=_muN0P9hCt3LQSqA--