Commit 229d3380 authored by Alvaro Herrera's avatar Alvaro Herrera

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.
parent a115bfe3
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.43 2007/05/02 15:47:14 alvherre Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.44 2007/05/02 18:27:57 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -549,8 +549,6 @@ AutoVacLauncherMain(int argc, char *argv[]) ...@@ -549,8 +549,6 @@ AutoVacLauncherMain(int argc, char *argv[])
if (can_launch && AutoVacuumShmem->av_startingWorker != INVALID_OFFSET) if (can_launch && AutoVacuumShmem->av_startingWorker != INVALID_OFFSET)
{ {
long secs;
int usecs;
WorkerInfo worker = (WorkerInfo) MAKE_PTR(AutoVacuumShmem->av_startingWorker); WorkerInfo worker = (WorkerInfo) MAKE_PTR(AutoVacuumShmem->av_startingWorker);
if (current_time == 0) if (current_time == 0)
...@@ -566,11 +564,8 @@ AutoVacLauncherMain(int argc, char *argv[]) ...@@ -566,11 +564,8 @@ AutoVacLauncherMain(int argc, char *argv[])
* startingWorker pointer before trying to connect; only low-level * startingWorker pointer before trying to connect; only low-level
* problems, like fork() failure, can get us here. * problems, like fork() failure, can get us here.
*/ */
TimestampDifference(worker->wi_launchtime, current_time, if (TimestampDifferenceExceeds(worker->wi_launchtime, current_time,
&secs, &usecs); autovacuum_naptime * 1000))
/* ignore microseconds, as they cannot make any difference */
if (secs > autovacuum_naptime)
{ {
LWLockRelease(AutovacuumLock); LWLockRelease(AutovacuumLock);
LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE); LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
...@@ -618,13 +613,13 @@ AutoVacLauncherMain(int argc, char *argv[]) ...@@ -618,13 +613,13 @@ AutoVacLauncherMain(int argc, char *argv[])
if (elem != NULL) if (elem != NULL)
{ {
avl_dbase *avdb = DLE_VAL(elem); avl_dbase *avdb = DLE_VAL(elem);
long secs;
int usecs;
TimestampDifference(current_time, avdb->adl_next_worker, &secs, &usecs);
/* do we have to start a worker? */ /*
if (secs <= 0 && usecs <= 0) * launch a worker if next_worker is right now or it is in the
* past
*/
if (TimestampDifferenceExceeds(avdb->adl_next_worker,
current_time, 0))
launch_worker(current_time); launch_worker(current_time);
} }
else else
...@@ -1037,22 +1032,15 @@ do_start_worker(void) ...@@ -1037,22 +1032,15 @@ do_start_worker(void)
if (dbp->adl_datid == tmp->adw_datid) if (dbp->adl_datid == tmp->adw_datid)
{ {
TimestampTz curr_plus_naptime;
TimestampTz next = dbp->adl_next_worker;
curr_plus_naptime =
TimestampTzPlusMilliseconds(current_time,
autovacuum_naptime * 1000);
/* /*
* What we want here if to skip if next_worker falls between * Skip this database if its next_worker value falls between
* the current time and the current time plus naptime. * the current time and the current time plus naptime.
*/ */
if (timestamp_cmp_internal(current_time, next) > 0) if (TimestampDifferenceExceeds(current_time,
skipit = false; dbp->adl_next_worker, 0) &&
else if (timestamp_cmp_internal(next, curr_plus_naptime) > 0) !TimestampDifferenceExceeds(current_time,
skipit = false; dbp->adl_next_worker,
else autovacuum_naptime * 1000))
skipit = true; skipit = true;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment