Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38cc085

Browse files
committed
Simplify main waiting loop of the archiver process
As coded, the timeout given to WaitLatch() was always equal to PGARCH_AUTOWAKE_INTERVAL, as time() was called two times repeatedly. This simplification could have been done in d75288f. While on it, this adjusts a comment in pgarch.c to describe the archiver in a more neutral way. Author: Sravan Kumar, Nathan Bossart Reviewed-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/CA+=NbjjqYE9-Lnw7H7DAiS5jebmoMikwZQb_sBP7kgBCn9q6Hg@mail.gmail.com
1 parent fbed4bc commit 38cc085

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/backend/postmaster/pgarch.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,12 @@ pgarch_waken_stop(SIGNAL_ARGS)
297297
static void
298298
pgarch_MainLoop(void)
299299
{
300-
pg_time_t last_copy_time = 0;
301300
bool time_to_stop;
302301

303302
/*
304303
* There shouldn't be anything for the archiver to do except to wait for a
305-
* signal ... however, the archiver exists to protect our data, so she
306-
* wakes up occasionally to allow herself to be proactive.
304+
* signal ... however, the archiver exists to protect our data, so it
305+
* wakes up occasionally to allow itself to be proactive.
307306
*/
308307
do
309308
{
@@ -335,30 +334,21 @@ pgarch_MainLoop(void)
335334

336335
/* Do what we're here for */
337336
pgarch_ArchiverCopyLoop();
338-
last_copy_time = time(NULL);
339337

340338
/*
341339
* Sleep until a signal is received, or until a poll is forced by
342-
* PGARCH_AUTOWAKE_INTERVAL having passed since last_copy_time, or
343-
* until postmaster dies.
340+
* PGARCH_AUTOWAKE_INTERVAL, or until postmaster dies.
344341
*/
345342
if (!time_to_stop) /* Don't wait during last iteration */
346343
{
347-
pg_time_t curtime = (pg_time_t) time(NULL);
348-
int timeout;
349-
350-
timeout = PGARCH_AUTOWAKE_INTERVAL - (curtime - last_copy_time);
351-
if (timeout > 0)
352-
{
353-
int rc;
354-
355-
rc = WaitLatch(MyLatch,
356-
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
357-
timeout * 1000L,
358-
WAIT_EVENT_ARCHIVER_MAIN);
359-
if (rc & WL_POSTMASTER_DEATH)
360-
time_to_stop = true;
361-
}
344+
int rc;
345+
346+
rc = WaitLatch(MyLatch,
347+
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
348+
PGARCH_AUTOWAKE_INTERVAL * 1000L,
349+
WAIT_EVENT_ARCHIVER_MAIN);
350+
if (rc & WL_POSTMASTER_DEATH)
351+
time_to_stop = true;
362352
}
363353

364354
/*

0 commit comments

Comments
 (0)