aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2007-05-02 18:27:57 +0000
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2007-05-02 18:27:57 +0000
commit229d33801d9e31c6eda8e54bee23ed056fd2e257 (patch)
tree958a77d8a528dc0680ba38a2b40985ad17d7930f
parenta115bfe3b97c3168f169e757dfbc3bc0a4ddf416 (diff)
downloadpostgresql-229d33801d9e31c6eda8e54bee23ed056fd2e257.tar.gz
postgresql-229d33801d9e31c6eda8e54bee23ed056fd2e257.zip
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.
-rw-r--r--src/backend/postmaster/autovacuum.c42
1 files changed, 15 insertions, 27 deletions
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 59128212d5a..c8097985042 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -10,7 +10,7 @@
*
*
* 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[])
if (can_launch && AutoVacuumShmem->av_startingWorker != INVALID_OFFSET)
{
- long secs;
- int usecs;
WorkerInfo worker = (WorkerInfo) MAKE_PTR(AutoVacuumShmem->av_startingWorker);
if (current_time == 0)
@@ -566,11 +564,8 @@ AutoVacLauncherMain(int argc, char *argv[])
* startingWorker pointer before trying to connect; only low-level
* problems, like fork() failure, can get us here.
*/
- TimestampDifference(worker->wi_launchtime, current_time,
- &secs, &usecs);
-
- /* ignore microseconds, as they cannot make any difference */
- if (secs > autovacuum_naptime)
+ if (TimestampDifferenceExceeds(worker->wi_launchtime, current_time,
+ autovacuum_naptime * 1000))
{
LWLockRelease(AutovacuumLock);
LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
@@ -618,13 +613,13 @@ AutoVacLauncherMain(int argc, char *argv[])
if (elem != NULL)
{
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);
}
else
@@ -1037,22 +1032,15 @@ do_start_worker(void)
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.
*/
- if (timestamp_cmp_internal(current_time, next) > 0)
- skipit = false;
- else if (timestamp_cmp_internal(next, curr_plus_naptime) > 0)
- skipit = false;
- else
+ if (TimestampDifferenceExceeds(current_time,
+ dbp->adl_next_worker, 0) &&
+ !TimestampDifferenceExceeds(current_time,
+ dbp->adl_next_worker,
+ autovacuum_naptime * 1000))
skipit = true;
break;