[4.1] bf167ec Expose to VCL whether or not a fetch is a background fetch (bgfetch)

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Tue Aug 22 15:11:11 CEST 2017


commit bf167ec4cec2315d8737911817d18fd3bebed55d
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Jul 21 14:18:51 2017 +0200

    Expose to VCL whether or not a fetch is a background fetch (bgfetch)
    
    The use case are cluster requests: Intra-cluster bgfetches should
    trigger a synchronous fetch on the peer-varnish in order to avoid
    additional short-lived / expired objects being created. Or, in
    other words, a bgfetch should actually get a fresh object and not
    one in grace from another cache.
    
    Merges #2376
    
    This is a back port of d7f8b531bd63fcb5b.
    
    Conflicts:
    	bin/varnishd/cache/cache_fetch.c
    	doc/changes.rst
    	include/tbl/bo_flags.h

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 8cb14fe..d36377c 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -998,16 +998,25 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
 	AN(oc->flags & OC_F_BUSY);
 	CHECK_OBJ_ORNULL(oldoc, OBJCORE_MAGIC);
 
+	bo = VBO_GetBusyObj(wrk, req);
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
-	switch(mode) {
-	case VBF_PASS:		how = "pass"; break;
-	case VBF_NORMAL:	how = "fetch"; break;
-	case VBF_BACKGROUND:	how = "bgfetch"; break;
-	default:		WRONG("Wrong fetch mode");
+	switch (mode) {
+	case VBF_PASS:
+		how = "pass";
+		bo->do_pass = 1;
+		break;
+	case VBF_NORMAL:
+		how = "fetch";
+		break;
+	case VBF_BACKGROUND:
+		how = "bgfetch";
+		bo->is_bgfetch = 1;
+		break;
+	default:
+		WRONG("Wrong fetch mode");
 	}
 
-	bo = VBO_GetBusyObj(wrk, req);
-	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	VSLb(bo->vsl, SLT_Begin, "bereq %u %s", VXID(req->vsl->wid), how);
 	VSLb(req->vsl, SLT_Link, "bereq %u %s", VXID(bo->vsl->wid), how);
 
@@ -1020,9 +1029,6 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
 
 	AN(bo->vcl);
 
-	if (mode == VBF_PASS)
-		bo->do_pass = 1;
-
 	bo->vary = req->vary_b;
 	req->vary_b = NULL;
 
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index b76c069..94441ed 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -203,6 +203,14 @@ VRT_r_beresp_##field(VRT_CTX)				\
 /*--------------------------------------------------------------------*/
 
 unsigned
+VRT_r_bereq_is_bgfetch(VRT_CTX)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
+	return (ctx->bo->is_bgfetch);
+}
+
+unsigned
 VRT_r_bereq_uncacheable(VRT_CTX)
 {
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
diff --git a/bin/varnishtest/tests/r01399.vtc b/bin/varnishtest/tests/r01399.vtc
index 5d7171a..98fff97 100644
--- a/bin/varnishtest/tests/r01399.vtc
+++ b/bin/varnishtest/tests/r01399.vtc
@@ -2,6 +2,7 @@ varnishtest "1399 race issue with bg-fetches"
 
 server s1 {
 	rxreq
+	expect req.http.Is-bg == "false"
 	txresp -bodylen 1
 
 	sema r1 sync 2
@@ -17,11 +18,15 @@ server s1 {
 	# And see if it has all its marbles still...
 	rxreq
 	expect req.url == "/"
+	expect req.http.Is-bg == "true"
 	txresp -bodylen 2
 
 } -start
 
 varnish v1 -vcl+backend {
+	sub vcl_backend_fetch {
+		set bereq.http.Is-bg = bereq.is_bgfetch;
+	}
 	sub vcl_backend_response {
 		set beresp.do_stream = false;
 		set beresp.ttl = 2s;
diff --git a/doc/changes.rst b/doc/changes.rst
index 275e336..78670a1 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -1,3 +1,9 @@
+======================================
+Varnish Cache 4.1.9-beta1 (unreleased)
+======================================
+
+* Added ``bereq.is_bgfetch`` which is true for background fetches.
+
 ================================
 Varnish Cache 4.1.8 (2017-08-02)
 ================================
diff --git a/include/tbl/bo_flags.h b/include/tbl/bo_flags.h
index fedde3f..efe7fc6 100644
--- a/include/tbl/bo_flags.h
+++ b/include/tbl/bo_flags.h
@@ -40,5 +40,6 @@ BO_FLAG(abandon,	0, 0, "")
 BO_FLAG(is_gzip,	0, 0, "")
 BO_FLAG(is_gunzip,	0, 0, "")
 BO_FLAG(was_304,	1, 0, "")
+BO_FLAG(is_bgfetch,	0, 0, "")
 
 /*lint -restore */
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 4c1645e..a370b32 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -440,6 +440,13 @@ sp_variables = [
 		backend.  Not available in pipe mode.
 		"""
 	),
+	('bereq.is_bgfetch',
+		'BOOL',
+		('backend', ),
+		(), """
+		True for background fetches.
+		"""
+	),
 	('beresp',
 		'HTTP',
 		( 'backend_response', 'backend_error'),



More information about the varnish-commit mailing list