[master] 15ee0c7 Implement backend_fetch_response( return (retry); )
Poul-Henning Kamp
phk at varnish-cache.org
Thu Jun 27 12:16:10 CEST 2013
commit 15ee0c7cf73365cc675f0fa332a1acd3450153d8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jun 27 10:15:51 2013 +0000
Implement backend_fetch_response( return (retry); )
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 5df6096..fe12452 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -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);
}
diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h
index ebeff0f..c00d427 100644
--- a/bin/varnishd/common/params.h
+++ b/bin/varnishd/common/params.h
@@ -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;
diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c
index 01534dc..82ed98f 100644
--- a/bin/varnishd/mgt/mgt_param_tbl.c
+++ b/bin/varnishd/mgt/mgt_param_tbl.c
@@ -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"
diff --git a/bin/varnishtest/tests/c00056.vtc b/bin/varnishtest/tests/c00056.vtc
new file mode 100644
index 0000000..694e6c8
--- /dev/null
+++ b/bin/varnishtest/tests/c00056.vtc
@@ -0,0 +1,50 @@
+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
diff --git a/bin/varnishtest/tests/v00017.vtc b/bin/varnishtest/tests/v00017.vtc
index b8553e6..ba0c8e4 100644
--- a/bin/varnishtest/tests/v00017.vtc
+++ b/bin/varnishtest/tests/v00017.vtc
@@ -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} {
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index d358351..ef3f109 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -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',)),
More information about the varnish-commit
mailing list