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

Commit644a0a6

Browse files
committed
Fix archive_cleanup_command.
When I moved ExecuteRecoveryCommand() from xlog.c to xlogarchive.c, I didn'trealize that it's called from the checkpoint process, not the startupprocess. I tried to use InRedo variable to decide whether or not to attemptcleaning up the archive (must not do so before we have read the initialcheckpoint record), but that variable is only valid within the startupprocess.Instead, let ExecuteRecoveryCommand() always clean up the archive, and addan explicit argument to RestoreArchivedFile() to say whether that's allowedor not. The caller knows better.Reported by Erik Rijkers, diagnosis by Fujii Masao. Only 9.3devel isaffected.
1 parentb6e3798 commit644a0a6

File tree

4 files changed

+25
-34
lines changed

4 files changed

+25
-34
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ readTimeLineHistory(TimeLineID targetTLI)
6464
if (InArchiveRecovery)
6565
{
6666
TLHistoryFileName(histfname,targetTLI);
67-
RestoreArchivedFile(path,histfname,"RECOVERYHISTORY",0);
67+
RestoreArchivedFile(path,histfname,"RECOVERYHISTORY",0, false);
6868
}
6969
else
7070
TLHistoryFilePath(path,targetTLI);
@@ -153,7 +153,7 @@ existsTimeLineHistory(TimeLineID probeTLI)
153153
if (InArchiveRecovery)
154154
{
155155
TLHistoryFileName(histfname,probeTLI);
156-
RestoreArchivedFile(path,histfname,"RECOVERYHISTORY",0);
156+
RestoreArchivedFile(path,histfname,"RECOVERYHISTORY",0, false);
157157
}
158158
else
159159
TLHistoryFilePath(path,probeTLI);
@@ -257,7 +257,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
257257
if (InArchiveRecovery)
258258
{
259259
TLHistoryFileName(histfname,parentTLI);
260-
RestoreArchivedFile(path,histfname,"RECOVERYHISTORY",0);
260+
RestoreArchivedFile(path,histfname,"RECOVERYHISTORY",0, false);
261261
}
262262
else
263263
TLHistoryFilePath(path,parentTLI);

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,8 @@ XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli,
25882588

25892589
restoredFromArchive=RestoreArchivedFile(path,xlogfname,
25902590
"RECOVERYXLOG",
2591-
XLogSegSize);
2591+
XLogSegSize,
2592+
InRedo);
25922593
if (!restoredFromArchive)
25932594
return-1;
25942595
break;
@@ -9051,33 +9052,16 @@ GetXLogWriteRecPtr(void)
90519052
}
90529053

90539054
/*
9054-
* Returns the redo pointer of the last restartpoint. This is the oldest
9055-
* point in WAL that we still need, if we have to restart recovery. Returns
9056-
* InvalidXLogRecPtr if we don't reliably know that point yet, that is,
9057-
* before we have started WAL redo.
9058-
*
9059-
* This function only works in the startup process, and only while we are
9060-
* in WAL redo. It's important to not return a value before redo has started,
9061-
* to avoid deleting WAL files that we might still need, but there's no
9062-
* fundamental reason why this couldn't return a valid value after redo has
9063-
* finished, or in other processes. This is enough for the current usage,
9064-
* however.
9055+
* Returns the redo pointer of the last checkpoint or restartpoint. This is
9056+
* the oldest point in WAL that we still need, if we have to restart recovery.
90659057
*/
90669058
void
90679059
GetOldestRestartPoint(XLogRecPtr*oldrecptr,TimeLineID*oldtli)
90689060
{
9069-
if (InRedo)
9070-
{
9071-
LWLockAcquire(ControlFileLock,LW_SHARED);
9072-
*oldrecptr=ControlFile->checkPointCopy.redo;
9073-
*oldtli=ControlFile->checkPointCopy.ThisTimeLineID;
9074-
LWLockRelease(ControlFileLock);
9075-
}
9076-
else
9077-
{
9078-
*oldrecptr=InvalidXLogRecPtr;
9079-
*oldtli=0;
9080-
}
9061+
LWLockAcquire(ControlFileLock,LW_SHARED);
9062+
*oldrecptr=ControlFile->checkPointCopy.redo;
9063+
*oldtli=ControlFile->checkPointCopy.ThisTimeLineID;
9064+
LWLockRelease(ControlFileLock);
90819065
}
90829066

90839067
/*

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@
4141
* For fixed-size files, the caller may pass the expected size as an
4242
* additional crosscheck on successful recovery. If the file size is not
4343
* known, set expectedSize = 0.
44+
*
45+
* When 'cleanupEnabled' is false, refrain from deleting any old WAL segments
46+
* in the archive. This is used when fetching the initial checkpoint record,
47+
* when we are not yet sure how far back we need the WAL.
4448
*/
4549
bool
4650
RestoreArchivedFile(char*path,constchar*xlogfname,
47-
constchar*recovername,off_texpectedSize)
51+
constchar*recovername,off_texpectedSize,
52+
boolcleanupEnabled)
4853
{
4954
charxlogpath[MAXPGPATH];
5055
charxlogRestoreCmd[MAXPGPATH];
@@ -113,9 +118,10 @@ RestoreArchivedFile(char *path, const char *xlogfname,
113118
* replication. All files earlier than this point can be deleted from the
114119
* archive, though there is no requirement to do so.
115120
*
116-
* We initialise this with the filename of an InvalidXLogRecPtr, which
117-
* will prevent the deletion of any WAL files from the archive because of
118-
* the alphabetic sorting property of WAL filenames.
121+
* If cleanup is not enabled, initialise this with the filename of
122+
* InvalidXLogRecPtr, which will prevent the deletion of any WAL files
123+
* from the archive because of the alphabetic sorting property of WAL
124+
* filenames.
119125
*
120126
* Once we have successfully located the redo pointer of the checkpoint
121127
* from which we start recovery we never request a file prior to the redo
@@ -124,9 +130,9 @@ RestoreArchivedFile(char *path, const char *xlogfname,
124130
* flags to signify the point when we can begin deleting WAL files from
125131
* the archive.
126132
*/
127-
GetOldestRestartPoint(&restartRedoPtr,&restartTli);
128-
if (!XLogRecPtrIsInvalid(restartRedoPtr))
133+
if (cleanupEnabled)
129134
{
135+
GetOldestRestartPoint(&restartRedoPtr,&restartTli);
130136
XLByteToSeg(restartRedoPtr,restartSegNo);
131137
XLogFileName(lastRestartPointFname,restartTli,restartSegNo);
132138
/* we shouldn't need anything earlier than last restart point */

‎src/include/access/xlog_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ extern char *recoveryRestoreCommand;
243243
* Prototypes for functions in xlogarchive.c
244244
*/
245245
externboolRestoreArchivedFile(char*path,constchar*xlogfname,
246-
constchar*recovername,off_texpectedSize);
246+
constchar*recovername,off_texpectedSize,
247+
boolcleanupEnabled);
247248
externvoidExecuteRecoveryCommand(char*command,char*commandName,
248249
boolfailOnerror);
249250
externvoidXLogArchiveNotify(constchar*xlog);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp