[master] cbe8047 Reintroduce hit-for-pass with new and better syntax:

Poul-Henning Kamp phk at FreeBSD.org
Wed Feb 22 14:04:05 CET 2017


commit cbe804760d78b917fbbb8a1d69b2236a2d98a028
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Feb 22 10:40:58 2017 +0000

    Reintroduce hit-for-pass with new and better syntax:
    
    	sub vcl_backend_response {
                    return (pass(2s));
            }

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 9433bcf..2b89ff4 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -471,6 +471,11 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 
 	if (bo->do_esi)
 		bo->do_stream = 0;
+	if (wrk->handling == VCL_RET_PASS) {
+		bo->fetch_objcore->flags |= OC_F_HFP;
+		bo->uncacheable = 1;
+		wrk->handling = VCL_RET_DELIVER;
+	}
 	if (bo->do_pass || bo->uncacheable)
 		bo->fetch_objcore->flags |= OC_F_PASS;
 
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 51423f3..d5eeff7 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -436,7 +436,10 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			/* If still valid, use it */
 			assert(oh->refcnt > 1);
 			assert(oc->objhead == oh);
-			if (oc->flags & OC_F_PASS) {
+			if (oc->flags & OC_F_HFP) {
+				wrk->stats->cache_hitpass++;
+				oc = NULL;
+			} else if (oc->flags & OC_F_PASS) {
 				wrk->stats->cache_hitpass++;
 				oc = NULL;
 				*bocp = hsh_insert_busyobj(wrk, oh);
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index b2a58a1..0e9b72f 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -427,10 +427,13 @@ cnt_lookup(struct worker *wrk, struct req *req)
 	if (lr == HSH_MISS) {
 		/* Found nothing */
 		AZ(oc);
-		AN(busy);
-		AN(busy->flags & OC_F_BUSY);
-		req->objcore = busy;
-		req->req_step = R_STP_MISS;
+		if (busy != NULL) {
+			AN(busy->flags & OC_F_BUSY);
+			req->objcore = busy;
+			req->req_step = R_STP_MISS;
+		} else {
+			req->req_step = R_STP_PASS;
+		}
 		return (REQ_FSM_MORE);
 	}
 
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index d865891..efc877f 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -85,6 +85,21 @@ VRT_acl_match(VRT_CTX, VCL_ACL acl, VCL_IP ip)
 	return (acl->match(ctx, ip));
 }
 
+void
+VRT_hit_for_pass(VRT_CTX, VCL_DURATION d)
+{
+	struct objcore *oc;
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+	oc = ctx->bo->fetch_objcore;
+	oc->ttl = d;
+	oc->grace = 0.0;
+	oc->keep = 0.0;
+	VSLb(ctx->vsl, SLT_TTL, "HFP %.0f %.0f %.0f %.0f",
+	    oc->ttl, oc->grace, oc->keep, oc->t_origin);
+}
+
 /*--------------------------------------------------------------------*/
 
 struct http *
diff --git a/bin/varnishtest/tests/c00081.vtc b/bin/varnishtest/tests/c00081.vtc
new file mode 100644
index 0000000..f119570
--- /dev/null
+++ b/bin/varnishtest/tests/c00081.vtc
@@ -0,0 +1,46 @@
+varnishtest "Hit-for-pass (mk II)"
+
+server s1 {
+	rxreq
+	txresp -hdr "foo: 1"
+	rxreq
+	txresp -hdr "foo: 2"
+	rxreq
+	txresp -hdr "foo: 3"
+} -start
+
+varnish v1 -vcl+backend {
+
+	sub vcl_miss {
+		set req.http.miss = "True";
+	}
+	sub vcl_pass {
+		set req.http.pass = "True";
+	}
+
+	sub vcl_backend_response {
+		return (pass(2s));
+	}
+
+	sub vcl_deliver {
+		set resp.http.miss = req.http.miss;
+		set resp.http.pass = req.http.pass;
+	}
+
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.miss == True
+
+	txreq
+	rxresp
+	expect resp.http.pass == True
+
+	delay 3
+
+	txreq
+	rxresp
+	expect resp.http.miss == True
+} -run
diff --git a/include/tbl/oc_flags.h b/include/tbl/oc_flags.h
index 2e231c7..78059aa 100644
--- a/include/tbl/oc_flags.h
+++ b/include/tbl/oc_flags.h
@@ -30,6 +30,7 @@
 
 OC_FLAG(BUSY,		busy,		(1<<1))
 OC_FLAG(PASS,		pass,		(1<<2))
+OC_FLAG(HFP,		hfp,		(1<<3))
 OC_FLAG(ABANDON,	abandon,	(1<<4))
 OC_FLAG(PRIVATE,	private,	(1<<5))
 OC_FLAG(FAILED,		failed,		(1<<6))
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index a9ff86b..604970e 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -134,7 +134,7 @@ returns = (
 	),
 	('backend_response',
 		"B",
-		('fail', 'deliver', 'retry', 'abandon')
+		('fail', 'deliver', 'retry', 'abandon', 'pass')
 	),
 	('backend_error',
 		"B",



More information about the varnish-commit mailing list