[master] c2ebc12 Introduce two new states in backend-fetch state machine: retry and error
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 25 12:33:25 CET 2014
commit c2ebc12633e6cc577e5ffa6b2cf23eb4e1af9ba4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Feb 18 12:19:23 2014 +0000
Introduce two new states in backend-fetch state machine: retry and error
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 819c39f..31379cf 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -45,6 +45,22 @@
*/
static void
+make_it_503(struct busyobj *bo)
+{
+
+ HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
+ http_SetResp(bo->beresp, "HTTP/1.1", 503, "Backend fetch failed");
+ http_SetHeader(bo->beresp, "Content-Length: 0");
+ http_SetHeader(bo->beresp, "Connection: close");
+ bo->exp.ttl = 0;
+ bo->exp.grace = 0;
+ bo->exp.keep = 0;
+}
+
+/*--------------------------------------------------------------------
+ */
+
+static void
vbf_release_req(struct busyobj *bo)
{
assert(bo->state == BOS_INVALID);
@@ -103,7 +119,31 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
}
/*--------------------------------------------------------------------
- * Copy run bereq by VCL::vcl_backend_fetch{}
+ * Start a new VSL transaction and try again
+ */
+
+static enum fetch_step
+vbf_stp_retry(struct worker *wrk, struct busyobj *bo)
+{
+ unsigned owid, wid;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+
+ // XXX: BereqEnd + BereqAcct ?
+ wid = VXID_Get(&wrk->vxid_pool);
+ VSLb(bo->vsl, SLT_Link, "bereq %u retry", wid);
+ VSLb(bo->vsl, SLT_End, "%s", "");
+ VSL_Flush(bo->vsl, 0);
+ owid = bo->vsl->wid & VSL_IDENTMASK;
+ bo->vsl->wid = wid | VSL_BACKENDMARKER;
+ VSLb(bo->vsl, SLT_Begin, "bereq %u retry", owid);
+
+ return (F_STP_STARTFETCH);
+}
+
+/*--------------------------------------------------------------------
+ * Setup bereq from bereq0, run vcl_backend_fetch
*/
static enum fetch_step
@@ -138,21 +178,6 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
return (F_STP_FETCHHDR);
}
-/*--------------------------------------------------------------------
- */
-
-static void
-make_it_503(struct busyobj *bo)
-{
-
- HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
- http_SetResp(bo->beresp, "HTTP/1.1", 503, "Backend fetch failed");
- http_SetHeader(bo->beresp, "Content-Length: 0");
- http_SetHeader(bo->beresp, "Connection: close");
- bo->exp.ttl = 0;
- bo->exp.grace = 0;
- bo->exp.keep = 0;
-}
/*--------------------------------------------------------------------
*/
@@ -161,7 +186,6 @@ static enum fetch_step
vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)
{
int i, do_ims, fail;
- unsigned owid, wid;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
@@ -247,17 +271,9 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)
if (bo->vbc)
VDI_CloseFd(&bo->vbc);
bo->retries++;
- if (bo->retries <= cache_param->max_retries) {
- // XXX: BereqEnd + BereqAcct ?
- wid = VXID_Get(&wrk->vxid_pool);
- VSLb(bo->vsl, SLT_Link, "bereq %u retry", wid);
- VSLb(bo->vsl, SLT_End, "%s", "");
- VSL_Flush(bo->vsl, 0);
- owid = bo->vsl->wid & VSL_IDENTMASK;
- bo->vsl->wid = wid | VSL_BACKENDMARKER;
- VSLb(bo->vsl, SLT_Begin, "bereq %u retry", owid);
- return (F_STP_STARTFETCH);
- }
+ if (bo->retries <= cache_param->max_retries)
+ return (F_STP_RETRY);
+
VSLb(bo->vsl, SLT_VCL_Error,
"Too many retries, delivering 503");
make_it_503(bo);
@@ -548,13 +564,6 @@ VSLb(bo->vsl, SLT_Debug, "YYY REF %d %d",
return (F_STP_DONE);
}
-static enum fetch_step
-vbf_stp_done(void)
-{
- WRONG("Just plain wrong");
- return (F_STP_DONE);
-}
-
/*--------------------------------------------------------------------
*/
@@ -659,8 +668,28 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
}
/*--------------------------------------------------------------------
+ * Create synth object
*/
+static enum fetch_step
+vbf_stp_error(struct worker *wrk, struct busyobj *bo)
+{
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+ WRONG("");
+ return (F_STP_DONE);
+}
+
+/*--------------------------------------------------------------------
+ */
+
+static enum fetch_step
+vbf_stp_done(void)
+{
+ WRONG("Just plain wrong");
+ return (F_STP_DONE);
+}
+
static const char *
vbf_step_name(enum fetch_step stp)
{
@@ -675,7 +704,6 @@ vbf_step_name(enum fetch_step stp)
}
}
-
static void
vbf_fetch_thread(struct worker *wrk, void *priv)
{
diff --git a/include/tbl/steps.h b/include/tbl/steps.h
index d99738c..9ef7f6c 100644
--- a/include/tbl/steps.h
+++ b/include/tbl/steps.h
@@ -50,10 +50,12 @@ REQ_STEP(error, ERROR, (wrk, req))
#ifdef FETCH_STEP
FETCH_STEP(mkbereq, MKBEREQ, (wrk, bo))
+FETCH_STEP(retry, RETRY, (wrk, bo))
FETCH_STEP(startfetch, STARTFETCH, (wrk, bo))
FETCH_STEP(fetchhdr, FETCHHDR, (wrk, bo))
FETCH_STEP(condfetch, CONDFETCH, (wrk, bo))
FETCH_STEP(fetch, FETCH, (wrk, bo))
+FETCH_STEP(error, ERROR, (wrk, bo))
FETCH_STEP(done, DONE, ())
#endif
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 0702465..29dcb9e 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -120,7 +120,7 @@ returns =(
),
###############################################################
- # Backend-fetch
+ # Backend-fetch
('backend_fetch',
"B",
More information about the varnish-commit
mailing list