[master] 2fc2e84 Even more cleanup.
Poul-Henning Kamp
phk at varnish-cache.org
Wed Oct 9 23:54:46 CEST 2013
commit 2fc2e842fa475da846a947840a18bc310f37a034
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Oct 9 21:53:11 2013 +0000
Even more cleanup.
Now EXP_Rearm() can take the timers to change.
Close a race where we could have an object be both born and killed
in the same slot on the inbox.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 5c249f5..b606f49 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -909,7 +909,8 @@ double EXP_Ttl(const struct req *, const struct object*);
void EXP_Insert(struct objcore *oc);
void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
void EXP_Init(void);
-void EXP_Rearm(const struct object *o);
+void EXP_Rearm(struct object *o, double now, double ttl, double grace,
+ double keep);
int EXP_Touch(struct objcore *oc);
int EXP_NukeOne(struct busyobj *, struct lru *lru);
void EXP_NukeLRU(struct worker *wrk, struct vsl_log *vsl, struct lru *lru);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index dbad851..3fd7bb2 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -62,6 +62,7 @@
#include "config.h"
+#include <math.h>
#include <pcre.h>
#include <stdio.h>
@@ -907,13 +908,9 @@ ban_check_object(struct object *o, struct vsl_log *vsl,
oc_updatemeta(oc);
return (0);
} else {
- EXP_Clr(&o->exp);
oc->ban = NULL;
- oc_updatemeta(oc);
- /* BAN also changed, but that is not important any more */
- /* XXX: no req in lurker */
VSLb(vsl, SLT_ExpBan, "%u was banned", o->vxid);
- EXP_Rearm(o);
+ EXP_Rearm(o, o->exp.t_origin, 0, 0, 0); // XXX fake now
return (1);
}
}
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 794f6c7..a6c802a 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -215,7 +215,7 @@ EXP_Touch(struct objcore *oc)
*/
void
-EXP_Rearm(const struct object *o)
+EXP_Rearm(struct object *o, double now, double ttl, double grace, double keep)
{
struct objcore *oc;
struct lru *lru;
@@ -227,6 +227,13 @@ EXP_Rearm(const struct object *o)
return;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+ if (!isnan(ttl))
+ o->exp.ttl = now + ttl - o->exp.t_origin;
+ if (!isnan(grace))
+ o->exp.grace = grace;
+ if (!isnan(keep))
+ o->exp.keep = keep;
+
when = exp_when(o);
VSL(SLT_ExpKill, 0, "EXP_Rearm %p %.9f %.9f 0x%x", oc,
@@ -241,7 +248,7 @@ EXP_Rearm(const struct object *o)
Lck_Lock(&lru->mtx);
AN(oc->flags & OC_F_EXP);
- if (when < 0)
+ if (!isnan(now) && when <= now)
oc->flags |= OC_F_DYING;
else
oc->flags |= OC_F_MOVE;
@@ -422,9 +429,13 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now)
Lck_Unlock(&lru->mtx);
if (flags & OC_F_DYING) {
- assert(oc->timer_idx != BINHEAP_NOIDX);
- binheap_delete(ep->heap, oc->timer_idx);
- assert(oc->timer_idx == BINHEAP_NOIDX);
+ VSLb(&ep->vsl, SLT_ExpKill, "EXP_KILL %p %.9f 0x%x", oc,
+ oc->timer_when, oc->flags);
+ if (!(flags & OC_F_INSERT)) {
+ assert(oc->timer_idx != BINHEAP_NOIDX);
+ binheap_delete(ep->heap, oc->timer_idx);
+ assert(oc->timer_idx == BINHEAP_NOIDX);
+ }
(void)HSH_DerefObjCore(&ep->wrk->stats, &oc);
return;
}
@@ -437,7 +448,7 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now)
}
VSLb(&ep->vsl, SLT_ExpKill, "EXP_WHEN %p %.9f 0x%x", oc,
- oc->timer_when, oc->flags);
+ oc->timer_when, flags);
/*
* XXX: There are some pathological cases here, were we
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index ce98926..5b90f94 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -61,6 +61,7 @@
#include "hash/hash_slinger.h"
#include "vsha256.h"
+#include "vtim.h"
static const struct hash_slinger *hash;
static struct objhead *private_oh;
@@ -558,6 +559,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, double ttl, double grace)
struct objcore *oc, **ocp;
unsigned spc, nobj, n;
struct object *o;
+ double now;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
@@ -566,10 +568,11 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, double ttl, double grace)
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
nobj = 0;
+ now = VTIM_real();
VTAILQ_FOREACH(oc, &oh->objcs, list) {
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
assert(oc->objhead == oh);
- if (oc->flags & OC_F_BUSY) {
+ if (oc->flags & (OC_F_BUSY|OC_F_DYING)) {
/*
* We cannot purge busy objects here, because their
* owners have special rights to them, and may nuke
@@ -578,6 +581,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, double ttl, double grace)
*/
continue;
}
+ xxxassert(spc > sizeof *ocp);
(void)oc_getobj(&wrk->stats, oc);
/* XXX: still needed ? */
@@ -589,11 +593,6 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, double ttl, double grace)
}
Lck_Unlock(&oh->mtx);
- /* NB: inverse test to catch NAN also */
- if (!(ttl > 0.))
- ttl = -1.;
- if (!(grace > 0.))
- grace = -1.;
for (n = 0; n < nobj; n++) {
oc = ocp[n];
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -601,9 +600,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, double ttl, double grace)
if (o == NULL)
continue;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
- o->exp.ttl = ttl;
- o->exp.grace = grace;
- EXP_Rearm(o);
+ EXP_Rearm(o, now, ttl, grace, NAN); // XXX: Keep ?
(void)HSH_DerefObj(&wrk->stats, &o);
}
WS_Release(wrk->aws, 0);
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 3e0a73e..ec97408 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -30,6 +30,7 @@
*/
#include "config.h"
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -478,12 +479,12 @@ VRT_r_##which##_##fld(const struct vrt_ctx *ctx) \
}
VRT_DO_EXP(obj, ctx->req->obj->exp, grace, 0, ctx->req->t_req,
- EXP_Rearm(ctx->req->obj);)
+ EXP_Rearm(ctx->req->obj, ctx->req->t_req, NAN, NAN, NAN);)
VRT_DO_EXP(obj, ctx->req->obj->exp, ttl,
(ctx->req->t_req - ctx->req->obj->exp.t_origin), ctx->req->t_req,
- EXP_Rearm(ctx->req->obj);)
+ EXP_Rearm(ctx->req->obj, ctx->req->t_req, NAN, NAN, NAN);)
VRT_DO_EXP(obj, ctx->req->obj->exp, keep, 0, ctx->req->t_req,
- EXP_Rearm(ctx->req->obj);)
+ EXP_Rearm(ctx->req->obj, ctx->req->t_req, NAN, NAN, NAN);)
VRT_DO_EXP(beresp, ctx->bo->exp, grace, 0, ctx->bo->exp.t_origin,)
VRT_DO_EXP(beresp, ctx->bo->exp, ttl, 0, ctx->bo->exp.t_origin,)
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 5bdba03..e57a758 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -34,6 +34,7 @@
#include "config.h"
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -471,7 +472,7 @@ smp_oc_getobj(struct dstat *ds, struct objcore *oc)
oc->flags &= ~OC_F_NEEDFIXUP;
}
Lck_Unlock(&sg->sc->mtx);
- EXP_Rearm(o);
+ EXP_Rearm(o, NAN, NAN, NAN, NAN); // XXX: Shouldn't be needed
return (o);
}
More information about the varnish-commit
mailing list