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
This commit is contained in:
parent
fbed4bc59e
commit
38cc085464
|
@ -297,13 +297,12 @@ pgarch_waken_stop(SIGNAL_ARGS)
|
||||||
static void
|
static void
|
||||||
pgarch_MainLoop(void)
|
pgarch_MainLoop(void)
|
||||||
{
|
{
|
||||||
pg_time_t last_copy_time = 0;
|
|
||||||
bool time_to_stop;
|
bool time_to_stop;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There shouldn't be anything for the archiver to do except to wait for a
|
* There shouldn't be anything for the archiver to do except to wait for a
|
||||||
* signal ... however, the archiver exists to protect our data, so she
|
* signal ... however, the archiver exists to protect our data, so it
|
||||||
* wakes up occasionally to allow herself to be proactive.
|
* wakes up occasionally to allow itself to be proactive.
|
||||||
*/
|
*/
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -335,30 +334,21 @@ pgarch_MainLoop(void)
|
||||||
|
|
||||||
/* Do what we're here for */
|
/* Do what we're here for */
|
||||||
pgarch_ArchiverCopyLoop();
|
pgarch_ArchiverCopyLoop();
|
||||||
last_copy_time = time(NULL);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sleep until a signal is received, or until a poll is forced by
|
* Sleep until a signal is received, or until a poll is forced by
|
||||||
* PGARCH_AUTOWAKE_INTERVAL having passed since last_copy_time, or
|
* PGARCH_AUTOWAKE_INTERVAL, or until postmaster dies.
|
||||||
* until postmaster dies.
|
|
||||||
*/
|
*/
|
||||||
if (!time_to_stop) /* Don't wait during last iteration */
|
if (!time_to_stop) /* Don't wait during last iteration */
|
||||||
{
|
{
|
||||||
pg_time_t curtime = (pg_time_t) time(NULL);
|
int rc;
|
||||||
int timeout;
|
|
||||||
|
|
||||||
timeout = PGARCH_AUTOWAKE_INTERVAL - (curtime - last_copy_time);
|
rc = WaitLatch(MyLatch,
|
||||||
if (timeout > 0)
|
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||||
{
|
PGARCH_AUTOWAKE_INTERVAL * 1000L,
|
||||||
int rc;
|
WAIT_EVENT_ARCHIVER_MAIN);
|
||||||
|
if (rc & WL_POSTMASTER_DEATH)
|
||||||
rc = WaitLatch(MyLatch,
|
time_to_stop = true;
|
||||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
|
||||||
timeout * 1000L,
|
|
||||||
WAIT_EVENT_ARCHIVER_MAIN);
|
|
||||||
if (rc & WL_POSTMASTER_DEATH)
|
|
||||||
time_to_stop = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue