[master] fc836dd Encapsulate the calculation of ttl and grace times in functions in cache_expire.c
Poul-Henning Kamp
phk at varnish-cache.org
Wed Mar 2 22:40:51 CET 2011
commit fc836dd23d4aa035ee50067e54cfe3ba6268ae16
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Mar 2 21:40:00 2011 +0000
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.
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index dfeb6be..f317e57 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -638,7 +638,8 @@ double EXP_Get_ttl(const struct exp *e);
void EXP_Set_grace(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_Inject(struct objcore *oc, struct lru *lru, double when);
void EXP_Init(void);
diff --git a/bin/varnishd/cache_expire.c b/bin/varnishd/cache_expire.c
index 3c5f661..b586922 100644
--- a/bin/varnishd/cache_expire.c
+++ b/bin/varnishd/cache_expire.c
@@ -71,7 +71,7 @@ EXP_Set_grace(struct exp *e, double v)
if (v > 0.)
e->grace = v;
else
- e->grace = NAN;
+ e->grace = -1.;
}
double
@@ -89,7 +89,7 @@ EXP_Set_ttl(struct exp *e, double v)
e->ttl = v;
else {
e->ttl = -1.;
- e->grace = NAN;
+ e->grace = -1.;
}
}
@@ -100,12 +100,33 @@ EXP_Get_ttl(const struct exp *e)
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
-EXP_Grace(double g)
+EXP_Ttl(const struct sess *sp, const struct object *o)
{
- if (isnan(g))
- return (double)(params->default_grace);
- return (g);
+ double r;
+
+ 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)
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
Lck_AssertHeld(&exp_mtx);
- when = o->entered + o->exp.ttl + EXP_Grace(o->exp.grace);
+ when = EXP_Grace(NULL, o);
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 56528ab..ea07f2b 100644
--- a/bin/varnishd/cache_hash.c
+++ b/bin/varnishd/cache_hash.c
@@ -362,14 +362,14 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
continue;
/* If still valid, use it */
- if (o->entered + o->exp.ttl >= sp->t_req)
+ if (EXP_Ttl(sp, o) >= sp->t_req)
break;
/*
* Remember any matching objects inside their grace period
* 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) {
grace_oc = oc;
grace_ttl = o->entered + o->exp.ttl;
@@ -396,8 +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->entered + o->exp.ttl + EXP_Grace(sp->exp.grace) >= sp->t_req)
- oc = grace_oc;
+ oc = grace_oc;
}
sp->objcore = NULL;
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index e943526..779af7b 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -34,7 +34,6 @@
SVNID("$Id$")
#include <stdio.h>
-#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
More information about the varnish-commit
mailing list