@@ -433,6 +433,7 @@ typedef struct XLogCtlData
433
433
* recovery. Protected by info_lck.
434
434
*/
435
435
bool SharedRecoveryInProgress ;
436
+ bool SharedInArchiveRecovery ;
436
437
437
438
/*
438
439
* SharedHotStandbyActive indicates if we're still in crash or archive
@@ -619,6 +620,7 @@ static bool bgwriterLaunched = false;
619
620
620
621
static void readRecoveryCommandFile (void );
621
622
static void exitArchiveRecovery (TimeLineID endTLI , XLogSegNo endLogSegNo );
623
+ static bool ArchiveRecoveryInProgress (void );
622
624
static bool recoveryStopsHere (XLogRecord * record , bool * includeThis );
623
625
static void recoveryPausesHere (void );
624
626
static void SetLatestXTime (TimestampTz xtime );
@@ -2923,7 +2925,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr endptr)
2923
2925
strspn (xlde -> d_name , "0123456789ABCDEF" ) == 24 &&
2924
2926
strcmp (xlde -> d_name + 8 , lastoff + 8 ) <= 0 )
2925
2927
{
2926
- if (RecoveryInProgress () || XLogArchiveCheckDone (xlde -> d_name ))
2928
+ if (ArchiveRecoveryInProgress () || XLogArchiveCheckDone (xlde -> d_name ))
2927
2929
{
2928
2930
snprintf (path , MAXPGPATH , XLOGDIR "/%s" , xlde -> d_name );
2929
2931
@@ -3869,6 +3871,7 @@ XLOGShmemInit(void)
3869
3871
*/
3870
3872
XLogCtl -> XLogCacheBlck = XLOGbuffers - 1 ;
3871
3873
XLogCtl -> SharedRecoveryInProgress = true;
3874
+ XLogCtl -> SharedInArchiveRecovery = false;
3872
3875
XLogCtl -> SharedHotStandbyActive = false;
3873
3876
XLogCtl -> WalWriterSleeping = false;
3874
3877
XLogCtl -> Insert .currpage = (XLogPageHeader ) (XLogCtl -> pages );
@@ -4262,6 +4265,7 @@ readRecoveryCommandFile(void)
4262
4265
4263
4266
/* Enable fetching from archive recovery area */
4264
4267
InArchiveRecovery = true;
4268
+ XLogCtl -> SharedInArchiveRecovery = true;
4265
4269
4266
4270
/*
4267
4271
* If user specified recovery_target_timeline, validate it or compute the
@@ -4300,11 +4304,16 @@ exitArchiveRecovery(TimeLineID endTLI, XLogSegNo endLogSegNo)
4300
4304
{
4301
4305
char recoveryPath [MAXPGPATH ];
4302
4306
char xlogpath [MAXPGPATH ];
4307
+ /* use volatile pointer to prevent code rearrangement */
4308
+ volatile XLogCtlData * xlogctl = XLogCtl ;
4303
4309
4304
4310
/*
4305
4311
* We are no longer in archive recovery state.
4306
4312
*/
4307
4313
InArchiveRecovery = false;
4314
+ SpinLockAcquire (& xlogctl -> info_lck );
4315
+ xlogctl -> SharedInArchiveRecovery = false;
4316
+ SpinLockRelease (& xlogctl -> info_lck );
4308
4317
4309
4318
/*
4310
4319
* Update min recovery point one last time.
@@ -6101,6 +6110,25 @@ RecoveryInProgress(void)
6101
6110
}
6102
6111
}
6103
6112
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
+
6104
6132
/*
6105
6133
* Is HotStandby active yet? This is only important in special backends
6106
6134
* since normal backends won't ever be able to connect until this returns
0 commit comments