1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-02 11:44:50 +03:00

Better fix for "unarchived WAL files get deleted on crash recovery" bug.

Revert my earlier fix for the bug that unarchived WAL files get deleted on
crash recovery, commit c9cc7e05c6d82a9781883a016c70d95aa4923122. We create
a .done file for files streamed or restored from archive, so the WAL file
recycling logic used during normal operation works just as well during
archive recovery.

Per Fujii Masao's suggestion.
This commit is contained in:
Heikki Linnakangas 2013-02-15 19:33:31 +02:00
parent fea934653c
commit b5ec56f664

View File

@ -418,7 +418,6 @@ typedef struct XLogCtlData
* recovery. Protected by info_lck.
*/
bool SharedRecoveryInProgress;
bool SharedInArchiveRecovery;
/*
* SharedHotStandbyActive indicates if we're still in crash or archive
@ -623,7 +622,6 @@ static void XLogArchiveCleanup(const char *xlog);
static void readRecoveryCommandFile(void);
static void exitArchiveRecovery(TimeLineID endTLI,
uint32 endLogId, uint32 endLogSeg);
static bool ArchiveRecoveryInProgress(void);
static bool recoveryStopsHere(XLogRecord *record, bool *includeThis);
static void recoveryPausesHere(void);
static void SetLatestXTime(TimestampTz xtime);
@ -3573,7 +3571,7 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
strcmp(xlde->d_name + 8, lastoff + 8) <= 0)
{
if (ArchiveRecoveryInProgress() || XLogArchiveCheckDone(xlde->d_name))
if (XLogArchiveCheckDone(xlde->d_name))
{
snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name);
@ -5291,7 +5289,6 @@ XLOGShmemInit(void)
*/
XLogCtl->XLogCacheBlck = XLOGbuffers - 1;
XLogCtl->SharedRecoveryInProgress = true;
XLogCtl->SharedInArchiveRecovery = false;
XLogCtl->SharedHotStandbyActive = false;
XLogCtl->WalWriterSleeping = false;
XLogCtl->Insert.currpage = (XLogPageHeader) (XLogCtl->pages);
@ -5683,7 +5680,6 @@ readRecoveryCommandFile(void)
/* Enable fetching from archive recovery area */
InArchiveRecovery = true;
XLogCtl->SharedInArchiveRecovery = true;
/*
* If user specified recovery_target_timeline, validate it or compute the
@ -5722,16 +5718,11 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
{
char recoveryPath[MAXPGPATH];
char xlogpath[MAXPGPATH];
/* use volatile pointer to prevent code rearrangement */
volatile XLogCtlData *xlogctl = XLogCtl;
/*
* We are no longer in archive recovery state.
*/
InArchiveRecovery = false;
SpinLockAcquire(&xlogctl->info_lck);
xlogctl->SharedInArchiveRecovery = false;
SpinLockRelease(&xlogctl->info_lck);
/*
* Update min recovery point one last time.
@ -7323,25 +7314,6 @@ RecoveryInProgress(void)
}
}
/*
* Are we currently in archive recovery? In the startup process, you can just
* check InArchiveRecovery variable instead.
*/
static bool
ArchiveRecoveryInProgress()
{
bool result;
/* use volatile pointer to prevent code rearrangement */
volatile XLogCtlData *xlogctl = XLogCtl;
/* spinlock is essential on machines with weak memory ordering! */
SpinLockAcquire(&xlogctl->info_lck);
result = xlogctl->SharedInArchiveRecovery;
SpinLockRelease(&xlogctl->info_lck);
return result;
}
/*
* Is HotStandby active yet? This is only important in special backends
* since normal backends won't ever be able to connect until this returns