[master] d6b3388 Change the ttl variables to be relative to o->entered, since most manipulation is actually the relative value, not the absolute time.
Poul-Henning Kamp
phk at varnish-cache.org
Wed Mar 2 20:24:58 CET 2011
commit d6b338852eb23dd24cf475eb7f2884daf8703ea8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Mar 2 19:24:21 2011 +0000
Change the ttl variables to be relative to o->entered, since most
manipulation is actually the relative value, not the absolute time.
diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c
index a14c54e..241001b 100644
--- a/bin/varnishd/cache_ban.c
+++ b/bin/varnishd/cache_ban.c
@@ -475,8 +475,8 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req)
oc_updatemeta(oc);
return (0);
} else {
- o->exp.ttl = 0;
- o->exp.grace = 0;
+ o->exp.ttl = -1.;
+ o->exp.grace = -1.;
oc->ban = NULL;
oc_updatemeta(oc);
/* BAN also changed, but that is not important any more */
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index f5e7718..34be2c6 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -543,13 +543,13 @@ cnt_fetch(struct sess *sp)
case 404: /* Not Found */
break;
default:
- sp->wrk->exp.ttl = sp->t_req - 1.;
+ sp->wrk->exp.ttl = -1.;
break;
}
/* pass from vclrecv{} has negative TTL */
if (sp->objcore == NULL)
- sp->wrk->exp.ttl = sp->t_req - 1.;
+ sp->wrk->exp.ttl = -1.;
sp->wrk->do_esi = 0;
sp->wrk->exp.grace = NAN;
@@ -564,7 +564,7 @@ cnt_fetch(struct sess *sp)
/* This is a pass from vcl_recv */
pass = 1;
/* VCL may have fiddled this, but that doesn't help */
- sp->wrk->exp.ttl = sp->t_req - 1.;
+ sp->wrk->exp.ttl = -1.;
} else if (sp->handling == VCL_RET_HIT_FOR_PASS) {
/* pass from vcl_fetch{} -> hit-for-pass */
/* XXX: the bereq was not filtered pass... */
@@ -653,8 +653,7 @@ cnt_fetch(struct sess *sp)
*/
l += strlen("Content-Length: XxxXxxXxxXxxXxxXxx") + sizeof(void *);
- if (sp->wrk->exp.ttl < sp->t_req + params->shortlived ||
- sp->objcore == NULL)
+ if (sp->wrk->exp.ttl < params->shortlived || sp->objcore == NULL)
sp->wrk->storage_hint = TRANSIENT_STORAGE;
sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
diff --git a/bin/varnishd/cache_expire.c b/bin/varnishd/cache_expire.c
index 2393ca5..60392c5 100644
--- a/bin/varnishd/cache_expire.c
+++ b/bin/varnishd/cache_expire.c
@@ -80,7 +80,7 @@ update_object_when(const struct object *o)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
Lck_AssertHeld(&exp_mtx);
- when = o->exp.ttl + EXP_Grace(o->exp.grace);
+ when = o->entered + o->exp.ttl + EXP_Grace(o->exp.grace);
assert(!isnan(when));
if (when == oc->timer_when)
return (0);
diff --git a/bin/varnishd/cache_hash.c b/bin/varnishd/cache_hash.c
index 107c149..56528ab 100644
--- a/bin/varnishd/cache_hash.c
+++ b/bin/varnishd/cache_hash.c
@@ -354,7 +354,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
o = oc_getobj(sp->wrk, oc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
- if (o->exp.ttl == 0)
+ if (o->exp.ttl <= 0.)
continue;
if (BAN_CheckObject(o, sp))
continue;
@@ -362,17 +362,17 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
continue;
/* If still valid, use it */
- if (o->exp.ttl >= sp->t_req)
+ if (o->entered + o->exp.ttl >= sp->t_req)
break;
/*
* Remember any matching objects inside their grace period
* and if there are several, use the least expired one.
*/
- if (o->exp.ttl + EXP_Grace(o->exp.grace) >= sp->t_req) {
- if (grace_oc == NULL || grace_ttl < o->exp.ttl) {
+ if (o->entered + o->exp.ttl + EXP_Grace(o->exp.grace) >= sp->t_req) {
+ if (grace_oc == NULL || grace_ttl < o->entered + o->exp.ttl) {
grace_oc = oc;
- grace_ttl = o->exp.ttl;
+ grace_ttl = o->entered + o->exp.ttl;
}
}
}
@@ -396,7 +396,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
/* Or it is impossible to fetch */
o = oc_getobj(sp->wrk, grace_oc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
- if (o->exp.ttl + EXP_Grace(sp->exp.grace) >= sp->t_req)
+ if (o->entered + o->exp.ttl + EXP_Grace(sp->exp.grace) >= sp->t_req)
oc = grace_oc;
}
sp->objcore = NULL;
@@ -536,7 +536,7 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace)
Lck_Unlock(&oh->mtx);
if (ttl <= 0)
- ttl = -1;
+ ttl = -1.;
for (n = 0; n < nobj; n++) {
oc = ocp[n];
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -544,7 +544,7 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace)
if (o == NULL)
continue;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
- o->exp.ttl = sp->t_req + ttl;
+ o->exp.ttl = ttl;
if (!isnan(grace))
o->exp.grace = grace;
EXP_Rearm(o);
@@ -569,7 +569,7 @@ HSH_Drop(struct sess *sp)
o = sp->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
AssertObjPassOrBusy(o);
- o->exp.ttl = 0;
+ o->exp.ttl = -1.;
if (o->objcore != NULL) /* Pass has no objcore */
HSH_Unbusy(sp);
(void)HSH_Deref(sp->wrk, NULL, &sp->obj);
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index b562d6d..ef89cdd 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -247,17 +247,17 @@ VRT_l_beresp_ttl(const struct sess *sp, double a)
* We special case and make sure that rounding does not surprise.
*/
if (a <= 0) {
- sp->wrk->exp.ttl = sp->t_req - 1;
+ sp->wrk->exp.ttl = -1.;
sp->wrk->exp.grace = 0.;
} else
- sp->wrk->exp.ttl = sp->t_req + a;
+ sp->wrk->exp.ttl = a;
}
double
VRT_r_beresp_ttl(const struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- return (sp->wrk->exp.ttl - sp->t_req);
+ return (sp->wrk->exp.ttl);
}
/*--------------------------------------------------------------------*/
@@ -351,10 +351,10 @@ VRT_l_obj_ttl(const struct sess *sp, double a)
* We special case and make sure that rounding does not surprise.
*/
if (a <= 0) {
- sp->obj->exp.ttl = sp->t_req - 1;
- sp->obj->exp.grace = 0;
+ sp->obj->exp.ttl = -1.;
+ sp->obj->exp.grace = 0.;
} else
- sp->obj->exp.ttl = sp->t_req + a;
+ sp->obj->exp.ttl = a;
EXP_Rearm(sp->obj);
}
@@ -365,7 +365,7 @@ VRT_r_obj_ttl(const struct sess *sp)
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
if (sp->obj->objcore == NULL)
return (0.0);
- return (sp->obj->exp.ttl - sp->t_req);
+ return (sp->obj->exp.ttl);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/rfc2616.c b/bin/varnishd/rfc2616.c
index b571381..42d9856 100644
--- a/bin/varnishd/rfc2616.c
+++ b/bin/varnishd/rfc2616.c
@@ -152,16 +152,16 @@ RFC2616_Ttl(const struct sess *sp)
} while (0);
- if (ttl > 0 && ttd == 0)
- ttd = sp->wrk->entered + ttl;
+ if (ttd > 0)
+ ttl = ttd - sp->wrk->entered;
/* calculated TTL, Our time, Date, Expires, max-age, age */
WSP(sp, SLT_TTL, "%u RFC %d %d %d %d %u %u", sp->xid,
- ttd ? (int)(ttd - sp->wrk->entered) : 0,
+ ttd ? (int)(ttl) : 0,
(int)sp->wrk->entered, (int)h_date,
(int)h_expires, max_age, age);
- return (ttd);
+ return (ttl);
}
/*--------------------------------------------------------------------
diff --git a/bin/varnishd/storage_persistent.c b/bin/varnishd/storage_persistent.c
index 789f86e..c5cf339 100644
--- a/bin/varnishd/storage_persistent.c
+++ b/bin/varnishd/storage_persistent.c
@@ -493,7 +493,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
AN(sp->objcore);
- AN(sp->wrk->exp.ttl >= 0);
+ AN(sp->wrk->exp.ttl > 0.);
ltot = IRNUP(sc, ltot);
@@ -519,7 +519,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
/* We have to do this somewhere, might as well be here... */
assert(sizeof so->hash == DIGEST_LEN);
memcpy(so->hash, oc->objhead->digest, DIGEST_LEN);
- so->ttl = o->exp.ttl; /* XXX: grace? */
+ so->ttl = o->entered + o->exp.ttl; /* XXX: grace? */
so->ptr = (uint8_t*)o - sc->base;
so->ban = o->ban_t;
diff --git a/bin/varnishd/storage_persistent_silo.c b/bin/varnishd/storage_persistent_silo.c
index 86f487b..dde8347 100644
--- a/bin/varnishd/storage_persistent_silo.c
+++ b/bin/varnishd/storage_persistent_silo.c
@@ -433,8 +433,8 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
bad |= 0x100;
if(bad) {
- o->exp.ttl = 0;
- o->exp.grace = 0;
+ o->exp.ttl = -1.;
+ o->exp.grace = 0.;
so->ttl = 0;
}
@@ -464,9 +464,9 @@ smp_oc_updatemeta(struct objcore *oc)
so = smp_find_so(sg, oc);
if (isnan(o->exp.grace))
- mttl = o->exp.ttl;
+ mttl = o->entered + o->exp.ttl;
else
- mttl = - (o->exp.ttl + o->exp.grace);
+ mttl = - (o->entered + o->exp.ttl + o->exp.grace);
if (sg == sg->sc->cur_seg) {
/* Lock necessary, we might race close_seg */
More information about the varnish-commit
mailing list