Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W0oi3-0002rt-1O for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jan 2014 08:41:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W0oi2-0007Gv-HR for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jan 2014 08:41:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W0oi1-0007Go-G2 for pgsql-bugs@postgresql.org; Wed, 08 Jan 2014 08:41:53 +0000 Received: from mail12.ics.ntts.co.jp ([210.232.35.65]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W0ohx-0003VK-OH for pgsql-bugs@postgresql.org; Wed, 08 Jan 2014 08:41:53 +0000 Received: from sadoku34.silk.ntts.co.jp (sadoku34 [10.7.18.34]) by mail12.ics.ntts.co.jp (8.14.4/8.14.4/NTTSOFT) with ESMTP id s088fh0P004232; Wed, 8 Jan 2014 17:41:44 +0900 (JST) Received: (from root@localhost) by sadoku34.silk.ntts.co.jp (8.13.8/NTTSOFT) id s088fhJU016988; Wed, 8 Jan 2014 17:41:43 +0900 (JST) Received: from ccmds32.silk.ntts.co.jp [10.107.0.32] by sadoku34.silk.ntts.co.jp with SMTP id TAA16987; Wed, 8 Jan 2014 17:41:43 +0900 Received: from mail147.silk.ntts.co.jp (ccmds32.silk.ntts.co.jp [127.0.0.1]) by ccmds32.silk.ntts.co.jp (8.14.3/8.14.3) with ESMTP id s088fhBl006629; Wed, 8 Jan 2014 17:41:43 +0900 Received: from mail147.silk.ntts.co.jp (localhost.localdomain [127.0.0.1]) by mail147.silk.ntts.co.jp (8.14.5/8.14.5/NTTSOFT) with ESMTP id s088fWof030954; Wed, 8 Jan 2014 17:41:32 +0900 Received: from ccmds32 (mail145.silk.ntts.co.jp [10.107.0.145]) by mail147.silk.ntts.co.jp (8.14.5/8.14.5/NTTSOFT) with SMTP id s088fWlR030951; Wed, 8 Jan 2014 17:41:32 +0900 Message-ID: <52CD0F39.6000403@po.ntts.co.jp> Date: Wed, 08 Jan 2014 17:41:29 +0900 From: Tomonari Katsumata User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Heikki Linnakangas , Tomonari Katsumata CC: pgsql-bugs@postgresql.org Subject: Re: BUG #8686: Standby could not restart. References: <52B46D0D.2070505@vmware.com> <52CABFD8.8090101@vmware.com> In-Reply-To: <52CABFD8.8090101@vmware.com> Content-Type: multipart/mixed; boundary="------------010509020300050007080804" X-CC-Mail-RelayStamp: CC-Mail-V4.3-Client X-CC-Mail-RelayStamp: CC-Mail-V4.3-Server X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------010509020300050007080804 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by ccmds32.silk.ntts.co.jp id s088fhBl006629 Hi Heikki, Sorry for slow response and thank you for new patch! I've tried your patch, but the patch was not for 92_STABLE. So I created a patch for 92_STABLE(*) from your patch. (*)against 8aa6912b8fec3400441c365bde6a1030295de749 It worked fine! If there are no problem, please commit this patch also to 92_STABLE. NOTE: I think your original patch has a miss typing. We should use 'checkPoint' not 'checkpoint'. ----------------------------------------------------------- 24=EF=BC=9A+ xlogctl->replayEndRecPtr =3D checkpoint.redo; 27=EF=BC=9A+ xlogctl->lastReplayedEndRecPtr =3D checkpoint.redo; 24=EF=BC=9A+ xlogctl->replayEndRecPtr =3D checkPoint.redo; 27=EF=BC=9A+ xlogctl->lastReplayedEndRecPtr =3D checkPoint.redo; ----------------------------------------------------------- regards, ------------- Tomonari Katsumata (2014/01/06 23:38), Heikki Linnakangas wrote: > On 12/23/2013 08:15 AM, Tomonari Katsumata wrote: >>> /* >>>> * Initialize shared replayEndRecPtr, >>>> lastReplayedEndRecPtr, and >>>> * recoveryLastXTime. >>>> * >>>> * This is slightly confusing if we're starting from an >>>> online >>>> * checkpoint; we've just read and replayed the >>>> checkpoint record, but >>>> * we're going to start replay from its redo pointer, >>>> which precedes >>>> * the location of the checkpoint record itself. So even >>>> though the >>>> * last record we've replayed is indeed ReadRecPtr, we >>>> haven't >>>> * replayed all the preceding records yet. That's OK for >>>> the current >>>> * use of these variables. >>>> */ >>>> SpinLockAcquire(&xlogctl->info_lck); >>>> xlogctl->replayEndRecPtr =3D ReadRecPtr; >>>> xlogctl->lastReplayedEndRecPtr =3D EndRecPtr; >>>> xlogctl->recoveryLastXTime =3D 0; >>>> xlogctl->currentChunkStartTime =3D 0; >>>> xlogctl->recoveryPause =3D false; >>>> SpinLockRelease(&xlogctl->info_lck); >>> >>> I think we need to fix that confusion. Your patch will do it by not >>> setting EndRecPtr yet; that fixes the bug, but leaves those=20 variables in a >>> slightly strange state; I'm not sure what EndRecPtr points to in=20 that case >>> (0 ?), but ReadRecPtr would be set I guess. >> Yes, the values were set like below. >> ReadRecPtr:1/8E7F0B0 >> EndRecPtr:0/0 >> >> >>> >>> Perhaps we should reset replayEndRecPtr and lastReplayedEndRecPtr=20 to the >>> REDO point here, instead of ReadRecPtr/EndRecPtr. >> >> I made another patch. >> I added a ReadRecord to make sure the REDO location is present or not. >> The similar process are done when we use backup_label. >> >> Because the ReadRecord returns a record already read, >> I set ReadRecPtr of the record to EndRecPtr. >> And also I set record->xl_prev to ReadRecPtr. >> As you said, it also worked fine. >> >> I'm not sure we should do same thing when crash recovery occurs, but=20 now I >> added the process when archive recovery is needed. >> >> Please see attached patch. > > Hmm. That would still initialize lastReplayedEndRecPtr to the=20 checkpoint record, when you do crash recovery (or begin archive recovery=20 from a filesystem snapshot, where you perform crash recovery before=20 starting to read the archive). I'm not very comfortable with that, even=20 though I don't see an immediate problem with it. > > I also noticed that CheckRecoveryConsistency() compares=20 backupEndPoint with EndRecPtr, but minRecoveryPoint with=20 lastReplayedEndRecPtr. That's correct as the code stands, but it's an=20 accident waiting to happen: if you called CheckRecoveryConsistency()=20 after reading a record with ReadRecord(), but before fully replaying it,=20 it might conclude that it's reached the backup end location one record=20 too early. And it's inconsistent, anyway. > > I propose the attached patch. I haven't tested it, but I think it's a=20 slightly more robust fix. > > - Heikki > > --------------010509020300050007080804 Content-Type: text/x-patch; name="fix-lastReplayedEndRecPtr-1_for92stable.patch" Content-Disposition: attachment; filename="fix-lastReplayedEndRecPtr-1_for92stable.patch" Content-Transfer-Encoding: 7bit diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 1e8bb8b..2a2e35c 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6750,20 +6750,12 @@ StartupXLOG(void) } /* - * Initialize shared replayEndRecPtr, lastReplayedEndRecPtr, and - * recoveryLastXTime. - * - * This is slightly confusing if we're starting from an online - * checkpoint; we've just read and replayed the checkpoint record, but - * we're going to start replay from its redo pointer, which precedes - * the location of the checkpoint record itself. So even though the - * last record we've replayed is indeed ReadRecPtr, we haven't - * replayed all the preceding records yet. That's OK for the current - * use of these variables. + * Initialize shared variables for tracking progress of WAL replay. */ SpinLockAcquire(&xlogctl->info_lck); - xlogctl->replayEndRecPtr = ReadRecPtr; - xlogctl->lastReplayedEndRecPtr = EndRecPtr; + /* pretend we had just replayed the record before the REDO location */ + xlogctl->replayEndRecPtr = checkPoint.redo; + xlogctl->lastReplayedEndRecPtr = checkPoint.redo; xlogctl->recoveryLastXTime = 0; xlogctl->currentChunkStartTime = 0; xlogctl->recoveryPause = false; @@ -7307,6 +7299,8 @@ StartupXLOG(void) static void CheckRecoveryConsistency(void) { + XLogRecPtr lastReplayedEndRecPtr; + /* * During crash recovery, we don't reach a consistent state until we've * replayed all the WAL. @@ -7315,10 +7309,16 @@ CheckRecoveryConsistency(void) return; /* + * assume that we are called in the startup process, and hence don't need + * a lock to read lastReplayedEndRecPtr + */ + lastReplayedEndRecPtr = XLogCtl->lastReplayedEndRecPtr; + + /* * Have we reached the point where our base backup was completed? */ if (!XLogRecPtrIsInvalid(ControlFile->backupEndPoint) && - XLByteLE(ControlFile->backupEndPoint, EndRecPtr)) + XLByteLE(ControlFile->backupEndPoint, lastReplayedEndRecPtr)) { /* * We have reached the end of base backup, as indicated by pg_control. @@ -7331,8 +7331,8 @@ CheckRecoveryConsistency(void) LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); - if (XLByteLT(ControlFile->minRecoveryPoint, EndRecPtr)) - ControlFile->minRecoveryPoint = EndRecPtr; + if (XLByteLT(ControlFile->minRecoveryPoint, lastReplayedEndRecPtr)) + ControlFile->minRecoveryPoint = lastReplayedEndRecPtr; MemSet(&ControlFile->backupStartPoint, 0, sizeof(XLogRecPtr)); MemSet(&ControlFile->backupEndPoint, 0, sizeof(XLogRecPtr)); @@ -7350,7 +7350,7 @@ CheckRecoveryConsistency(void) * consistent yet. */ if (!reachedConsistency && !ControlFile->backupEndRequired && - XLByteLE(minRecoveryPoint, XLogCtl->lastReplayedEndRecPtr) && + XLByteLE(minRecoveryPoint, lastReplayedEndRecPtr) && XLogRecPtrIsInvalid(ControlFile->backupStartPoint)) { /* @@ -7362,8 +7362,8 @@ CheckRecoveryConsistency(void) reachedConsistency = true; ereport(LOG, (errmsg("consistent recovery state reached at %X/%X", - XLogCtl->lastReplayedEndRecPtr.xlogid, - XLogCtl->lastReplayedEndRecPtr.xrecoff))); + lastReplayedEndRecPtr.xlogid, + lastReplayedEndRecPtr.xrecoff))); } /* --------------010509020300050007080804 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------010509020300050007080804--