Commit d7f8b531 authored by Nils Goroll's avatar Nils Goroll

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
parent 560d2744
...@@ -1020,20 +1020,28 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc, ...@@ -1020,20 +1020,28 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
AN(oc->flags & OC_F_BUSY); AN(oc->flags & OC_F_BUSY);
CHECK_OBJ_ORNULL(oldoc, OBJCORE_MAGIC); 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); bo = VBO_GetBusyObj(wrk, req);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
boc = HSH_RefBoc(oc); boc = HSH_RefBoc(oc);
CHECK_OBJ_NOTNULL(boc, BOC_MAGIC); 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(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); 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, ...@@ -1044,9 +1052,6 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
AN(bo->vcl); AN(bo->vcl);
if (mode == VBF_PASS)
bo->do_pass = 1;
oc->boc->vary = req->vary_b; oc->boc->vary = req->vary_b;
req->vary_b = NULL; req->vary_b = NULL;
......
...@@ -202,6 +202,14 @@ VRT_r_beresp_##field(VRT_CTX) \ ...@@ -202,6 +202,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 unsigned
VRT_r_bereq_uncacheable(VRT_CTX) VRT_r_bereq_uncacheable(VRT_CTX)
{ {
......
...@@ -4,6 +4,7 @@ barrier b1 cond 2 ...@@ -4,6 +4,7 @@ barrier b1 cond 2
server s1 { server s1 {
rxreq rxreq
expect req.http.Is-bg == "false"
txresp -bodylen 1 txresp -bodylen 1
barrier b1 sync barrier b1 sync
...@@ -19,11 +20,15 @@ server s1 { ...@@ -19,11 +20,15 @@ server s1 {
# And see if it has all its marbles still... # And see if it has all its marbles still...
rxreq rxreq
expect req.url == "/" expect req.url == "/"
expect req.http.Is-bg == "true"
txresp -bodylen 2 txresp -bodylen 2
} -start } -start
varnish v1 -vcl+backend { varnish v1 -vcl+backend {
sub vcl_backend_fetch {
set bereq.http.Is-bg = bereq.is_bgfetch;
}
sub vcl_backend_response { sub vcl_backend_response {
set beresp.do_stream = false; set beresp.do_stream = false;
set beresp.ttl = 2s; set beresp.ttl = 2s;
......
...@@ -19,6 +19,8 @@ Varnish Cache Trunk (ongoing) ...@@ -19,6 +19,8 @@ Varnish Cache Trunk (ongoing)
``MAIN.client_req``. VSM consumers should be changed to use the ``MAIN.client_req``. VSM consumers should be changed to use the
latter if necessary. latter if necessary.
* Added ``bereq.is_bgfetch`` which is true for background fetches.
================================ ================================
Varnish Cache 5.1.2 (2017-04-07) Varnish Cache 5.1.2 (2017-04-07)
================================ ================================
......
...@@ -39,6 +39,7 @@ BO_FLAG(uncacheable, 0, 0, "") ...@@ -39,6 +39,7 @@ BO_FLAG(uncacheable, 0, 0, "")
BO_FLAG(is_gzip, 0, 0, "") BO_FLAG(is_gzip, 0, 0, "")
BO_FLAG(is_gunzip, 0, 0, "") BO_FLAG(is_gunzip, 0, 0, "")
BO_FLAG(was_304, 1, 0, "") BO_FLAG(was_304, 1, 0, "")
BO_FLAG(is_bgfetch, 0, 0, "")
#undef BO_FLAG #undef BO_FLAG
/*lint -restore */ /*lint -restore */
...@@ -478,6 +478,13 @@ sp_variables = [ ...@@ -478,6 +478,13 @@ sp_variables = [
backend. Not available in pipe mode. backend. Not available in pipe mode.
""" """
), ),
('bereq.is_bgfetch',
'BOOL',
('backend', ),
(), """
True for background fetches.
"""
),
('beresp', ('beresp',
'HTTP', 'HTTP',
('backend_response', 'backend_error'), ('backend_response', 'backend_error'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment