@@ -681,8 +681,18 @@ typedef struct XLogCtlData
681
681
* recoveryWakeupLatch is used to wake up the startup process to continue
682
682
* WAL replay, if it is waiting for WAL to arrive or failover trigger file
683
683
* to appear.
684
+ *
685
+ * Note that the startup process also uses another latch, its procLatch,
686
+ * to wait for recovery conflict. If we get rid of recoveryWakeupLatch for
687
+ * signaling the startup process in favor of using its procLatch, which
688
+ * comports better with possible generic signal handlers using that latch.
689
+ * But we should not do that because the startup process doesn't assume
690
+ * that it's waken up by walreceiver process or SIGHUP signal handler
691
+ * while it's waiting for recovery conflict. The separate latches,
692
+ * recoveryWakeupLatch and procLatch, should be used for inter-process
693
+ * communication for WAL replay and recovery conflict, respectively.
684
694
*/
685
- Latch * recoveryWakeupLatch ;
695
+ Latch recoveryWakeupLatch ;
686
696
687
697
/*
688
698
* During recovery, we keep a copy of the latest checkpoint record here.
@@ -5186,6 +5196,7 @@ XLOGShmemInit(void)
5186
5196
SpinLockInit (& XLogCtl -> Insert .insertpos_lck );
5187
5197
SpinLockInit (& XLogCtl -> info_lck );
5188
5198
SpinLockInit (& XLogCtl -> ulsn_lck );
5199
+ InitSharedLatch (& XLogCtl -> recoveryWakeupLatch );
5189
5200
}
5190
5201
5191
5202
/*
@@ -6121,7 +6132,7 @@ recoveryApplyDelay(XLogReaderState *record)
6121
6132
6122
6133
while (true)
6123
6134
{
6124
- ResetLatch (MyLatch );
6135
+ ResetLatch (& XLogCtl -> recoveryWakeupLatch );
6125
6136
6126
6137
/* might change the trigger file's location */
6127
6138
HandleStartupProcInterrupts ();
@@ -6140,7 +6151,7 @@ recoveryApplyDelay(XLogReaderState *record)
6140
6151
6141
6152
elog (DEBUG2 , "recovery apply delay %ld milliseconds" , msecs );
6142
6153
6143
- (void ) WaitLatch (MyLatch ,
6154
+ (void ) WaitLatch (& XLogCtl -> recoveryWakeupLatch ,
6144
6155
WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH ,
6145
6156
msecs ,
6146
6157
WAIT_EVENT_RECOVERY_APPLY_DELAY );
@@ -6469,11 +6480,11 @@ StartupXLOG(void)
6469
6480
}
6470
6481
6471
6482
/*
6472
- * Advertise our latch that other processes can use to wake us up
6473
- * if we're going to sleep during recovery.
6483
+ * Take ownership of the wakeup latch if we're going to sleep during
6484
+ * recovery.
6474
6485
*/
6475
6486
if (ArchiveRecoveryRequested )
6476
- XLogCtl -> recoveryWakeupLatch = & MyProc -> procLatch ;
6487
+ OwnLatch ( & XLogCtl -> recoveryWakeupLatch ) ;
6477
6488
6478
6489
/* Set up XLOG reader facility */
6479
6490
MemSet (& private , 0 , sizeof (XLogPageReadPrivate ));
@@ -7484,11 +7495,11 @@ StartupXLOG(void)
7484
7495
ResetUnloggedRelations (UNLOGGED_RELATION_INIT );
7485
7496
7486
7497
/*
7487
- * We don't need the latch anymore. It's not strictly necessary to reset
7488
- * it to NULL , but let's do it for the sake of tidiness.
7498
+ * We don't need the latch anymore. It's not strictly necessary to disown
7499
+ * it, but let's do it for the sake of tidiness.
7489
7500
*/
7490
7501
if (ArchiveRecoveryRequested )
7491
- XLogCtl -> recoveryWakeupLatch = NULL ;
7502
+ DisownLatch ( & XLogCtl -> recoveryWakeupLatch ) ;
7492
7503
7493
7504
/*
7494
7505
* We are now done reading the xlog from stream. Turn off streaming
@@ -12300,12 +12311,12 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
12300
12311
wait_time = wal_retrieve_retry_interval -
12301
12312
TimestampDifferenceMilliseconds (last_fail_time , now );
12302
12313
12303
- (void ) WaitLatch (MyLatch ,
12314
+ (void ) WaitLatch (& XLogCtl -> recoveryWakeupLatch ,
12304
12315
WL_LATCH_SET | WL_TIMEOUT |
12305
12316
WL_EXIT_ON_PM_DEATH ,
12306
12317
wait_time ,
12307
12318
WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL );
12308
- ResetLatch (MyLatch );
12319
+ ResetLatch (& XLogCtl -> recoveryWakeupLatch );
12309
12320
now = GetCurrentTimestamp ();
12310
12321
12311
12322
/* Handle interrupt signals of startup process */
@@ -12559,11 +12570,11 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
12559
12570
* to react to a trigger file promptly and to check if the
12560
12571
* WAL receiver is still active.
12561
12572
*/
12562
- (void ) WaitLatch (MyLatch ,
12573
+ (void ) WaitLatch (& XLogCtl -> recoveryWakeupLatch ,
12563
12574
WL_LATCH_SET | WL_TIMEOUT |
12564
12575
WL_EXIT_ON_PM_DEATH ,
12565
12576
5000L , WAIT_EVENT_RECOVERY_WAL_STREAM );
12566
- ResetLatch (MyLatch );
12577
+ ResetLatch (& XLogCtl -> recoveryWakeupLatch );
12567
12578
break ;
12568
12579
}
12569
12580
@@ -12735,8 +12746,7 @@ CheckPromoteSignal(void)
12735
12746
void
12736
12747
WakeupRecovery (void )
12737
12748
{
12738
- if (XLogCtl -> recoveryWakeupLatch )
12739
- SetLatch (XLogCtl -> recoveryWakeupLatch );
12749
+ SetLatch (& XLogCtl -> recoveryWakeupLatch );
12740
12750
}
12741
12751
12742
12752
/*
0 commit comments