Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1bd42cd

Browse files
committed
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 c9cc7e0. 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.
1 parent c2f79ba commit 1bd42cd

File tree

1 file changed

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

1 file changed

+1
-29
lines changed

src/backend/access/transam/xlog.c

+1-29
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ typedef struct XLogCtlData
433433
* recovery. Protected by info_lck.
434434
*/
435435
bool SharedRecoveryInProgress;
436-
bool SharedInArchiveRecovery;
437436

438437
/*
439438
* SharedHotStandbyActive indicates if we're still in crash or archive
@@ -620,7 +619,6 @@ static bool bgwriterLaunched = false;
620619

621620
static void readRecoveryCommandFile(void);
622621
static void exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo);
623-
static bool ArchiveRecoveryInProgress(void);
624622
static bool recoveryStopsHere(XLogRecord *record, bool *includeThis);
625623
static void recoveryPausesHere(void);
626624
static void SetLatestXTime(TimestampTz xtime);
@@ -2925,7 +2923,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr endptr)
29252923
strspn(xlde->d_name, "0123456789ABCDEF") == 24 &&
29262924
strcmp(xlde->d_name + 8, lastoff + 8) <= 0)
29272925
{
2928-
if (ArchiveRecoveryInProgress() || XLogArchiveCheckDone(xlde->d_name))
2926+
if (XLogArchiveCheckDone(xlde->d_name))
29292927
{
29302928
snprintf(path, MAXPGPATH, XLOGDIR "/%s", xlde->d_name);
29312929

@@ -3871,7 +3869,6 @@ XLOGShmemInit(void)
38713869
*/
38723870
XLogCtl->XLogCacheBlck = XLOGbuffers - 1;
38733871
XLogCtl->SharedRecoveryInProgress = true;
3874-
XLogCtl->SharedInArchiveRecovery = false;
38753872
XLogCtl->SharedHotStandbyActive = false;
38763873
XLogCtl->WalWriterSleeping = false;
38773874
XLogCtl->Insert.currpage = (XLogPageHeader) (XLogCtl->pages);
@@ -4265,7 +4262,6 @@ readRecoveryCommandFile(void)
42654262

42664263
/* Enable fetching from archive recovery area */
42674264
InArchiveRecovery = true;
4268-
XLogCtl->SharedInArchiveRecovery = true;
42694265

42704266
/*
42714267
* If user specified recovery_target_timeline, validate it or compute the
@@ -4304,16 +4300,11 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo)
43044300
{
43054301
char recoveryPath[MAXPGPATH];
43064302
char xlogpath[MAXPGPATH];
4307-
/* use volatile pointer to prevent code rearrangement */
4308-
volatile XLogCtlData *xlogctl = XLogCtl;
43094303

43104304
/*
43114305
* We are no longer in archive recovery state.
43124306
*/
43134307
InArchiveRecovery = false;
4314-
SpinLockAcquire(&xlogctl->info_lck);
4315-
xlogctl->SharedInArchiveRecovery = false;
4316-
SpinLockRelease(&xlogctl->info_lck);
43174308

43184309
/*
43194310
* Update min recovery point one last time.
@@ -6110,25 +6101,6 @@ RecoveryInProgress(void)
61106101
}
61116102
}
61126103

6113-
/*
6114-
* Are we currently in archive recovery? In the startup process, you can just
6115-
* check InArchiveRecovery variable instead.
6116-
*/
6117-
static bool
6118-
ArchiveRecoveryInProgress()
6119-
{
6120-
bool result;
6121-
/* use volatile pointer to prevent code rearrangement */
6122-
volatile XLogCtlData *xlogctl = XLogCtl;
6123-
6124-
/* spinlock is essential on machines with weak memory ordering! */
6125-
SpinLockAcquire(&xlogctl->info_lck);
6126-
result = xlogctl->SharedInArchiveRecovery;
6127-
SpinLockRelease(&xlogctl->info_lck);
6128-
6129-
return result;
6130-
}
6131-
61326104
/*
61336105
* Is HotStandby active yet? This is only important in special backends
61346106
* since normal backends won't ever be able to connect until this returns

0 commit comments

Comments
 (0)