Commit 15ee0c7c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Implement backend_fetch_response( return (retry); )

parent a28ad1e0
......@@ -58,7 +58,8 @@ vbf_release_req(struct req ***reqpp)
*/
static enum fetch_step
vbf_stp_mkbereq(struct worker *wrk, struct busyobj *bo, const struct req *req)
vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo,
const struct req *req)
{
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
......@@ -205,6 +206,14 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo, struct req ***reqpp)
if (wrk->handling == VCL_RET_DELIVER)
return (F_STP_FETCH);
if (wrk->handling == VCL_RET_RETRY) {
bo->retries++;
if (bo->retries <= cache_param->max_retries) {
VDI_CloseFd(&bo->vbc);
return (F_STP_STARTFETCH);
}
// XXX: wrk->handling = VCL_RET_SYNTH;
}
return (F_STP_NOTYET);
}
......
......@@ -143,6 +143,9 @@ struct params {
/* Maximum restarts allowed */
unsigned max_restarts;
/* Maximum backend retriesallowed */
unsigned max_retries;
/* Maximum esi:include depth allowed */
unsigned max_esi_depth;
......
......@@ -319,6 +319,10 @@ const struct parspec mgt_parspec[] = {
"the backend, so don't increase thoughtlessly.\n",
0,
"4", "restarts" },
{ "max_retries", tweak_uint, &mgt_param.max_retries, 0, UINT_MAX,
"Upper limit on how many times a backend fetch can retry.\n",
0,
"4", "retries" },
{ "esi_syntax",
tweak_uint, &mgt_param.esi_syntax, 0, UINT_MAX,
"Bitmap controlling ESI parsing code:\n"
......
varnishtest "vcl_backend_response{} retry"
server s1 {
rxreq
txresp -hdr "foo: 1"
accept
rxreq
txresp -hdr "foo: 2"
} -start
varnish v1 -vcl+backend {
sub vcl_recv { return (pass); }
sub vcl_backend_response {
set beresp.http.bar = bereq.retries;
if (beresp.http.foo != bereq.http.stop) {
return (retry);
}
}
} -start
varnish v1 -cliok "param.set debug +syncvsl"
client c1 {
txreq -hdr "stop: 2"
rxresp
expect resp.http.foo == 2
} -run
delay .1
server s1 {
rxreq
txresp -hdr "foo: 1"
accept
rxreq
txresp -hdr "foo: 2"
accept
rxreq
txresp -hdr "foo: 3"
} -start
varnish v1 -cliok "param.set max_retries 2"
client c1 {
txreq -hdr "stop: 3"
rxresp
expect resp.http.foo == 3
} -run
# XXX: Add a test which exceeds max_retries and gets 503 back
......@@ -67,7 +67,7 @@ varnish v1 -vcl {
varnish v1 -vcl {
backend b { .host = "127.0.0.1"; }
sub vcl_recv { if (client.ip == "127.0.0.1") { return(pass); } }
sub vcl_backend_response { if (client.ip != "127.0.0.1") { return(restart); } }
sub vcl_backend_response { if (client.ip != "127.0.0.1") { return(retry); } }
}
varnish v1 -errvcl {Operator > not possible on IP} {
......
......@@ -86,7 +86,7 @@ returns =(
('miss', "C", ('error', 'restart', 'pass', 'fetch',)),
('lookup', "C", ('error', 'restart', 'pass', 'deliver',)),
('backend_fetch', "B", ('fetch', 'abandon')),
('backend_response', "B", ('deliver', 'restart', 'error')),
('backend_response', "B", ('deliver', 'retry', 'abandon')),
('deliver', "C", ('restart', 'deliver',)),
('error', "C", ('restart', 'deliver',)),
('init', "", ('ok',)),
......
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