From 65b8d6c45cd0c2bcbbd806a5fbc9e6c07401d626 Mon Sep 17 00:00:00 2001 From: Sravan Velagandula Date: Tue, 6 Dec 2022 06:21:38 -0500 Subject: [PATCH v1] simplify wait loop in the archiver --- src/backend/postmaster/pgarch.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index fffb6a599c..3c74c0aca4 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -297,7 +297,6 @@ pgarch_waken_stop(SIGNAL_ARGS) static void pgarch_MainLoop(void) { - pg_time_t last_copy_time = 0; bool time_to_stop; /* @@ -335,30 +334,21 @@ pgarch_MainLoop(void) /* Do what we're here for */ pgarch_ArchiverCopyLoop(); - last_copy_time = time(NULL); /* * Sleep until a signal is received, or until a poll is forced by - * PGARCH_AUTOWAKE_INTERVAL having passed since last_copy_time, or - * until postmaster dies. + * PGARCH_AUTOWAKE_INTERVAL, or until postmaster dies. */ if (!time_to_stop) /* Don't wait during last iteration */ { - pg_time_t curtime = (pg_time_t) time(NULL); - int timeout; - - timeout = PGARCH_AUTOWAKE_INTERVAL - (curtime - last_copy_time); - if (timeout > 0) - { - int rc; - - rc = WaitLatch(MyLatch, - WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, - timeout * 1000L, - WAIT_EVENT_ARCHIVER_MAIN); - if (rc & WL_POSTMASTER_DEATH) - time_to_stop = true; - } + int rc; + + rc = WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, + PGARCH_AUTOWAKE_INTERVAL * 1000L, + WAIT_EVENT_ARCHIVER_MAIN); + if (rc & WL_POSTMASTER_DEATH) + time_to_stop = true; } /* -- 2.34.1