[master] d7f8b53 Expose to VCL whether or not a fetch is a background fetch (bgfetch)
Nils Goroll
nils.goroll at uplex.de
Tue Aug 8 11:56:06 CEST 2017
commit d7f8b531bd63fcb5bc01c680d859a969b2c4525d
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
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index e82fe5c..b8066a1 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -1020,20 +1020,28 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
AN(oc->flags & OC_F_BUSY);
CHECK_OBJ_ORNULL(oldoc, OBJCORE_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");
- }
-
bo = VBO_GetBusyObj(wrk, req);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
boc = HSH_RefBoc(oc);
CHECK_OBJ_NOTNULL(boc, BOC_MAGIC);
+ 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");
+ }
+
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);
@@ -1044,9 +1052,6 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
AN(bo->vcl);
- if (mode == VBF_PASS)
- bo->do_pass = 1;
-
oc->boc->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 ec85e64..f99b2a6 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 c7adffa..e33da79 100644
--- a/bin/varnishtest/tests/r01399.vtc
+++ b/bin/varnishtest/tests/r01399.vtc
@@ -4,6 +4,7 @@ barrier b1 cond 2
server s1 {
rxreq
+ expect req.http.Is-bg == "false"
txresp -bodylen 1
barrier b1 sync
@@ -19,11 +20,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 fe16406..5dd2bb1 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -19,6 +19,8 @@ Varnish Cache Trunk (ongoing)
``MAIN.client_req``. VSM consumers should be changed to use the
latter if necessary.
+* Added ``bereq.is_bgfetch`` which is true for background fetches.
+
================================
Varnish Cache 5.1.2 (2017-04-07)
================================
diff --git a/include/tbl/bo_flags.h b/include/tbl/bo_flags.h
index 221f9a3..5757699 100644
--- a/include/tbl/bo_flags.h
+++ b/include/tbl/bo_flags.h
@@ -39,6 +39,7 @@ BO_FLAG(uncacheable, 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, "")
#undef BO_FLAG
/*lint -restore */
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 7faf58c..13645ea 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -478,6 +478,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