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

Encapsulate the calculation of ttl and grace times in functions

in cache_expire.c

All this interior decoration should make it less painful to add
yet a timer for IMS processing.
parent f04a08e8
...@@ -638,7 +638,8 @@ double EXP_Get_ttl(const struct exp *e); ...@@ -638,7 +638,8 @@ double EXP_Get_ttl(const struct exp *e);
void EXP_Set_grace(struct exp *e, double v); void EXP_Set_grace(struct exp *e, double v);
void EXP_Set_ttl(struct exp *e, double v); void EXP_Set_ttl(struct exp *e, double v);
double EXP_Grace(double g); double EXP_Grace(const struct sess *, const struct object*);
double EXP_Ttl(const struct sess *, const struct object*);
void EXP_Insert(struct object *o); void EXP_Insert(struct object *o);
void EXP_Inject(struct objcore *oc, struct lru *lru, double when); void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
void EXP_Init(void); void EXP_Init(void);
......
...@@ -71,7 +71,7 @@ EXP_Set_grace(struct exp *e, double v) ...@@ -71,7 +71,7 @@ EXP_Set_grace(struct exp *e, double v)
if (v > 0.) if (v > 0.)
e->grace = v; e->grace = v;
else else
e->grace = NAN; e->grace = -1.;
} }
double double
...@@ -89,7 +89,7 @@ EXP_Set_ttl(struct exp *e, double v) ...@@ -89,7 +89,7 @@ EXP_Set_ttl(struct exp *e, double v)
e->ttl = v; e->ttl = v;
else { else {
e->ttl = -1.; e->ttl = -1.;
e->grace = NAN; e->grace = -1.;
} }
} }
...@@ -100,12 +100,33 @@ EXP_Get_ttl(const struct exp *e) ...@@ -100,12 +100,33 @@ EXP_Get_ttl(const struct exp *e)
return (e->ttl > 0. ? e->ttl : -1.); return (e->ttl > 0. ? e->ttl : -1.);
} }
/*--------------------------------------------------------------------
* Calculate when an object is out of ttl or grace, possibly constrained
* by per-session limits.
*/
double
EXP_Grace(const struct sess *sp, const struct object *o)
{
double r;
r = (double)params->default_grace;
if (o->exp.grace > 0.)
r = o->exp.grace;
if (sp != NULL && sp->exp.grace > 0. && sp->exp.grace > r)
r = sp->exp.grace;
return (EXP_Ttl(sp, o) + r);
}
double double
EXP_Grace(double g) EXP_Ttl(const struct sess *sp, const struct object *o)
{ {
if (isnan(g)) double r;
return (double)(params->default_grace);
return (g); r = o->exp.ttl;
if (sp != NULL && sp->exp.ttl > 0. && sp->exp.ttl > r)
r = sp->exp.ttl;
return (o->entered + r);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -123,7 +144,7 @@ update_object_when(const struct object *o) ...@@ -123,7 +144,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->entered + o->exp.ttl + EXP_Grace(o->exp.grace); when = EXP_Grace(NULL, o);
assert(!isnan(when)); assert(!isnan(when));
if (when == oc->timer_when) if (when == oc->timer_when)
return (0); return (0);
......
...@@ -362,14 +362,14 @@ HSH_Lookup(struct sess *sp, struct objhead **poh) ...@@ -362,14 +362,14 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
continue; continue;
/* If still valid, use it */ /* If still valid, use it */
if (o->entered + o->exp.ttl >= sp->t_req) if (EXP_Ttl(sp, o) >= 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->entered + o->exp.ttl + EXP_Grace(o->exp.grace) >= sp->t_req) { if (EXP_Grace(sp, o) >= sp->t_req) {
if (grace_oc == NULL || grace_ttl < o->entered + o->exp.ttl) { if (grace_oc == NULL || grace_ttl < o->entered + o->exp.ttl) {
grace_oc = oc; grace_oc = oc;
grace_ttl = o->entered + o->exp.ttl; grace_ttl = o->entered + o->exp.ttl;
...@@ -396,7 +396,6 @@ HSH_Lookup(struct sess *sp, struct objhead **poh) ...@@ -396,7 +396,6 @@ 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->entered + o->exp.ttl + EXP_Grace(sp->exp.grace) >= sp->t_req)
oc = grace_oc; oc = grace_oc;
} }
sp->objcore = NULL; sp->objcore = NULL;
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
SVNID("$Id$") SVNID("$Id$")
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
......
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