pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #8686: Standby could not restart.
7+ messages / 4 participants
[nested] [flat]
* BUG #8686: Standby could not restart.
@ 2013-12-19 02:57 katsumata.tomonari@po.ntts.co.jp
0 siblings, 2 replies; 7+ messages in thread
From: katsumata.tomonari@po.ntts.co.jp @ 2013-12-19 02:57 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 8686
Logged by: Tomonari Katsumata
Email address: katsumata.tomonari@po.ntts.co.jp
PostgreSQL version: 9.2.6
Operating system: Red Hat Enterprise Linux 6.2 x86_64
Description:
Hi,
I'm testing whether a standby could restart with asynchronous replication.
The testcase is very simple like below.
(A) start asyncronous replication
(B) stop standby with "-m f"
(C) start standby
I tried (B) and (C) periodically.
In almost cases, it worked fine.
But standby could not start one time because of PANIC.
---- Log -----
[Standby] 2013-12-09 10:42:30 JST LOG: 00000: database system was shut down
in recovery at 2013-12-09 10:42:29 JST
[Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6273
cp: cannot stat `../arc/00000002.history': No such file or directory
[Standby] 2013-12-09 10:42:30 JST LOG: 00000: entering standby mode
[Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6359
cp: cannot stat `../arc/000000010000000100000008': No such file or
directory
[Standby] 2013-12-09 10:42:30 JST LOG: 00000: consistent recovery state
reached at 1/8E7F110
[Standby] 2013-12-09 10:42:30 JST LOCATION: CheckRecoveryConsistency,
xlog.c:7366
[Standby] 2013-12-09 10:42:30 JST LOG: 00000: restored log file
"000000010000000100000007" from archive
[Standby] 2013-12-09 10:42:30 JST LOCATION: RestoreArchivedFile,
xlog.c:3273
[Standby] 2013-12-09 10:42:30 JST LOG: 00000: redo starts at 1/783B230
[Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6827
[Standby] 2013-12-09 10:42:30 JST WARNING: 01000: page 1365 of relation
base/16384/16388 does not exist
[Standby] 2013-12-09 10:42:30 JST CONTEXT: xlog redo hot_update: rel
1663/16384/16388; tid 1365/152; new 1365/153
[Standby] 2013-12-09 10:42:30 JST LOCATION: report_invalid_page,
xlogutils.c:66
[Standby] 2013-12-09 10:42:30 JST PANIC: XX000: WAL contains references to
invalid pages
[Standby] 2013-12-09 10:42:30 JST CONTEXT: xlog redo hot_update: rel
1663/16384/16388; tid 1365/152; new 1365/153
[Standby] 2013-12-09 10:42:30 JST LOCATION: log_invalid_page,
xlogutils.c:91
[Standby] 2013-12-09 10:42:30 JST LOG: 00000: startup process (PID 12560)
was terminated by signal 6: Aborted
[Standby] 2013-12-09 10:42:30 JST LOCATION: LogChildExit,
postmaster.c:2895
[Standby] 2013-12-09 10:42:30 JST LOG: 00000: terminating any other active
server processes
[Standby] 2013-12-09 10:42:30 JST LOCATION: HandleChildCrash,
postmaster.c:2682
[Standby] 2013-12-09 11:10:12 JST LOG: 00000: database system was
interrupted while in recovery at log time 2013-12-09 10:32:14 JST
[Standby] 2013-12-09 11:10:12 JST HINT: If this has occurred more than once
some data might be corrupted and you might need to choose an earlier
recovery target.
[Standby] 2013-12-09 11:10:12 JST LOCATION: StartupXLOG, xlog.c:6289
---------
I tried to fix this problem.
At first, I doubted the recovery state reached "consistent" before redo
starts.
And then I checked pg_control and related WAL.
The WAL sequence is like below.
WAL--(a)--(b)--(c)--(d)--(e)-->
================================================
(a) Latest checkpoint's REDO location
1/783B230
(b) hot_update
1/7842010
(c) truncate
1/8E7E5C8
(d) Latest checkpoint location
1/8E7F0B0
(e) Minimum recovery ending location
1/8E7F110
================================================
From these things, I found it has happened with this scenario.
----------
(1) standby starting
(2) seeking checkpoint location 1/8E7F0B0 because backup_label is not
absecnt
(3) reachedConsistency is set to true at 1/8E7F110 in
CheckRecoveryConsistent
(4) redo start from 1/783B230
(5) PANIC at 1/7842010 because reachedConsistency has set already and
operating against a block which will be truncated at (c).
----------
At step(2), EndRecPtr is set to 1/8E7F110(next to 1/8E7F0B0),
so reachedConsistency is set to true at step(3).
I think it's not need to increase EndRecPtr while seeking checkpoint
location.
I tried to revise it and this worked fine.
I think this is very very narrow gate, but it could happen.
I'm not sure this problem happen with synchronous replication or
another version of PostgreSQL(ie. 9.3/9.1/9.0),
but at least we need to fix it.
regards,
----------------
Tomonari Katsumata
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #8686: Standby could not restart.
@ 2013-12-19 03:01 Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
parent: katsumata.tomonari@po.ntts.co.jp
1 sibling, 0 replies; 7+ messages in thread
From: Tomonari Katsumata @ 2013-12-19 03:01 UTC (permalink / raw)
To: pgsql-bugs
Hi,
This is a patch against REL9_2_STABLE(*)
(*)0c07ef1ad2ba73a6a050f3e1a19267f961a43586
regards,
---------------
Tomonari Katsumata
(2013/12/19 11:57), katsumata.tomonari@po.ntts.co.jp wrote:
> The following bug has been logged on the website:
>
> Bug reference: 8686
> Logged by: Tomonari Katsumata
> Email address: katsumata.tomonari@po.ntts.co.jp
> PostgreSQL version: 9.2.6
> Operating system: Red Hat Enterprise Linux 6.2 x86_64
> Description:
>
> Hi,
>
>
> I'm testing whether a standby could restart with asynchronous
replication.
>
>
> The testcase is very simple like below.
> (A) start asyncronous replication
> (B) stop standby with "-m f"
> (C) start standby
>
>
> I tried (B) and (C) periodically.
>
>
> In almost cases, it worked fine.
> But standby could not start one time because of PANIC.
> ---- Log -----
> [Standby] 2013-12-09 10:42:30 JST LOG: 00000: database system was
shut down
> in recovery at 2013-12-09 10:42:29 JST
> [Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6273
> cp: cannot stat `../arc/00000002.history': No such file or directory
> [Standby] 2013-12-09 10:42:30 JST LOG: 00000: entering standby mode
> [Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6359
> cp: cannot stat `../arc/000000010000000100000008': No such file or
> directory
> [Standby] 2013-12-09 10:42:30 JST LOG: 00000: consistent recovery state
> reached at 1/8E7F110
> [Standby] 2013-12-09 10:42:30 JST LOCATION: CheckRecoveryConsistency,
> xlog.c:7366
> [Standby] 2013-12-09 10:42:30 JST LOG: 00000: restored log file
> "000000010000000100000007" from archive
> [Standby] 2013-12-09 10:42:30 JST LOCATION: RestoreArchivedFile,
> xlog.c:3273
> [Standby] 2013-12-09 10:42:30 JST LOG: 00000: redo starts at 1/783B230
> [Standby] 2013-12-09 10:42:30 JST LOCATION: StartupXLOG, xlog.c:6827
> [Standby] 2013-12-09 10:42:30 JST WARNING: 01000: page 1365 of relation
> base/16384/16388 does not exist
> [Standby] 2013-12-09 10:42:30 JST CONTEXT: xlog redo hot_update: rel
> 1663/16384/16388; tid 1365/152; new 1365/153
> [Standby] 2013-12-09 10:42:30 JST LOCATION: report_invalid_page,
> xlogutils.c:66
> [Standby] 2013-12-09 10:42:30 JST PANIC: XX000: WAL contains
references to
> invalid pages
> [Standby] 2013-12-09 10:42:30 JST CONTEXT: xlog redo hot_update: rel
> 1663/16384/16388; tid 1365/152; new 1365/153
> [Standby] 2013-12-09 10:42:30 JST LOCATION: log_invalid_page,
> xlogutils.c:91
> [Standby] 2013-12-09 10:42:30 JST LOG: 00000: startup process (PID
12560)
> was terminated by signal 6: Aborted
> [Standby] 2013-12-09 10:42:30 JST LOCATION: LogChildExit,
> postmaster.c:2895
> [Standby] 2013-12-09 10:42:30 JST LOG: 00000: terminating any other
active
> server processes
> [Standby] 2013-12-09 10:42:30 JST LOCATION: HandleChildCrash,
> postmaster.c:2682
> [Standby] 2013-12-09 11:10:12 JST LOG: 00000: database system was
> interrupted while in recovery at log time 2013-12-09 10:32:14 JST
> [Standby] 2013-12-09 11:10:12 JST HINT: If this has occurred more
than once
> some data might be corrupted and you might need to choose an earlier
> recovery target.
> [Standby] 2013-12-09 11:10:12 JST LOCATION: StartupXLOG, xlog.c:6289
> ---------
>
>
> I tried to fix this problem.
> At first, I doubted the recovery state reached "consistent" before redo
> starts.
> And then I checked pg_control and related WAL.
> The WAL sequence is like below.
>
>
> WAL--(a)--(b)--(c)--(d)--(e)-->
> ================================================
> (a) Latest checkpoint's REDO location
> 1/783B230
>
>
> (b) hot_update
> 1/7842010
>
>
> (c) truncate
> 1/8E7E5C8
>
>
> (d) Latest checkpoint location
> 1/8E7F0B0
>
>
> (e) Minimum recovery ending location
> 1/8E7F110
> ================================================
>
>
> >From these things, I found it has happened with this scenario.
> ----------
> (1) standby starting
> (2) seeking checkpoint location 1/8E7F0B0 because backup_label is not
> absecnt
> (3) reachedConsistency is set to true at 1/8E7F110 in
> CheckRecoveryConsistent
> (4) redo start from 1/783B230
> (5) PANIC at 1/7842010 because reachedConsistency has set already and
> operating against a block which will be truncated at (c).
> ----------
>
>
> At step(2), EndRecPtr is set to 1/8E7F110(next to 1/8E7F0B0),
> so reachedConsistency is set to true at step(3).
>
>
> I think it's not need to increase EndRecPtr while seeking checkpoint
> location.
> I tried to revise it and this worked fine.
>
>
> I think this is very very narrow gate, but it could happen.
>
>
> I'm not sure this problem happen with synchronous replication or
> another version of PostgreSQL(ie. 9.3/9.1/9.0),
> but at least we need to fix it.
>
>
> regards,
> ----------------
> Tomonari Katsumata
>
>
>
>
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
do_not_increase_EndRecPtr_while_seek_ckptloc.patch (text/x-diff, 1.6K) download
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 190d86b..92599bc 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4222,10 +4222,13 @@ retry:
if (!RecordIsValid(record, *RecPtr, emode))
goto next_record_is_invalid;
pageHeaderSize = XLogPageHeaderSize((XLogPageHeader) readBuf);
- EndRecPtr.xlogid = readId;
- EndRecPtr.xrecoff = readSeg * XLogSegSize + readOff +
+ if (!fetching_ckpt)
+ {
+ EndRecPtr.xlogid = readId;
+ EndRecPtr.xrecoff = readSeg * XLogSegSize + readOff +
pageHeaderSize +
MAXALIGN(SizeOfXLogContRecord + contrecord->xl_rem_len);
+ }
ReadRecPtr = *RecPtr;
/* needn't worry about XLOG SWITCH, it can't cross page boundaries */
@@ -4235,8 +4238,11 @@ retry:
/* Record does not cross a page boundary */
if (!RecordIsValid(record, *RecPtr, emode))
goto next_record_is_invalid;
- EndRecPtr.xlogid = RecPtr->xlogid;
- EndRecPtr.xrecoff = RecPtr->xrecoff + MAXALIGN(total_len);
+ if (!fetching_ckpt)
+ {
+ EndRecPtr.xlogid = RecPtr->xlogid;
+ EndRecPtr.xrecoff = RecPtr->xrecoff + MAXALIGN(total_len);
+ }
ReadRecPtr = *RecPtr;
memcpy(buffer, record, total_len);
@@ -4247,8 +4253,11 @@ retry:
if (record->xl_rmid == RM_XLOG_ID && record->xl_info == XLOG_SWITCH)
{
/* Pretend it extends to end of segment */
- EndRecPtr.xrecoff += XLogSegSize - 1;
- EndRecPtr.xrecoff -= EndRecPtr.xrecoff % XLogSegSize;
+ if (!fetching_ckpt)
+ {
+ EndRecPtr.xrecoff += XLogSegSize - 1;
+ EndRecPtr.xrecoff -= EndRecPtr.xrecoff % XLogSegSize;
+ }
/*
* Pretend that readBuf contains the last page of the segment. This is
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #8686: Standby could not restart.
@ 2013-12-20 16:15 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: katsumata.tomonari@po.ntts.co.jp
1 sibling, 1 reply; 7+ messages in thread
From: Heikki Linnakangas @ 2013-12-20 16:15 UTC (permalink / raw)
To: katsumata.tomonari@po.ntts.co.jp; +Cc: pgsql-bugs
On 12/19/2013 04:57 AM, katsumata.tomonari@po.ntts.co.jp wrote:
> At first, I doubted the recovery state reached "consistent" before redo
> starts.
> And then I checked pg_control and related WAL.
> The WAL sequence is like below.
>
>
> WAL--(a)--(b)--(c)--(d)--(e)-->
> ================================================
> (a) Latest checkpoint's REDO location
> 1/783B230
>
>
> (b) hot_update
> 1/7842010
>
>
> (c) truncate
> 1/8E7E5C8
>
>
> (d) Latest checkpoint location
> 1/8E7F0B0
>
>
> (e) Minimum recovery ending location
> 1/8E7F110
> ================================================
>
>
>>From these things, I found it has happened with this scenario.
> ----------
> (1) standby starting
> (2) seeking checkpoint location 1/8E7F0B0 because backup_label is not
> absecnt
> (3) reachedConsistency is set to true at 1/8E7F110 in
> CheckRecoveryConsistent
> (4) redo start from 1/783B230
> (5) PANIC at 1/7842010 because reachedConsistency has set already and
> operating against a block which will be truncated at (c).
> ----------
>
> At step(2), EndRecPtr is set to 1/8E7F110(next to 1/8E7F0B0),
> so reachedConsistency is set to true at step(3).
Yep. Thanks for a good explanation.
> I think it's not need to increase EndRecPtr while seeking checkpoint
> location.
> I tried to revise it and this worked fine.
Hmm. There's this comment in StartupXLOG, after reading the checkpoint
record, but before reading the first record at REDO point:
> /*
> * 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.
Perhaps we should reset replayEndRecPtr and lastReplayedEndRecPtr to the
REDO point here, instead of ReadRecPtr/EndRecPtr.
- Heikki
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #8686: Standby could not restart.
@ 2013-12-23 06:15 Tomonari Katsumata <t.katsumata1122@gmail.com>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 1 reply; 7+ messages in thread
From: Tomonari Katsumata @ 2013-12-23 06:15 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>; pgsql-bugs
Hi Heikki,
Thanks for your confirmation and comments.
>
>
> /*
>> * 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.
regards,
---------------------
Tomonari Katsumata
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
making_sure_ckptredo_from_pg_control.patch (application/octet-stream, 973B) download
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 190d86b..22b5ff9 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6499,6 +6499,21 @@ StartupXLOG(void)
}
memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
wasShutdown = (record->xl_info == XLOG_CHECKPOINT_SHUTDOWN);
+
+ /*
+ * Make sure that REDO location exists and reset ReadRecPtr,
+ * EndRecPtr to the REDO location.
+ * Later, xlogctl->replayEndRecPtr, xlogctl->lastReplayedEndRecPtr
+ * are set to these values as initial value.
+ */
+ if (InArchiveRecovery && XLByteLT(checkPoint.redo, checkPointLoc))
+ {
+ if (!(record = ReadRecord(&(checkPoint.redo), LOG, false)))
+ ereport(FATAL,
+ (errmsg("could not find redo location referenced by checkpoint record from control file")));
+ EndRecPtr = ReadRecPtr;
+ ReadRecPtr = record->xl_prev;
+ }
}
LastRec = RecPtr = checkPointLoc;
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #8686: Standby could not restart.
@ 2014-01-06 14:38 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: Tomonari Katsumata <t.katsumata1122@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Heikki Linnakangas @ 2014-01-06 14:38 UTC (permalink / raw)
To: Tomonari Katsumata <t.katsumata1122@gmail.com>; +Cc: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>; pgsql-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-bugs
Attachments:
fix-lastReplayedEndRecPtr-1.patch (text/x-diff, 3.2K) download
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 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)));
}
/*
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #8686: Standby could not restart.
@ 2014-01-08 08:41 Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
parent: Heikki Linnakangas <hlinnakangas@vmware.com>
0 siblings, 1 reply; 7+ messages in thread
From: Tomonari Katsumata @ 2014-01-08 08:41 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnakangas@vmware.com>; Tomonari Katsumata <t.katsumata1122@gmail.com>; +Cc: pgsql-bugs
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'.
-----------------------------------------------------------
<original>
24:+ xlogctl->replayEndRecPtr = checkpoint.redo;
27:+ xlogctl->lastReplayedEndRecPtr = checkpoint.redo;
<fix>
24:+ xlogctl->replayEndRecPtr = checkPoint.redo;
27:+ xlogctl->lastReplayedEndRecPtr = 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 = 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-bugs
Attachments:
fix-lastReplayedEndRecPtr-1_for92stable.patch (text/x-patch, 3.2K) download
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)));
}
/*
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: BUG #8686: Standby could not restart.
@ 2014-01-08 14:57 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
0 siblings, 0 replies; 7+ messages in thread
From: Heikki Linnakangas @ 2014-01-08 14:57 UTC (permalink / raw)
To: Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>; +Cc: Tomonari Katsumata <t.katsumata1122@gmail.com>; pgsql-bugs
On 01/08/2014 10:41 AM, Tomonari Katsumata wrote:
> 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.
Thanks! Committed to all stable branches 9.0 and above.
- Heikki
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2014-01-08 14:57 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 02:57 BUG #8686: Standby could not restart. katsumata.tomonari@po.ntts.co.jp
2013-12-19 03:01 ` Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
2013-12-20 16:15 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-12-23 06:15 ` Tomonari Katsumata <t.katsumata1122@gmail.com>
2014-01-06 14:38 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-01-08 08:41 ` Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
2014-01-08 14:57 ` Heikki Linnakangas <hlinnakangas@vmware.com>
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