Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7e59b12

Browse files
committed
Fix control file update done in restartpoints still running after promotion
If a cluster is promoted (aka the control file shows a state differentthan DB_IN_ARCHIVE_RECOVERY) while CreateRestartPoint() is stillprocessing, this function could miss an update of the control file for"checkPoint" and "checkPointCopy" but still do the recycling and/orremoval of the past WAL segments, assuming that the to-be-updated LSNvalues should be used as reference points for the cleanup. This causesa follow-up restart attempting crash recovery to fail with a PANIC on amissing checkpoint record if the end-of-recovery checkpoint triggered bythe promotion did not complete while the cluster abruptly stopped orcrashed before the completion of this checkpoint. The PANIC would becaused by the redo LSN referred in the control file as located in asegment already gone, recycled by the previous restartpoint with"checkPoint" out-of-sync in the control file.This commit fixes the update of the control file during restartpoints soas "checkPoint" and "checkPointCopy" are updated even if the cluster hasbeen promoted while a restartpoint is running, to be on par with the setof WAL segments actually recycled in the end of CreateRestartPoint().7863ee4 has fixed this problem already on master, but the release timingof the latest point versions did not let me enough time to study and fixthat on all the stable branches.Reported-by: Fujii Masao, Rui ZhaoAuthor: Kyotaro HoriguchiReviewed-by: Nathan Bossart, Michael PaquierDiscussion:https://postgr.es/m/20220316.102444.2193181487576617583.horikyota.ntt@gmail.comBackpatch-through: 10
1 parent301b91c commit7e59b12

File tree

1 file changed

+29
-15
lines changed
  • src/backend/access/transam

1 file changed

+29
-15
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9370,21 +9370,26 @@ CreateRestartPoint(int flags)
93709370
PriorRedoPtr=ControlFile->checkPointCopy.redo;
93719371

93729372
/*
9373-
* Update pg_control, using current time. Check that it still shows
9374-
*IN_ARCHIVE_RECOVERY state and anolder checkpoint, else do nothing;
9375-
*this is a quick hack to make surenothing really bad happens if somehow
9376-
*we get here after theend-of-recovery checkpoint.
9373+
* Update pg_control, using current time. Check that it still shows an
9374+
* older checkpoint, else do nothing; this is a quick hack to make sure
9375+
* nothing really bad happens if somehow we get here after the
9376+
* end-of-recovery checkpoint.
93779377
*/
93789378
LWLockAcquire(ControlFileLock,LW_EXCLUSIVE);
9379-
if (ControlFile->state==DB_IN_ARCHIVE_RECOVERY&&
9380-
ControlFile->checkPointCopy.redo<lastCheckPoint.redo)
9379+
if (ControlFile->checkPointCopy.redo<lastCheckPoint.redo)
93819380
{
9381+
/*
9382+
* Update the checkpoint information. We do this even if the cluster
9383+
* does not show DB_IN_ARCHIVE_RECOVERY to match with the set of WAL
9384+
* segments recycled below.
9385+
*/
93829386
ControlFile->checkPoint=lastCheckPointRecPtr;
93839387
ControlFile->checkPointCopy=lastCheckPoint;
93849388
ControlFile->time= (pg_time_t)time(NULL);
93859389

93869390
/*
9387-
* Ensure minRecoveryPoint is past the checkpoint record. Normally,
9391+
* Ensure minRecoveryPoint is past the checkpoint record and update it
9392+
* if the control file still shows DB_IN_ARCHIVE_RECOVERY. Normally,
93889393
* this will have happened already while writing out dirty buffers,
93899394
* but not necessarily - e.g. because no buffers were dirtied. We do
93909395
* this because a non-exclusive base backup uses minRecoveryPoint to
@@ -9393,18 +9398,27 @@ CreateRestartPoint(int flags)
93939398
* at a minimum. Note that for an ordinary restart of recovery there's
93949399
* no value in having the minimum recovery point any earlier than this
93959400
* anyway, because redo will begin just after the checkpoint record.
9401+
* this because a non-exclusive base backup uses minRecoveryPoint to
9402+
* determine which WAL files must be included in the backup, and the
9403+
* file (or files) containing the checkpoint record must be included,
9404+
* at a minimum. Note that for an ordinary restart of recovery there's
9405+
* no value in having the minimum recovery point any earlier than this
9406+
* anyway, because redo will begin just after the checkpoint record.
93969407
*/
9397-
if (ControlFile->minRecoveryPoint<lastCheckPointEndPtr)
9408+
if (ControlFile->state==DB_IN_ARCHIVE_RECOVERY)
93989409
{
9399-
ControlFile->minRecoveryPoint=lastCheckPointEndPtr;
9400-
ControlFile->minRecoveryPointTLI=lastCheckPoint.ThisTimeLineID;
9410+
if (ControlFile->minRecoveryPoint<lastCheckPointEndPtr)
9411+
{
9412+
ControlFile->minRecoveryPoint=lastCheckPointEndPtr;
9413+
ControlFile->minRecoveryPointTLI=lastCheckPoint.ThisTimeLineID;
94019414

9402-
/* update local copy */
9403-
minRecoveryPoint=ControlFile->minRecoveryPoint;
9404-
minRecoveryPointTLI=ControlFile->minRecoveryPointTLI;
9415+
/* update local copy */
9416+
minRecoveryPoint=ControlFile->minRecoveryPoint;
9417+
minRecoveryPointTLI=ControlFile->minRecoveryPointTLI;
9418+
}
9419+
if (flags&CHECKPOINT_IS_SHUTDOWN)
9420+
ControlFile->state=DB_SHUTDOWNED_IN_RECOVERY;
94059421
}
9406-
if (flags&CHECKPOINT_IS_SHUTDOWN)
9407-
ControlFile->state=DB_SHUTDOWNED_IN_RECOVERY;
94089422
UpdateControlFile();
94099423
}
94109424
LWLockRelease(ControlFileLock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp