@@ -418,6 +418,7 @@ typedef struct XLogCtlData
418
418
* recovery. Protected by info_lck.
419
419
*/
420
420
bool SharedRecoveryInProgress ;
421
+ bool SharedInArchiveRecovery ;
421
422
422
423
/*
423
424
* SharedHotStandbyActive indicates if we're still in crash or archive
@@ -622,6 +623,7 @@ static void XLogArchiveCleanup(const char *xlog);
622
623
static void readRecoveryCommandFile (void );
623
624
static void exitArchiveRecovery (TimeLineID endTLI ,
624
625
uint32 endLogId , uint32 endLogSeg );
626
+ static bool ArchiveRecoveryInProgress (void );
625
627
static bool recoveryStopsHere (XLogRecord * record , bool * includeThis );
626
628
static void recoveryPausesHere (void );
627
629
static void SetLatestXTime (TimestampTz xtime );
@@ -3571,7 +3573,7 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
3571
3573
strspn (xlde -> d_name , "0123456789ABCDEF" ) == 24 &&
3572
3574
strcmp (xlde -> d_name + 8 , lastoff + 8 ) <= 0 )
3573
3575
{
3574
- if (RecoveryInProgress () || XLogArchiveCheckDone (xlde -> d_name ))
3576
+ if (ArchiveRecoveryInProgress () || XLogArchiveCheckDone (xlde -> d_name ))
3575
3577
{
3576
3578
snprintf (path , MAXPGPATH , XLOGDIR "/%s" , xlde -> d_name );
3577
3579
@@ -5289,6 +5291,7 @@ XLOGShmemInit(void)
5289
5291
*/
5290
5292
XLogCtl -> XLogCacheBlck = XLOGbuffers - 1 ;
5291
5293
XLogCtl -> SharedRecoveryInProgress = true;
5294
+ XLogCtl -> SharedInArchiveRecovery = false;
5292
5295
XLogCtl -> SharedHotStandbyActive = false;
5293
5296
XLogCtl -> WalWriterSleeping = false;
5294
5297
XLogCtl -> Insert .currpage = (XLogPageHeader ) (XLogCtl -> pages );
@@ -5680,6 +5683,7 @@ readRecoveryCommandFile(void)
5680
5683
5681
5684
/* Enable fetching from archive recovery area */
5682
5685
InArchiveRecovery = true;
5686
+ XLogCtl -> SharedInArchiveRecovery = true;
5683
5687
5684
5688
/*
5685
5689
* If user specified recovery_target_timeline, validate it or compute the
@@ -5718,11 +5722,16 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
5718
5722
{
5719
5723
char recoveryPath [MAXPGPATH ];
5720
5724
char xlogpath [MAXPGPATH ];
5725
+ /* use volatile pointer to prevent code rearrangement */
5726
+ volatile XLogCtlData * xlogctl = XLogCtl ;
5721
5727
5722
5728
/*
5723
5729
* We are no longer in archive recovery state.
5724
5730
*/
5725
5731
InArchiveRecovery = false;
5732
+ SpinLockAcquire (& xlogctl -> info_lck );
5733
+ xlogctl -> SharedInArchiveRecovery = false;
5734
+ SpinLockRelease (& xlogctl -> info_lck );
5726
5735
5727
5736
/*
5728
5737
* Update min recovery point one last time.
@@ -7314,6 +7323,25 @@ RecoveryInProgress(void)
7314
7323
}
7315
7324
}
7316
7325
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
+
7317
7345
/*
7318
7346
* Is HotStandby active yet? This is only important in special backends
7319
7347
* since normal backends won't ever be able to connect until this returns
0 commit comments