From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Tomonari Katsumata <t.katsumata1122@gmail.com>
Cc: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8686: Standby could not restart.
Date: Mon, 06 Jan 2014 16:38:16 +0200
Message-ID: <52CABFD8.8090101@vmware.com> (raw)
In-Reply-To: <CAC55fYfGp3zfp1ySJc_QCJycQt4iJ0ch2S77S4gWQLj-x_pp1g@mail.gmail.com>
References: <E1VtTni-00082E-Jv@wrigleys.postgresql.org>
<52B46D0D.2070505@vmware.com>
<CAC55fYfGp3zfp1ySJc_QCJycQt4iJ0ch2S77S4gWQLj-x_pp1g@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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 = ReadRecPtr;
>>> xlogctl->lastReplayedEndRecPtr = EndRecPtr;
>>> xlogctl->recoveryLastXTime = 0;
>>> xlogctl->currentChunkStartTime = 0;
>>> xlogctl->recoveryPause = 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 variables in a
>> slightly strange state; I'm not sure what EndRecPtr points to in 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 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 now I
> added the process when archive recovery is needed.
>
> Please see attached patch.
Hmm. That would still initialize lastReplayedEndRecPtr to the checkpoint
record, when you do crash recovery (or begin archive recovery from a
filesystem snapshot, where you perform crash recovery before starting to
read the archive). I'm not very comfortable with that, even though I
don't see an immediate problem with it.
I also noticed that CheckRecoveryConsistency() compares backupEndPoint
with EndRecPtr, but minRecoveryPoint with lastReplayedEndRecPtr. That's
correct as the code stands, but it's an accident waiting to happen: if
you called CheckRecoveryConsistency() after reading a record with
ReadRecord(), but before fully replaying it, it might conclude that it's
reached the backup end location one record too early. And it's
inconsistent, anyway.
I propose the attached patch. I haven't tested it, but I think it's a
slightly more robust fix.
- Heikki
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:fix-lastReplayedEndRecPtr-1.patch (text/x-diff, 3.2K) downloaddiff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.cindex 43a0416..5661a17 100644--- a/src/backend/access/transam/xlog.c+++ b/src/backend/access/transam/xlog.c@@ -6684,21 +6684,13 @@ 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;+ /* pretend we had just replayed the record before the REDO location */+ xlogctl->replayEndRecPtr = checkpoint.redo;
xlogctl->replayEndTLI = ThisTimeLineID;
- xlogctl->lastReplayedEndRecPtr = EndRecPtr;+ xlogctl->lastReplayedEndRecPtr = checkpoint.redo;
xlogctl->lastReplayedTLI = ThisTimeLineID;
xlogctl->recoveryLastXTime = 0;
xlogctl->currentChunkStartTime = 0;
@@ -7388,6 +7380,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.
@@ -7396,10 +7390,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) &&
- ControlFile->backupEndPoint <= EndRecPtr)+ ControlFile->backupEndPoint <= lastReplayedEndRecPtr)
{
/*
* We have reached the end of base backup, as indicated by pg_control.
@@ -7412,8 +7412,8 @@ CheckRecoveryConsistency(void)
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
- if (ControlFile->minRecoveryPoint < EndRecPtr)- ControlFile->minRecoveryPoint = EndRecPtr;+ if (ControlFile->minRecoveryPoint < lastReplayedEndRecPtr)+ ControlFile->minRecoveryPoint = lastReplayedEndRecPtr;
ControlFile->backupStartPoint = InvalidXLogRecPtr;
ControlFile->backupEndPoint = InvalidXLogRecPtr;
@@ -7431,7 +7431,7 @@ CheckRecoveryConsistency(void)
* consistent yet.
*/
if (!reachedConsistency && !ControlFile->backupEndRequired &&
- minRecoveryPoint <= XLogCtl->lastReplayedEndRecPtr &&+ minRecoveryPoint <= lastReplayedEndRecPtr &&
XLogRecPtrIsInvalid(ControlFile->backupStartPoint))
{
/*
@@ -7443,8 +7443,8 @@ CheckRecoveryConsistency(void)
reachedConsistency = true;
ereport(LOG,
(errmsg("consistent recovery state reached at %X/%X",
- (uint32) (XLogCtl->lastReplayedEndRecPtr >> 32),- (uint32) XLogCtl->lastReplayedEndRecPtr)));+ (uint32) (lastReplayedEndRecPtr >> 32),+ (uint32) lastReplayedEndRecPtr)));
}
/*
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-bugs@postgresql.org
Cc: hlinnakangas@vmware.com, t.katsumata1122@gmail.com, katsumata.tomonari@po.ntts.co.jp
Subject: Re: BUG #8686: Standby could not restart.
In-Reply-To: <52CABFD8.8090101@vmware.com>
References: <E1VtTni-00082E-Jv@wrigleys.postgresql.org> <52B46D0D.2070505@vmware.com> <CAC55fYfGp3zfp1ySJc_QCJycQt4iJ0ch2S77S4gWQLj-x_pp1g@mail.gmail.com> <52CABFD8.8090101@vmware.com>
* 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