From 34a892e3d7f234f84914aaa5c46579eb3fabb291 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Sat, 31 Dec 2022 15:16:54 -0800 Subject: [PATCH v10 3/4] ensure signals are dispatched in startup process on Windows --- src/backend/access/transam/xlogrecovery.c | 36 ++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index d5a81f9d83..6c4c5a18a1 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -3466,6 +3466,8 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, */ if (lastSourceFailed) { + long wait_time; + /* * Don't allow any retry loops to occur during nonblocking * readahead. Let the caller process everything that has been @@ -3556,33 +3558,39 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess, * and retry from the archive, but if it hasn't been long * since last attempt, sleep wal_retrieve_retry_interval * milliseconds to avoid busy-waiting. + * + * NB: Even if it's already been wal_retrieve_rety_interval + * milliseconds since the last attempt, we still call + * WaitLatch() with the timeout set to 0 to make sure any + * queued signals are dispatched on Windows builds. */ now = GetCurrentTimestamp(); if (!TimestampDifferenceExceeds(last_fail_time, now, wal_retrieve_retry_interval)) { - long wait_time; - wait_time = wal_retrieve_retry_interval - TimestampDifferenceMilliseconds(last_fail_time, now); elog(LOG, "waiting for WAL to become available at %X/%X", LSN_FORMAT_ARGS(RecPtr)); + } + else + wait_time = 0; - /* Do background tasks that might benefit us later. */ - KnownAssignedTransactionIdsIdleMaintenance(); + /* Do background tasks that might benefit us later. */ + KnownAssignedTransactionIdsIdleMaintenance(); - (void) WaitLatch(&XLogRecoveryCtl->recoveryWakeupLatch, - WL_LATCH_SET | WL_TIMEOUT | - WL_EXIT_ON_PM_DEATH, - wait_time, - WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL); - ResetLatch(&XLogRecoveryCtl->recoveryWakeupLatch); - now = GetCurrentTimestamp(); + (void) WaitLatch(&XLogRecoveryCtl->recoveryWakeupLatch, + WL_LATCH_SET | WL_TIMEOUT | + WL_EXIT_ON_PM_DEATH, + wait_time, + WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL); + ResetLatch(&XLogRecoveryCtl->recoveryWakeupLatch); + now = GetCurrentTimestamp(); + + /* Handle interrupt signals of startup process */ + HandleStartupProcInterrupts(); - /* Handle interrupt signals of startup process */ - HandleStartupProcInterrupts(); - } last_fail_time = now; currentSource = XLOG_FROM_ARCHIVE; break; -- 2.25.1