@@ -418,6 +418,7 @@ typedef struct XLogCtlData
418418 * recovery. Protected by info_lck.
419419 */
420420bool SharedRecoveryInProgress ;
421+ bool SharedInArchiveRecovery ;
421422
422423/*
423424 * SharedHotStandbyActive indicates if we're still in crash or archive
@@ -622,6 +623,7 @@ static void XLogArchiveCleanup(const char *xlog);
622623static void readRecoveryCommandFile (void );
623624static void exitArchiveRecovery (TimeLineID endTLI ,
624625uint32 endLogId ,uint32 endLogSeg );
626+ static bool ArchiveRecoveryInProgress (void );
625627static bool recoveryStopsHere (XLogRecord * record ,bool * includeThis );
626628static void recoveryPausesHere (void );
627629static void SetLatestXTime (TimestampTz xtime );
@@ -3571,7 +3573,7 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
35713573strspn (xlde -> d_name ,"0123456789ABCDEF" )== 24 &&
35723574strcmp (xlde -> d_name + 8 ,lastoff + 8 ) <=0 )
35733575{
3574- if (RecoveryInProgress ()|| XLogArchiveCheckDone (xlde -> d_name ))
3576+ if (ArchiveRecoveryInProgress ()|| XLogArchiveCheckDone (xlde -> d_name ))
35753577{
35763578snprintf (path ,MAXPGPATH ,XLOGDIR "/%s" ,xlde -> d_name );
35773579
@@ -5289,6 +5291,7 @@ XLOGShmemInit(void)
52895291 */
52905292XLogCtl -> XLogCacheBlck = XLOGbuffers - 1 ;
52915293XLogCtl -> SharedRecoveryInProgress = true;
5294+ XLogCtl -> SharedInArchiveRecovery = false;
52925295XLogCtl -> SharedHotStandbyActive = false;
52935296XLogCtl -> WalWriterSleeping = false;
52945297XLogCtl -> Insert .currpage = (XLogPageHeader ) (XLogCtl -> pages );
@@ -5680,6 +5683,7 @@ readRecoveryCommandFile(void)
56805683
56815684/* Enable fetching from archive recovery area */
56825685InArchiveRecovery = true;
5686+ XLogCtl -> SharedInArchiveRecovery = true;
56835687
56845688/*
56855689 * If user specified recovery_target_timeline, validate it or compute the
@@ -5718,11 +5722,16 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
57185722{
57195723char recoveryPath [MAXPGPATH ];
57205724char xlogpath [MAXPGPATH ];
5725+ /* use volatile pointer to prevent code rearrangement */
5726+ volatile XLogCtlData * xlogctl = XLogCtl ;
57215727
57225728/*
57235729 * We are no longer in archive recovery state.
57245730 */
57255731InArchiveRecovery = false;
5732+ SpinLockAcquire (& xlogctl -> info_lck );
5733+ xlogctl -> SharedInArchiveRecovery = false;
5734+ SpinLockRelease (& xlogctl -> info_lck );
57265735
57275736/*
57285737 * Update min recovery point one last time.
@@ -7314,6 +7323,25 @@ RecoveryInProgress(void)
73147323}
73157324}
73167325
7326+ /*
7327+ * Are we currently in archive recovery? In the startup process, you can just
7328+ * check InArchiveRecovery variable instead.
7329+ */
7330+ static bool
7331+ ArchiveRecoveryInProgress ()
7332+ {
7333+ bool result ;
7334+ /* use volatile pointer to prevent code rearrangement */
7335+ volatile XLogCtlData * xlogctl = XLogCtl ;
7336+
7337+ /* spinlock is essential on machines with weak memory ordering! */
7338+ SpinLockAcquire (& xlogctl -> info_lck );
7339+ result = xlogctl -> SharedInArchiveRecovery ;
7340+ SpinLockRelease (& xlogctl -> info_lck );
7341+
7342+ return result ;
7343+ }
7344+
73177345/*
73187346 * Is HotStandby active yet? This is only important in special backends
73197347 * since normal backends won't ever be able to connect until this returns