[master] 4c00fe8 Rename "pass" in vcl_fetch to "hit_for_pass" and respect a zerp TTL from VCL.

Poul-Henning Kamp phk at varnish-cache.org
Thu Feb 17 11:18:24 CET 2011


commit 4c00fe8ca656903492dbabf144ab6a27d678e80e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Feb 17 10:15:48 2011 +0000

    Rename "pass" in vcl_fetch to "hit_for_pass" and respect a zerp TTL from VCL.
    
    Make the default VCL explictly set the TTL to two minutes, decoupling
    it from the default_ttl parameter.
    
    This makes it clear that hit-for-pass happens, and makes it possible
    to avoid the hit-for-pass object, (ie: get a plain pass) by setting
    its ttl to zero in vcl_fetch.

diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 9480db1..4a8b6ac 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -566,14 +566,11 @@ cnt_fetch(struct sess *sp)
 		pass = 1;
 		/* VCL may have fiddled this, but that doesn't help */
 		sp->wrk->ttl = sp->t_req - 1.;
-	} else if (sp->handling == VCL_RET_PASS) {
+	} else if (sp->handling == VCL_RET_HIT_FOR_PASS) {
 		/* pass from vcl_fetch{} -> hit-for-pass */
 		/* XXX: the bereq was not filtered pass... */
 		pass = 1;
 		sp->objcore->flags |= OC_F_PASS;
-		/* Enforce a minimum TTL of 1 sec (if set from VCL) */
-		if (sp->wrk->ttl <= sp->t_req)
-			sp->wrk->ttl = sp->wrk->entered + params->default_ttl;
 	} else {
 		/* regular object */
 		pass = 0;
@@ -728,7 +725,7 @@ cnt_fetch(struct sess *sp)
 		sp->restarts++;
 		sp->step = STP_RECV;
 		return (0);
-	case VCL_RET_PASS:
+	case VCL_RET_HIT_FOR_PASS:
 	case VCL_RET_DELIVER:
 		break;
 	case VCL_RET_ERROR:
diff --git a/bin/varnishd/default.vcl b/bin/varnishd/default.vcl
index 6093780..c25f560 100644
--- a/bin/varnishd/default.vcl
+++ b/bin/varnishd/default.vcl
@@ -102,14 +102,14 @@ sub vcl_miss {
 }
 
 sub vcl_fetch {
-    if (beresp.ttl <= 0s) {
-        return (pass);
-    }
-    if (beresp.http.Set-Cookie) {
-        return (pass);
-    }
-    if (beresp.http.Vary == "*") {
-        return (pass);
+    if (beresp.ttl <= 0s ||
+        beresp.http.Set-Cookie ||
+        beresp.http.Vary == "*") {
+		/*
+		 * Mark as "Hit-For-Pass" for the next 2 minutes
+		 */
+		set beresp.ttl = 120 s;
+		return (hit_for_pass);
     }
     return (deliver);
 }
diff --git a/bin/varnishtest/tests/c00011.vtc b/bin/varnishtest/tests/c00011.vtc
index f0f348d..ab03d6a 100644
--- a/bin/varnishtest/tests/c00011.vtc
+++ b/bin/varnishtest/tests/c00011.vtc
@@ -13,7 +13,7 @@ server s1 {
 
 varnish v1 -vcl+backend { 
 	sub vcl_fetch {
-		return(pass);
+		return(hit_for_pass);
 	}
 } -start
 
diff --git a/bin/varnishtest/tests/c00014.vtc b/bin/varnishtest/tests/c00014.vtc
index 3fc83e6..b06d3df 100644
--- a/bin/varnishtest/tests/c00014.vtc
+++ b/bin/varnishtest/tests/c00014.vtc
@@ -17,7 +17,7 @@ server s1 {
 
 varnish v1 -vcl+backend { 
 	sub vcl_fetch {
-		return(pass);
+		return(hit_for_pass);
 	}
 } -start
 
diff --git a/bin/varnishtest/tests/e00011.vtc b/bin/varnishtest/tests/e00011.vtc
index 9075639..5609ee1 100644
--- a/bin/varnishtest/tests/e00011.vtc
+++ b/bin/varnishtest/tests/e00011.vtc
@@ -20,7 +20,7 @@ server s1 {
 varnish v1 -vcl+backend {
 	sub vcl_fetch {
 		set beresp.do_esi = true;
-		return(pass);
+		return(hit_for_pass);
 	}
 } -start 
 
diff --git a/bin/varnishtest/tests/r00318.vtc b/bin/varnishtest/tests/r00318.vtc
index b081336..9cab6af 100644
--- a/bin/varnishtest/tests/r00318.vtc
+++ b/bin/varnishtest/tests/r00318.vtc
@@ -10,7 +10,7 @@ server s1 {
 varnish v1 -vcl+backend {
 	sub vcl_fetch {
 		set beresp.do_esi = true;
-		return(pass);
+		return(hit_for_pass);
 	}
 } -start
 
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index d6f75e4..6e27946 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -91,7 +91,7 @@ returns =(
 	('hash',	('hash',)),
 	('miss',	('error', 'restart', 'pass', 'fetch',)),
 	('hit',		('error', 'restart', 'pass', 'deliver',)),
-	('fetch',	('error', 'restart', 'pass', 'deliver',)),
+	('fetch',	('error', 'restart', 'hit_for_pass', 'deliver',)),
 	('deliver',	('restart', 'deliver',)),
 	('error',	('restart', 'deliver',)),
 )



More information about the varnish-commit mailing list