[master] 2b4e631 Make default_ttl/grace doubles, polish rfc2616 ttl calculation accordingly.

Poul-Henning Kamp phk at varnish-cache.org
Thu Mar 3 16:14:33 CET 2011


commit 2b4e631769eb1fba1219b0d38fe83be56ae05a60
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Mar 3 09:39:43 2011 +0000

    Make default_ttl/grace doubles, polish rfc2616 ttl calculation
    accordingly.

diff --git a/bin/varnishd/heritage.h b/bin/varnishd/heritage.h
index c027838..06b6f5d 100644
--- a/bin/varnishd/heritage.h
+++ b/bin/varnishd/heritage.h
@@ -71,7 +71,7 @@ struct params {
 	gid_t			gid;
 
 	/* TTL used for lack of anything better */
-	unsigned		default_ttl;
+	double			default_ttl;
 
 	/* Maximum concurrent sessions */
 	unsigned		max_sess;
@@ -163,7 +163,7 @@ struct params {
 	unsigned		diag_bitmap;
 
 	/* Default grace period */
-	unsigned		default_grace;
+	double			default_grace;
 
 	/* Log hash string to shm */
 	unsigned		log_hash;
diff --git a/bin/varnishd/mgt_param.c b/bin/varnishd/mgt_param.c
index 201aaab..1f7eb50 100644
--- a/bin/varnishd/mgt_param.c
+++ b/bin/varnishd/mgt_param.c
@@ -502,7 +502,8 @@ static const struct parspec input_parspec[] = {
 		"The unprivileged group to run as.",
 		MUST_RESTART,
 		MAGIC_INIT_STRING },
-	{ "default_ttl", tweak_uint, &master.default_ttl, 0, UINT_MAX,
+	{ "default_ttl", tweak_timeout_double, &master.default_ttl,
+		0, UINT_MAX,
 		"The TTL assigned to objects if neither the backend nor "
 		"the VCL code assigns one.\n"
 		"Objects already cached will not be affected by changes "
@@ -573,7 +574,8 @@ static const struct parspec input_parspec[] = {
 		"Maximum is 65535 bytes.",
 		0,
 		"255", "bytes" },
-	{ "default_grace", tweak_uint, &master.default_grace, 0, UINT_MAX,
+	{ "default_grace", tweak_timeout_double, &master.default_grace,
+		0, UINT_MAX,
 		"Default grace period.  We will deliver an object "
 		"this long after it has expired, provided another thread "
 		"is attempting to get a new copy.\n"
diff --git a/bin/varnishd/rfc2616.c b/bin/varnishd/rfc2616.c
index 42d9856..1c07751 100644
--- a/bin/varnishd/rfc2616.c
+++ b/bin/varnishd/rfc2616.c
@@ -71,9 +71,9 @@ SVNID("$Id$")
 double
 RFC2616_Ttl(const struct sess *sp)
 {
-	int ttl;
+	double ttl;
 	unsigned max_age, age;
-	double h_date, h_expires, ttd;
+	double h_date, h_expires;
 	char *p;
 	const struct http *hp;
 
@@ -84,7 +84,6 @@ RFC2616_Ttl(const struct sess *sp)
 	ttl = params->default_ttl;
 
 	max_age = age = 0;
-	ttd = 0;
 	h_expires = 0;
 	h_date = 0;
 
@@ -116,6 +115,8 @@ RFC2616_Ttl(const struct sess *sp)
 
 		if (http_GetHdr(hp, H_Expires, &p))
 			h_expires = TIM_parse(p);
+
+		/* No expire header, fall back to default */
 		if (h_expires == 0)
 			break;
 
@@ -129,8 +130,7 @@ RFC2616_Ttl(const struct sess *sp)
 		}
 
 		if (h_date == 0 ||
-		    (h_date < sp->wrk->entered + params->clock_skew &&
-		    h_date + params->clock_skew > sp->wrk->entered)) {
+		    fabs(h_date - sp->wrk->entered) < params->clock_skew) {
 			/*
 			 * If we have no Date: header or if it is
 			 * sufficiently close to our clock we will
@@ -139,27 +139,22 @@ RFC2616_Ttl(const struct sess *sp)
 			if (h_expires < sp->wrk->entered)
 				ttl = 0;
 			else
-				ttd = h_expires;
+				ttl = h_expires - sp->wrk->entered;
 			break;
+		} else {
+			/*
+			 * But even if the clocks are out of whack we can still
+			 * derive a relative time from the two headers.
+			 * (the negative ttl case is caught above)
+			 */
+			ttl = (int)(h_expires - h_date);
 		}
 
-		/*
-		 * But even if the clocks are out of whack we can still
-		 * derive a relative time from the two headers.
-		 * (the negative ttl case is caught above)
-		 */
-		ttl = (int)(h_expires - h_date);
-
 	} while (0);
 
-	if (ttd > 0)
-		ttl = ttd - sp->wrk->entered;
-
 	/* calculated TTL, Our time, Date, Expires, max-age, age */
-	WSP(sp, SLT_TTL, "%u RFC %d %d %d %d %u %u", sp->xid,
-	    ttd ? (int)(ttl) : 0,
-	    (int)sp->wrk->entered, (int)h_date,
-	    (int)h_expires, max_age, age);
+	WSP(sp, SLT_TTL, "%u RFC %g %g %g %g %u %u", sp->xid,
+	    ttl, sp->wrk->entered, h_date, h_expires, max_age, age);
 
 	return (ttl);
 }



More information about the varnish-commit mailing list