[4.0] 9919320 Use the time we get the content from the backend as the origin time of objects.

Martin Blix Grydeland martin at varnish-software.com
Tue Jun 24 11:31:37 CEST 2014


commit 9919320874d90c1a99e3a7fe9172c63fa8c24159
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Apr 14 17:09:20 2014 +0200

    Use the time we get the content from the backend as the origin time of objects.
    
    Before, the origin time for the objects was defined as the time we
    received the full request from the client that initiated the
    fetch. Now we use the time we received the response headers from the
    backend.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c8d8d89..b0740c1 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -532,7 +532,6 @@ struct busyobj {
 	 */
 	unsigned		refcount;
 	int			retries;
-	double			t_fetch;
 	struct req		*req;
 
 	uint8_t			*vary;
@@ -1240,7 +1239,7 @@ int WS_Overflowed(const struct ws *ws);
 void *WS_Printf(struct ws *ws, const char *fmt, ...) __printflike(2, 3);
 
 /* rfc2616.c */
-void RFC2616_Ttl(struct busyobj *);
+void RFC2616_Ttl(struct busyobj *, double now);
 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_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 22f6441..45e2845 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -148,8 +148,6 @@ VBO_GetBusyObj(struct worker *wrk, const struct req *req)
 	bo->vcl = req->vcl;
 	VCL_Ref(bo->vcl);
 
-	bo->t_fetch = req->t_req;
-	assert(!isnan(bo->t_fetch) && bo->t_fetch != 0.);
 	bo->t_first = bo->t_prev = NAN;
 
 	return (bo);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 3091d29..2bb5feb 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -347,7 +347,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 	 * What does RFC2616 think about TTL ?
 	 */
 	EXP_Clr(&bo->exp);
-	RFC2616_Ttl(bo);
+	RFC2616_Ttl(bo, now);
 
 	/* private objects have negative TTL */
 	if (bo->fetch_objcore->flags & OC_F_PRIVATE)
@@ -670,7 +670,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 	HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
 	http_SetResp(bo->beresp, "HTTP/1.1", 503, "Backend fetch failed");
 
-	bo->exp.t_origin = VTIM_real();
+	bo->exp.t_origin = bo->t_prev;
 	bo->exp.ttl = 0;
 	bo->exp.grace = 0;
 	bo->exp.keep = 0;
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 5334291..bb0a85e 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)
+RFC2616_Ttl(struct busyobj *bo, double now)
 {
 	unsigned max_age, age;
 	double h_date, h_expires;
@@ -76,8 +76,8 @@ RFC2616_Ttl(struct busyobj *bo)
 
 	hp = bo->beresp;
 
-	assert(bo->t_fetch != 0.0 && !isnan(bo->t_fetch));
-	expp->t_origin = bo->t_fetch;
+	assert(now != 0.0 && !isnan(now));
+	expp->t_origin = now;
 
 	expp->ttl = cache_param->default_ttl;
 	expp->grace = cache_param->default_grace;
@@ -154,16 +154,16 @@ RFC2616_Ttl(struct busyobj *bo)
 		}
 
 		if (h_date == 0 ||
-		    fabs(h_date - bo->t_fetch) < cache_param->clock_skew) {
+		    fabs(h_date - now) < 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 < bo->t_fetch)
+			if (h_expires < now)
 				expp->ttl = 0;
 			else
-				expp->ttl = h_expires - bo->t_fetch;
+				expp->ttl = h_expires - now;
 			break;
 		} else {
 			/*
@@ -179,7 +179,7 @@ RFC2616_Ttl(struct busyobj *bo)
 	/* 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., bo->t_fetch,
+	    expp->ttl, -1., -1., now,
 	    expp->t_origin, h_date, h_expires, max_age);
 }
 



More information about the varnish-commit mailing list