Skip to content

Commit 229d338

Browse files
committed
Use the new TimestampDifferenceExceeds API instead of timestamp_cmp_internal
and TimestampDifference, to make coding clearer. I think this should also fix the failure to start workers in platforms with low resolution timers, as reported by Itagaki Takahiro.
1 parent a115bfe commit 229d338

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.43 2007/05/02 15:47:14 alvherre Exp $
13+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.44 2007/05/02 18:27:57 alvherre Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -549,8 +549,6 @@ AutoVacLauncherMain(int argc, char *argv[])
549549

550550
if (can_launch && AutoVacuumShmem->av_startingWorker != INVALID_OFFSET)
551551
{
552-
long secs;
553-
int usecs;
554552
WorkerInfo worker = (WorkerInfo) MAKE_PTR(AutoVacuumShmem->av_startingWorker);
555553

556554
if (current_time == 0)
@@ -566,11 +564,8 @@ AutoVacLauncherMain(int argc, char *argv[])
566564
* startingWorker pointer before trying to connect; only low-level
567565
* problems, like fork() failure, can get us here.
568566
*/
569-
TimestampDifference(worker->wi_launchtime, current_time,
570-
&secs, &usecs);
571-
572-
/* ignore microseconds, as they cannot make any difference */
573-
if (secs > autovacuum_naptime)
567+
if (TimestampDifferenceExceeds(worker->wi_launchtime, current_time,
568+
autovacuum_naptime * 1000))
574569
{
575570
LWLockRelease(AutovacuumLock);
576571
LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
@@ -618,13 +613,13 @@ AutoVacLauncherMain(int argc, char *argv[])
618613
if (elem != NULL)
619614
{
620615
avl_dbase *avdb = DLE_VAL(elem);
621-
long secs;
622-
int usecs;
623-
624-
TimestampDifference(current_time, avdb->adl_next_worker, &secs, &usecs);
625616

626-
/* do we have to start a worker? */
627-
if (secs <= 0 && usecs <= 0)
617+
/*
618+
* launch a worker if next_worker is right now or it is in the
619+
* past
620+
*/
621+
if (TimestampDifferenceExceeds(avdb->adl_next_worker,
622+
current_time, 0))
628623
launch_worker(current_time);
629624
}
630625
else
@@ -1037,22 +1032,15 @@ do_start_worker(void)
10371032

10381033
if (dbp->adl_datid == tmp->adw_datid)
10391034
{
1040-
TimestampTz curr_plus_naptime;
1041-
TimestampTz next = dbp->adl_next_worker;
1042-
1043-
curr_plus_naptime =
1044-
TimestampTzPlusMilliseconds(current_time,
1045-
autovacuum_naptime * 1000);
1046-
10471035
/*
1048-
* What we want here if to skip if next_worker falls between
1036+
* Skip this database if its next_worker value falls between
10491037
* the current time and the current time plus naptime.
10501038
*/
1051-
if (timestamp_cmp_internal(current_time, next) > 0)
1052-
skipit = false;
1053-
else if (timestamp_cmp_internal(next, curr_plus_naptime) > 0)
1054-
skipit = false;
1055-
else
1039+
if (TimestampDifferenceExceeds(current_time,
1040+
dbp->adl_next_worker, 0) &&
1041+
!TimestampDifferenceExceeds(current_time,
1042+
dbp->adl_next_worker,
1043+
autovacuum_naptime * 1000))
10561044
skipit = true;
10571045

10581046
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy