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

Commit500fe16

Browse files
committed
Avoid assertion failure with targeted recovery in standby mode.
At the end of recovery, standby mode is turned off to re-fetch the lastvalid record from archive or pg_wal. Previously, if recovery target wasreached and standby mode was turned off while the current WAL sourcewas stream, recovery could try to retrieve WAL file containing the lastvalid record unexpectedly from stream even though not in standby mode.This caused an assertion failure. That is, the assertion test confirms thatWAL file should not be retrieved from stream if standby mode is not true.This commit moves back the current WAL source to archive if it's streameven though not in standby mode, to avoid that assertion failure.This issue doesn't cause the server to crash when built with assertiondisabled. In this case, the attempt to retrieve WAL file from stream notin standby mode just fails. And then recovery tries to retrieve WAL filefrom archive or pg_wal.Back-patch to all supported branches.Author: Kyotaro HoriguchiReviewed-by: Fujii MasaoDiscussion:https://postgr.es/m/20200227.124830.2197604521555566121.horikyota.ntt@gmail.com
1 parent53a039d commit500fe16

File tree

1 file changed

+22
-1
lines changed
  • src/backend/access/transam

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7452,7 +7452,11 @@ StartupXLOG(void)
74527452
* We are now done reading the xlog from stream. Turn off streaming
74537453
* recovery to force fetching the files (which would be required at end of
74547454
* recovery, e.g., timeline history file) from archive or pg_wal.
7455+
*
7456+
* Note that standby mode must be turned off after killing WAL receiver,
7457+
* i.e., calling ShutdownWalRcv().
74557458
*/
7459+
Assert(!WalRcvStreaming());
74567460
StandbyMode= false;
74577461

74587462
/*
@@ -11896,12 +11900,23 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
1189611900
* values for "check trigger", "rescan timelines", and "sleep" states,
1189711901
* those actions are taken when reading from the previous source fails, as
1189811902
* part of advancing to the next state.
11903+
*
11904+
* If standby mode is turned off while reading WAL from stream, we move
11905+
* to XLOG_FROM_ARCHIVE and reset lastSourceFailed, to force fetching
11906+
* the files (which would be required at end of recovery, e.g., timeline
11907+
* history file) from archive or pg_wal. We don't need to kill WAL receiver
11908+
* here because it's already stopped when standby mode is turned off at
11909+
* the end of recovery.
1189911910
*-------
1190011911
*/
1190111912
if (!InArchiveRecovery)
1190211913
currentSource=XLOG_FROM_PG_WAL;
11903-
elseif (currentSource==0)
11914+
elseif (currentSource==0||
11915+
(!StandbyMode&&currentSource==XLOG_FROM_STREAM))
11916+
{
11917+
lastSourceFailed= false;
1190411918
currentSource=XLOG_FROM_ARCHIVE;
11919+
}
1190511920

1190611921
for (;;)
1190711922
{
@@ -12093,6 +12108,12 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
1209312108
{
1209412109
caseXLOG_FROM_ARCHIVE:
1209512110
caseXLOG_FROM_PG_WAL:
12111+
/*
12112+
* WAL receiver must not be running when reading WAL from
12113+
* archive or pg_wal.
12114+
*/
12115+
Assert(!WalRcvStreaming());
12116+
1209612117
/* Close any old file we might have open. */
1209712118
if (readFile >=0)
1209812119
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp