Commit bf167ec4 authored by Nils Goroll's avatar Nils Goroll Committed by Pål Hermunn Johansen

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 d7f8b531.

Conflicts:
	bin/varnishd/cache/cache_fetch.c
	doc/changes.rst
	include/tbl/bo_flags.h
parent 610b309c
......@@ -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;
......
......@@ -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
VRT_r_bereq_uncacheable(VRT_CTX)
{
......
......@@ -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;
......
======================================
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)
================================
......
......@@ -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 */
......@@ -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'),
......
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