Commit d6b33885 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Change the ttl variables to be relative to o->entered, since most

manipulation is actually the relative value, not the absolute time.
parent 7264c919
...@@ -475,8 +475,8 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req) ...@@ -475,8 +475,8 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req)
oc_updatemeta(oc); oc_updatemeta(oc);
return (0); return (0);
} else { } else {
o->exp.ttl = 0; o->exp.ttl = -1.;
o->exp.grace = 0; o->exp.grace = -1.;
oc->ban = NULL; oc->ban = NULL;
oc_updatemeta(oc); oc_updatemeta(oc);
/* BAN also changed, but that is not important any more */ /* BAN also changed, but that is not important any more */
......
...@@ -543,13 +543,13 @@ cnt_fetch(struct sess *sp) ...@@ -543,13 +543,13 @@ cnt_fetch(struct sess *sp)
case 404: /* Not Found */ case 404: /* Not Found */
break; break;
default: default:
sp->wrk->exp.ttl = sp->t_req - 1.; sp->wrk->exp.ttl = -1.;
break; break;
} }
/* pass from vclrecv{} has negative TTL */ /* pass from vclrecv{} has negative TTL */
if (sp->objcore == NULL) if (sp->objcore == NULL)
sp->wrk->exp.ttl = sp->t_req - 1.; sp->wrk->exp.ttl = -1.;
sp->wrk->do_esi = 0; sp->wrk->do_esi = 0;
sp->wrk->exp.grace = NAN; sp->wrk->exp.grace = NAN;
...@@ -564,7 +564,7 @@ cnt_fetch(struct sess *sp) ...@@ -564,7 +564,7 @@ cnt_fetch(struct sess *sp)
/* This is a pass from vcl_recv */ /* This is a pass from vcl_recv */
pass = 1; pass = 1;
/* VCL may have fiddled this, but that doesn't help */ /* 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) { } else if (sp->handling == VCL_RET_HIT_FOR_PASS) {
/* pass from vcl_fetch{} -> hit-for-pass */ /* pass from vcl_fetch{} -> hit-for-pass */
/* XXX: the bereq was not filtered pass... */ /* XXX: the bereq was not filtered pass... */
...@@ -653,8 +653,7 @@ cnt_fetch(struct sess *sp) ...@@ -653,8 +653,7 @@ cnt_fetch(struct sess *sp)
*/ */
l += strlen("Content-Length: XxxXxxXxxXxxXxxXxx") + sizeof(void *); l += strlen("Content-Length: XxxXxxXxxXxxXxxXxx") + sizeof(void *);
if (sp->wrk->exp.ttl < sp->t_req + params->shortlived || if (sp->wrk->exp.ttl < params->shortlived || sp->objcore == NULL)
sp->objcore == NULL)
sp->wrk->storage_hint = TRANSIENT_STORAGE; sp->wrk->storage_hint = TRANSIENT_STORAGE;
sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l, sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
......
...@@ -80,7 +80,7 @@ update_object_when(const struct object *o) ...@@ -80,7 +80,7 @@ update_object_when(const struct object *o)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
Lck_AssertHeld(&exp_mtx); 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)); assert(!isnan(when));
if (when == oc->timer_when) if (when == oc->timer_when)
return (0); return (0);
......
...@@ -354,7 +354,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh) ...@@ -354,7 +354,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
o = oc_getobj(sp->wrk, oc); o = oc_getobj(sp->wrk, oc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
if (o->exp.ttl == 0) if (o->exp.ttl <= 0.)
continue; continue;
if (BAN_CheckObject(o, sp)) if (BAN_CheckObject(o, sp))
continue; continue;
...@@ -362,17 +362,17 @@ HSH_Lookup(struct sess *sp, struct objhead **poh) ...@@ -362,17 +362,17 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
continue; continue;
/* If still valid, use it */ /* If still valid, use it */
if (o->exp.ttl >= sp->t_req) if (o->entered + o->exp.ttl >= sp->t_req)
break; break;
/* /*
* Remember any matching objects inside their grace period * Remember any matching objects inside their grace period
* and if there are several, use the least expired one. * and if there are several, use the least expired one.
*/ */
if (o->exp.ttl + EXP_Grace(o->exp.grace) >= sp->t_req) { if (o->entered + o->exp.ttl + EXP_Grace(o->exp.grace) >= sp->t_req) {
if (grace_oc == NULL || grace_ttl < o->exp.ttl) { if (grace_oc == NULL || grace_ttl < o->entered + o->exp.ttl) {
grace_oc = oc; 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) ...@@ -396,7 +396,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
/* Or it is impossible to fetch */ /* Or it is impossible to fetch */
o = oc_getobj(sp->wrk, grace_oc); o = oc_getobj(sp->wrk, grace_oc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); 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; oc = grace_oc;
} }
sp->objcore = NULL; sp->objcore = NULL;
...@@ -536,7 +536,7 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace) ...@@ -536,7 +536,7 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace)
Lck_Unlock(&oh->mtx); Lck_Unlock(&oh->mtx);
if (ttl <= 0) if (ttl <= 0)
ttl = -1; ttl = -1.;
for (n = 0; n < nobj; n++) { for (n = 0; n < nobj; n++) {
oc = ocp[n]; oc = ocp[n];
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
...@@ -544,7 +544,7 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace) ...@@ -544,7 +544,7 @@ HSH_Purge(const struct sess *sp, struct objhead *oh, double ttl, double grace)
if (o == NULL) if (o == NULL)
continue; continue;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->exp.ttl = sp->t_req + ttl; o->exp.ttl = ttl;
if (!isnan(grace)) if (!isnan(grace))
o->exp.grace = grace; o->exp.grace = grace;
EXP_Rearm(o); EXP_Rearm(o);
...@@ -569,7 +569,7 @@ HSH_Drop(struct sess *sp) ...@@ -569,7 +569,7 @@ HSH_Drop(struct sess *sp)
o = sp->obj; o = sp->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
AssertObjPassOrBusy(o); AssertObjPassOrBusy(o);
o->exp.ttl = 0; o->exp.ttl = -1.;
if (o->objcore != NULL) /* Pass has no objcore */ if (o->objcore != NULL) /* Pass has no objcore */
HSH_Unbusy(sp); HSH_Unbusy(sp);
(void)HSH_Deref(sp->wrk, NULL, &sp->obj); (void)HSH_Deref(sp->wrk, NULL, &sp->obj);
......
...@@ -247,17 +247,17 @@ VRT_l_beresp_ttl(const struct sess *sp, double a) ...@@ -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. * We special case and make sure that rounding does not surprise.
*/ */
if (a <= 0) { if (a <= 0) {
sp->wrk->exp.ttl = sp->t_req - 1; sp->wrk->exp.ttl = -1.;
sp->wrk->exp.grace = 0.; sp->wrk->exp.grace = 0.;
} else } else
sp->wrk->exp.ttl = sp->t_req + a; sp->wrk->exp.ttl = a;
} }
double double
VRT_r_beresp_ttl(const struct sess *sp) VRT_r_beresp_ttl(const struct sess *sp)
{ {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); 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) ...@@ -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. * We special case and make sure that rounding does not surprise.
*/ */
if (a <= 0) { if (a <= 0) {
sp->obj->exp.ttl = sp->t_req - 1; sp->obj->exp.ttl = -1.;
sp->obj->exp.grace = 0; sp->obj->exp.grace = 0.;
} else } else
sp->obj->exp.ttl = sp->t_req + a; sp->obj->exp.ttl = a;
EXP_Rearm(sp->obj); EXP_Rearm(sp->obj);
} }
...@@ -365,7 +365,7 @@ VRT_r_obj_ttl(const struct sess *sp) ...@@ -365,7 +365,7 @@ VRT_r_obj_ttl(const struct sess *sp)
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */
if (sp->obj->objcore == NULL) if (sp->obj->objcore == NULL)
return (0.0); return (0.0);
return (sp->obj->exp.ttl - sp->t_req); return (sp->obj->exp.ttl);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
...@@ -152,16 +152,16 @@ RFC2616_Ttl(const struct sess *sp) ...@@ -152,16 +152,16 @@ RFC2616_Ttl(const struct sess *sp)
} while (0); } while (0);
if (ttl > 0 && ttd == 0) if (ttd > 0)
ttd = sp->wrk->entered + ttl; ttl = ttd - sp->wrk->entered;
/* calculated TTL, Our time, Date, Expires, max-age, age */ /* calculated TTL, Our time, Date, Expires, max-age, age */
WSP(sp, SLT_TTL, "%u RFC %d %d %d %d %u %u", sp->xid, 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)sp->wrk->entered, (int)h_date,
(int)h_expires, max_age, age); (int)h_expires, max_age, age);
return (ttd); return (ttl);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
...@@ -493,7 +493,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot, ...@@ -493,7 +493,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC); CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
AN(sp->objcore); AN(sp->objcore);
AN(sp->wrk->exp.ttl >= 0); AN(sp->wrk->exp.ttl > 0.);
ltot = IRNUP(sc, ltot); ltot = IRNUP(sc, ltot);
...@@ -519,7 +519,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned 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... */ /* We have to do this somewhere, might as well be here... */
assert(sizeof so->hash == DIGEST_LEN); assert(sizeof so->hash == DIGEST_LEN);
memcpy(so->hash, oc->objhead->digest, 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->ptr = (uint8_t*)o - sc->base;
so->ban = o->ban_t; so->ban = o->ban_t;
......
...@@ -433,8 +433,8 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc) ...@@ -433,8 +433,8 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
bad |= 0x100; bad |= 0x100;
if(bad) { if(bad) {
o->exp.ttl = 0; o->exp.ttl = -1.;
o->exp.grace = 0; o->exp.grace = 0.;
so->ttl = 0; so->ttl = 0;
} }
...@@ -464,9 +464,9 @@ smp_oc_updatemeta(struct objcore *oc) ...@@ -464,9 +464,9 @@ smp_oc_updatemeta(struct objcore *oc)
so = smp_find_so(sg, oc); so = smp_find_so(sg, oc);
if (isnan(o->exp.grace)) if (isnan(o->exp.grace))
mttl = o->exp.ttl; mttl = o->entered + o->exp.ttl;
else else
mttl = - (o->exp.ttl + o->exp.grace); mttl = - (o->entered + o->exp.ttl + o->exp.grace);
if (sg == sg->sc->cur_seg) { if (sg == sg->sc->cur_seg) {
/* Lock necessary, we might race close_seg */ /* Lock necessary, we might race close_seg */
......
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