[master] e0acf69 Assign obj.keep and obj.grace from defaults on obj creation.
Poul-Henning Kamp
phk at varnish-cache.org
Fri Oct 4 09:17:35 CEST 2013
commit e0acf69d44c23acaf698ebf11e77ef02dc7d775f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Oct 4 07:17:03 2013 +0000
Assign obj.keep and obj.grace from defaults on obj creation.
Losse EXP_Grace() and EXP_Keep() functions
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 52b8d93..7880481 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -904,7 +904,6 @@ void EXP_Set_grace(struct exp *e, double v);
void EXP_Set_keep(struct exp *e, double v);
double EXP_Ttl(const struct req *, const struct object*);
-double EXP_Grace(const struct req *, const struct object*);
void EXP_Insert(const struct object *o, double now);
void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
void EXP_Init(void);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index d9225bf..de4e3e9 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -107,28 +107,6 @@ EXP_ACCESS(keep, 0.,)
* adjusted for defaults and by per-session limits.
*/
-static double
-EXP_Keep(const struct req *req, const struct object *o)
-{
- double r;
-
- r = (double)cache_param->default_keep;
- if (o->exp.keep > 0.)
- r = o->exp.keep;
- return (EXP_Ttl(req, o) + r);
-}
-
-double
-EXP_Grace(const struct req *req, const struct object *o)
-{
- double r;
-
- r = (double)cache_param->default_grace;
- if (o->exp.grace >= 0.)
- r = o->exp.grace;
- return (EXP_Ttl(req, o) + r);
-}
-
double
EXP_Ttl(const struct req *req, const struct object *o)
{
@@ -148,17 +126,14 @@ static int
update_object_when(const struct object *o)
{
struct objcore *oc;
- double when, w2;
+ double when;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
oc = o->objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
Lck_AssertHeld(&exp_mtx);
- when = EXP_Keep(NULL, o);
- w2 = EXP_Grace(NULL, o);
- if (w2 > when)
- when = w2;
+ when = o->exp.t_origin + o->exp.ttl + o->exp.grace + o->exp.keep;
assert(!isnan(when));
if (when == oc->timer_when)
return (0);
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 69735f3..66724ab 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -79,8 +79,9 @@ RFC2616_Ttl(struct busyobj *bo)
assert(bo->t_fetch != 0.0 && !isnan(bo->t_fetch));
expp->t_origin = bo->t_fetch;
- /* If all else fails, cache using default ttl */
expp->ttl = cache_param->default_ttl;
+ expp->grace = cache_param->default_grace;
+ expp->keep = cache_param->default_keep;
max_age = age = 0;
h_expires = 0;
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index f54368d..df90d7e 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -547,7 +547,7 @@ smp_allocobj(struct stevedore *stv, struct busyobj *bo,
/* 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 = EXP_Grace(NULL, o);
+ so->ttl = oc->timer_when;
so->ptr = (uint8_t*)o - sc->base;
so->ban = BAN_Time(oc->ban);
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 7ca79d6..75dee88 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -480,7 +480,6 @@ smp_oc_updatemeta(struct objcore *oc)
struct object *o;
struct smp_seg *sg;
struct smp_object *so;
- double mttl;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
o = smp_oc_getobj(NULL, oc);
@@ -490,17 +489,15 @@ smp_oc_updatemeta(struct objcore *oc)
CHECK_OBJ_NOTNULL(sg->sc, SMP_SC_MAGIC);
so = smp_find_so(sg, oc->priv2);
- mttl = EXP_Grace(NULL, o);
-
if (sg == sg->sc->cur_seg) {
/* Lock necessary, we might race close_seg */
Lck_Lock(&sg->sc->mtx);
so->ban = BAN_Time(oc->ban);
- so->ttl = mttl;
+ so->ttl = oc->timer_when;
Lck_Unlock(&sg->sc->mtx);
} else {
so->ban = BAN_Time(oc->ban);
- so->ttl = mttl;
+ so->ttl = oc->timer_when;
}
}
diff --git a/bin/varnishtest/tests/p00001.vtc b/bin/varnishtest/tests/p00001.vtc
index ac95149..e8c4aa5 100644
--- a/bin/varnishtest/tests/p00001.vtc
+++ b/bin/varnishtest/tests/p00001.vtc
@@ -13,6 +13,9 @@ varnish v1 \
-storage "-spersistent,${tmpdir}/_.per,10m" \
-vcl+backend { } -start
+varnish v1 -cliok "param.set default_grace 0"
+varnish v1 -cliok "param.set default_keep 0"
+
client c1 {
txreq -url "/"
rxresp
diff --git a/bin/varnishtest/tests/s00000.vtc b/bin/varnishtest/tests/s00000.vtc
index b5090ff..e04c960 100644
--- a/bin/varnishtest/tests/s00000.vtc
+++ b/bin/varnishtest/tests/s00000.vtc
@@ -11,6 +11,8 @@ server s1 {
} -start
varnish v1 -vcl+backend { } -start
+varnish v1 -cliok "param.set default_grace 0"
+varnish v1 -cliok "param.set default_keep 0"
client c1 {
txreq -url "/"
diff --git a/bin/varnishtest/tests/s00001.vtc b/bin/varnishtest/tests/s00001.vtc
index 44ea211..0223916 100644
--- a/bin/varnishtest/tests/s00001.vtc
+++ b/bin/varnishtest/tests/s00001.vtc
@@ -12,6 +12,9 @@ server s1 {
varnish v1 -vcl+backend { } -start
+varnish v1 -cliok "param.set default_keep 0"
+varnish v1 -cliok "param.set default_grace 0"
+
client c1 {
txreq -url "/"
rxresp
More information about the varnish-commit
mailing list