[master] 160927b Collaps ->age and ->entered into ->t_origin. This is the time this object was created, as best we can determine it from the headers etc.

Poul-Henning Kamp phk at varnish-cache.org
Thu Oct 3 13:35:26 CEST 2013


commit 160927b690dd076702601b7407eb71bd423c62dd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 3 11:34:30 2013 +0000

    Collaps ->age and ->entered into ->t_origin.  This is the time this
    object was created, as best we can determine it from the headers etc.
    
    This is also the point from which ttls should be counted.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 4b7b90d..cd71bc6 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -292,8 +292,7 @@ struct exp {
 	double			ttl;
 	double			grace;
 	double			keep;
-	double			age;
-	double			entered;
+	double			t_origin;
 };
 
 /*--------------------------------------------------------------------*/
@@ -610,6 +609,8 @@ struct object {
 
 	/* VCL only variables */
 	long			hits;
+	double			last_use;
+
 	double			last_modified;
 
 	struct http		*http;
@@ -618,7 +619,6 @@ struct object {
 
 	struct storage		*esidata;
 
-	double			last_use;
 };
 
 /*--------------------------------------------------------------------*/
@@ -905,7 +905,7 @@ 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);
+void EXP_Insert(const struct object *o, double now);
 void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
 void EXP_Init(void);
 void EXP_Rearm(const struct object *o);
@@ -1195,7 +1195,7 @@ void *WS_Copy(struct ws *ws, const void *str, int len);
 char *WS_Snapshot(struct ws *ws);
 
 /* rfc2616.c */
-void RFC2616_Ttl(struct busyobj *, double now);
+void RFC2616_Ttl(struct busyobj *);
 enum body_status RFC2616_Body(struct busyobj *, struct dstat *);
 unsigned RFC2616_Req_Gzip(const struct http *);
 int RFC2616_Do_Cond(const struct req *sp);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index d764856..e59e26a 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -77,8 +77,7 @@ EXP_Clr(struct exp *e)
 	e->ttl = -1;
 	e->grace = -1;
 	e->keep = -1;
-	e->age = 0;
-	e->entered = 0;
+	e->t_origin = 0;
 }
 
 #define EXP_ACCESS(fld, low_val, extra)				\
@@ -142,7 +141,7 @@ EXP_Ttl(const struct req *req, const struct object *o)
 	r = o->exp.ttl;
 	if (req != NULL && req->exp.ttl > 0. && req->exp.ttl < r)
 		r = req->exp.ttl;
-	return (o->exp.entered + r);
+	return (o->exp.t_origin + r);
 }
 
 /*--------------------------------------------------------------------
@@ -216,7 +215,7 @@ EXP_Inject(struct objcore *oc, struct lru *lru, double when)
  */
 
 void
-EXP_Insert(const struct object *o)
+EXP_Insert(const struct object *o, double now)
 {
 	struct objcore *oc;
 	struct lru *lru;
@@ -226,8 +225,8 @@ EXP_Insert(const struct object *o)
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	HSH_Ref(oc);
 
-	assert(o->exp.entered != 0 && !isnan(o->exp.entered));
-	oc->last_lru = o->exp.entered;
+	assert(o->exp.t_origin != 0 && !isnan(o->exp.t_origin));
+	oc->last_lru = now;
 
 	lru = oc_getlru(oc);
 	CHECK_OBJ_NOTNULL(lru, LRU_MAGIC);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 5aca605..d65d181 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -206,7 +206,7 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)
 	 * What does RFC2616 think about TTL ?
 	 */
 	EXP_Clr(&bo->exp);
-	RFC2616_Ttl(bo, W_TIM_real(wrk));
+	RFC2616_Ttl(bo);
 
 	/* private objects have negative TTL */
 	if (bo->fetch_objcore->flags & OC_F_PRIVATE)
@@ -411,7 +411,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	if (http_GetHdr(hp, H_Last_Modified, &b))
 		obj->last_modified = VTIM_parse(b);
 	else
-		obj->last_modified = floor(bo->exp.entered);
+		obj->last_modified = floor(bo->exp.t_origin);
 
 	assert(WRW_IsReleased(wrk));
 
@@ -422,7 +422,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	assert(bo->refcount >= 1);
 
 	if (!(bo->fetch_obj->objcore->flags & OC_F_PRIVATE)) {
-		EXP_Insert(obj);
+		EXP_Insert(obj, bo->t_fetch);
 		AN(obj->objcore->ban);
 	}
 
@@ -517,7 +517,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 
 
 	if (!(bo->fetch_obj->objcore->flags & OC_F_PRIVATE)) {
-		EXP_Insert(obj);
+		EXP_Insert(obj, bo->t_fetch);
 		AN(obj->objcore->ban);
 	}
 
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 61b6621..9851584 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -343,7 +343,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 	struct objcore *oc;
 	struct objcore *exp_oc;
 	struct object *o, *exp_o;
-	double exp_entered;
+	double exp_t_origin;
 	int busy_found;
 	enum lookup_e retval;
 
@@ -393,7 +393,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 	busy_found = 0;
 	exp_o = NULL;
 	exp_oc = NULL;
-	exp_entered = 0.0;
+	exp_t_origin = 0.0;
 	o = NULL;
 	VTAILQ_FOREACH(oc, &oh->objcs, list) {
 		/* Must be at least our own ref + the objcore we examine */
@@ -438,12 +438,12 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			*ocp = oc;
 			return (HSH_HIT);
 		}
-		if (o->exp.entered > exp_entered &&
+		if (o->exp.t_origin > exp_t_origin &&
 		    !(oc->flags & OC_F_PASS)) {
 			/* record the newest object */
 			exp_oc = oc;
 			exp_o = o;
-			exp_entered = o->exp.entered;
+			exp_t_origin = o->exp.t_origin;
 		}
 	}
 
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 9807836..647ef49 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -128,7 +128,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 		    "X-Varnish: %u", req->vsl->wid & VSL_IDENTMASK);
 
 	http_PrintfHeader(req->resp, "Age: %.0f",
-	    req->obj->exp.age + req->t_resp - req->obj->exp.entered);
+	    req->t_resp - req->obj->exp.t_origin);
 
 	http_SetHeader(req->resp, "Via: 1.1 varnish");
 
@@ -217,7 +217,7 @@ cnt_error(struct worker *wrk, struct req *req)
 	CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
 	AZ(req->objcore);
 	req->obj->vxid = bo->vsl->wid;
-	req->obj->exp.entered = req->t_req;
+	req->obj->exp.t_origin = req->t_req;
 
 	h = req->obj->http;
 
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 32887a2..69735f3 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -63,7 +63,7 @@
  */
 
 void
-RFC2616_Ttl(struct busyobj *bo, double now)
+RFC2616_Ttl(struct busyobj *bo)
 {
 	unsigned max_age, age;
 	double h_date, h_expires;
@@ -76,8 +76,8 @@ RFC2616_Ttl(struct busyobj *bo, double now)
 
 	hp = bo->beresp;
 
-	assert(now != 0.0 && !isnan(now));
-	expp->entered = now;
+	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;
@@ -92,8 +92,13 @@ RFC2616_Ttl(struct busyobj *bo, double now)
 	 */
 
 	if (http_GetHdr(hp, H_Age, &p)) {
-		age = strtoul(p, NULL, 0);
-		expp->age = age;
+		/*
+		 * We deliberately run with partial results, rather than
+		 * reject the Age: header outright.  This will be future
+		 * compatible with fractional seconds.
+		 */
+		age = strtoul(p, NULL, 10);
+		expp->t_origin -= age;
 	}
 
 	if (http_GetHdr(hp, H_Expires, &p))
@@ -147,16 +152,16 @@ RFC2616_Ttl(struct busyobj *bo, double now)
 		}
 
 		if (h_date == 0 ||
-		    fabs(h_date - now) < cache_param->clock_skew) {
+		    fabs(h_date - bo->t_fetch) < cache_param->clock_skew) {
 			/*
 			 * If we have no Date: header or if it is
 			 * sufficiently close to our clock we will
 			 * trust Expires: relative to our own clock.
 			 */
-			if (h_expires < now)
+			if (h_expires < bo->t_fetch)
 				expp->ttl = 0;
 			else
-				expp->ttl = h_expires - now;
+				expp->ttl = h_expires - bo->t_fetch;
 			break;
 		} else {
 			/*
@@ -172,8 +177,8 @@ RFC2616_Ttl(struct busyobj *bo, double now)
 	/* calculated TTL, Our time, Date, Expires, max-age, age */
 	VSLb(bo->vsl, SLT_TTL,
 	    "RFC %.0f %.0f %.0f %.0f %.0f %.0f %.0f %u",
-	    expp->ttl, -1., -1., now,
-	    expp->age, h_date, h_expires, max_age);
+	    expp->ttl, -1., -1., bo->t_fetch,
+	    expp->t_origin, h_date, h_expires, max_age);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 3d691a5..9afb9a3 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -467,9 +467,9 @@ vrt_wsp_exp(struct vsl_log *vsl, double now, const struct exp *e)
 {
 	double dt;
 
-	dt = now - e->entered;
+	dt = now - e->t_origin;
 	VSLb(vsl, SLT_TTL, "VCL %.0f %.0f %.0f %.0f %.0f",
-	    e->ttl - dt, e->grace, e->keep, now, e->age + dt);
+	    e->ttl - dt, e->grace, e->keep, now, dt);
 }
 
 VRT_DO_EXP(req, ctx->req->exp, ttl, 0, )
@@ -480,7 +480,7 @@ VRT_DO_EXP(obj, ctx->req->obj->exp, grace, 0,
    EXP_Rearm(ctx->req->obj);
    vrt_wsp_exp(ctx->vsl, ctx->req->t_req, &ctx->req->obj->exp);)
 VRT_DO_EXP(obj, ctx->req->obj->exp, ttl,
-   (ctx->req->t_req - ctx->req->obj->exp.entered),
+   (ctx->req->t_req - ctx->req->obj->exp.t_origin),
    EXP_Rearm(ctx->req->obj);
    vrt_wsp_exp(ctx->vsl, ctx->req->t_req, &ctx->req->obj->exp);)
 VRT_DO_EXP(obj, ctx->req->obj->exp, keep, 0,
@@ -488,11 +488,11 @@ VRT_DO_EXP(obj, ctx->req->obj->exp, keep, 0,
    vrt_wsp_exp(ctx->vsl, ctx->req->t_req, &ctx->req->obj->exp);)
 
 VRT_DO_EXP(beresp, ctx->bo->exp, grace, 0,
-   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.entered, &ctx->bo->exp);)
+   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.t_origin, &ctx->bo->exp);)
 VRT_DO_EXP(beresp, ctx->bo->exp, ttl, 0,
-   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.entered, &ctx->bo->exp);)
+   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.t_origin, &ctx->bo->exp);)
 VRT_DO_EXP(beresp, ctx->bo->exp, keep, 0,
-   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.entered, &ctx->bo->exp);)
+   vrt_wsp_exp(ctx->vsl, ctx->bo->exp.t_origin, &ctx->bo->exp);)
 
 /*--------------------------------------------------------------------
  * req.xid
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index a8203c4..aa5d7eb 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -284,7 +284,7 @@ STV_MkObject(struct stevedore *stv, struct busyobj *bo,
 	HTTP_Setup(o->http, bo->ws_o, bo->vsl, HTTP_Obj);
 	o->http->magic = HTTP_MAGIC;
 	o->exp = bo->exp;
-	o->last_use = bo->exp.entered;
+	o->last_use = bo->t_fetch;
 	VTAILQ_INIT(&o->store);
 	bo->stats->n_object++;
 
@@ -376,9 +376,9 @@ STV_NewObject(struct busyobj *bo, const char *hint,
 		}
 	}
 
-	if (o == NULL) {
+	if (o == NULL)
 		return (NULL);
-	}
+
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	CHECK_OBJ_NOTNULL(o->objstore, STORAGE_MAGIC);
 	return (o);



More information about the varnish-commit mailing list