r4336 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl man

kristian at projects.linpro.no kristian at projects.linpro.no
Wed Oct 21 13:36:28 CEST 2009


Author: kristian
Date: 2009-10-21 13:36:28 +0200 (Wed, 21 Oct 2009)
New Revision: 4336

Added:
   trunk/varnish-cache/bin/varnishtest/tests/c00030.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_backend.h
   trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
   trunk/varnish-cache/include/vrt.h
   trunk/varnish-cache/lib/libvcl/vcc_backend.c
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/man/vcl.7so
Log:
Add saintmode_threshold to backend definitions

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2009-10-21 08:24:24 UTC (rev 4335)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2009-10-21 11:36:28 UTC (rev 4336)
@@ -35,6 +35,7 @@
 #include "svnid.h"
 SVNID("$Id$")
 
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -245,15 +246,23 @@
 	struct trouble *tr2;
 	struct trouble *old = NULL;
 	unsigned i = 0;
-
+	unsigned int threshold;
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(backend, BACKEND_MAGIC);
 
 	if (!backend->healthy)
 		return 0;
 
+	/* VRT/VCC sets threshold to UINT_MAX to mark that it's not
+	 * specified by VCL (thus use param).
+	 */
+	if (backend->saintmode_threshold == UINT_MAX)
+		threshold = params->saintmode_threshold;
+	else
+		threshold = backend->saintmode_threshold;
+
 	/* Saintmode is disabled */
-	if (params->saintmode_threshold == 0)
+	if (threshold == 0)
 		return 1;
 
 	/* No need to test if we don't have an object head to test against.
@@ -280,7 +289,7 @@
 		 * will disable the backend. Since 0 is disable, ++i
 		 * instead of i++ to allow this behavior.
 		 */
-		if (++i >= params->saintmode_threshold) {
+		if (++i >=threshold) {
 			Lck_Unlock(&backend->mtx);
 			return 0;
 		}

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h	2009-10-21 08:24:24 UTC (rev 4335)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h	2009-10-21 11:36:28 UTC (rev 4336)
@@ -137,6 +137,7 @@
 	struct vbp_target	*probe;
 	unsigned		healthy;
 	VTAILQ_HEAD(, trouble)	troublelist;
+	unsigned		saintmode_threshold;
 };
 
 /* cache_backend.c */

Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2009-10-21 08:24:24 UTC (rev 4335)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2009-10-21 11:36:28 UTC (rev 4336)
@@ -240,6 +240,7 @@
 	b->first_byte_timeout = vb->first_byte_timeout;
 	b->between_bytes_timeout = vb->between_bytes_timeout;
 	b->max_conn = vb->max_connections;
+	b->saintmode_threshold = vb->saintmode_threshold;
 
 	/*
 	 * Copy over the sockaddrs

Added: trunk/varnish-cache/bin/varnishtest/tests/c00030.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/c00030.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/c00030.vtc	2009-10-21 11:36:28 UTC (rev 4336)
@@ -0,0 +1,108 @@
+# $Id$
+
+test "Test that saintmode_threshold in VCL"
+
+server s1 {
+	rxreq
+	txresp
+
+	rxreq
+	txresp
+
+	rxreq
+	txresp
+
+	rxreq
+	txresp
+
+	rxreq
+	txresp -hdr "X-Saint: yes"
+
+	rxreq
+	txresp -hdr "X-Saint: yes"
+
+	rxreq
+	txresp -hdr "X-Saint: yes"
+
+	rxreq
+	txresp -hdr "X-Saint: yes"
+} -start
+
+varnish v1 -arg "-p saintmode_threshold=10" -vcl {
+	backend foo {
+		.host = "127.0.0.1";
+		.port = "9080";
+		.saintmode_threshold = 2;
+	}
+
+	sub vcl_recv {
+		set req.backend = foo;
+		set req.grace = 1h;
+	}
+
+	sub vcl_fetch {
+		if (beresp.http.X-Saint == "yes") {
+			set beresp.saintmode = 20s;
+			restart;
+		}
+		set beresp.grace = 1h;
+		set beresp.ttl = 1s;
+	}
+	sub vcl_deliver {
+		set resp.http.X-Restarts = req.restarts;
+	}
+ } -start
+
+client c1 {
+        txreq -url "/one"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "0"
+
+        txreq -url "/two"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "0"
+
+        txreq -url "/three"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "0"
+
+        txreq -url "/four"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "0"
+
+	delay 2
+
+        txreq -url "/one"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "1"
+
+        txreq -url "/two"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "1"
+
+        txreq -url "/three"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "0"
+
+        txreq -url "/four"
+        rxresp
+        expect resp.status == 200
+        expect resp.http.X-Saint != "yes"
+	expect resp.http.X-Restarts == "0"
+
+} -run
+

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2009-10-21 08:24:24 UTC (rev 4335)
+++ trunk/varnish-cache/include/vrt.h	2009-10-21 11:36:28 UTC (rev 4336)
@@ -73,6 +73,7 @@
 	double				first_byte_timeout;
 	double				between_bytes_timeout;
 	unsigned			max_connections;
+	unsigned			saintmode_threshold;
 	struct vrt_backend_probe	probe;
 };
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c	2009-10-21 08:24:24 UTC (rev 4335)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c	2009-10-21 11:36:28 UTC (rev 4336)
@@ -56,6 +56,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 
+#include <limits.h>
 #include <netdb.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -476,6 +477,7 @@
 	struct token *t_host = NULL;
 	struct token *t_port = NULL;
 	struct token *t_hosthdr = NULL;
+	unsigned saint = UINT_MAX;
 	const char *ep;
 	struct fld_spec *fs;
 	struct vsb *vsb;
@@ -490,6 +492,7 @@
 	    "?between_bytes_timeout",
 	    "?probe",
 	    "?max_connections",
+	    "?saintmode_threshold",
 	    NULL);
 	t_first = tl->t;
 
@@ -573,6 +576,22 @@
 			ExpectErr(tl, ';');
 			vcc_NextToken(tl);
 			Fb(tl, 0, "\t.max_connections = %u,\n", u);
+		} else if (vcc_IdIs(t_field, "saintmode_threshold")) {
+			u = vcc_UintVal(tl);
+			/* UINT_MAX == magic number to mark as unset, so
+			 * not allowed here.
+			 */
+			if (u == UINT_MAX) {
+				vsb_printf(tl->sb, "Value outside allowed range: ");
+				vcc_ErrToken(tl, tl->t);
+				vsb_printf(tl->sb, " at\n");
+				vcc_ErrWhere(tl, tl->t);
+			}
+			vcc_NextToken(tl);
+			ERRCHK(tl);
+			saint = u;
+			ExpectErr(tl, ';');
+			vcc_NextToken(tl);
 		} else if (vcc_IdIs(t_field, "probe")) {
 			vcc_ParseProbe(tl);
 			ERRCHK(tl);
@@ -623,6 +642,8 @@
 		EncToken(tl->fb, t_host);
 	Fb(tl, 0, ",\n");
 
+	Fb(tl, 0, "\t.saintmode_threshold = %d,\n",saint);
+
 	/* Close the struct */
 	Fb(tl, 0, "};\n");
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-10-21 08:24:24 UTC (rev 4335)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-10-21 11:36:28 UTC (rev 4336)
@@ -251,6 +251,7 @@
 	vsb_cat(sb, "\tdouble\t\t\t\tfirst_byte_timeout;\n");
 	vsb_cat(sb, "\tdouble\t\t\t\tbetween_bytes_timeout;\n");
 	vsb_cat(sb, "\tunsigned\t\t\tmax_connections;\n");
+	vsb_cat(sb, "\tunsigned\t\t\tsaintmode_threshold;\n");
 	vsb_cat(sb, "\tstruct vrt_backend_probe\tprobe;\n");
 	vsb_cat(sb, "};\n\n/*\n * A director with a predictable reply\n");
 	vsb_cat(sb, " */\n\nstruct vrt_dir_simple {\n");

Modified: trunk/varnish-cache/man/vcl.7so
===================================================================
--- trunk/varnish-cache/man/vcl.7so	2009-10-21 08:24:24 UTC (rev 4335)
+++ trunk/varnish-cache/man/vcl.7so	2009-10-21 11:36:28 UTC (rev 4336)
@@ -120,6 +120,14 @@
     .between_bytes_timeout = 2s;
 }
 .Ed
+.Pp
+To stop using a backend after number of items have been added to it's
+saintmode list 
+.Fa .saintmode_threshold
+can be set to the maximum list size. Setting a value of 0 disables
+saintmode checking entirely for that backend. The value in the backend
+declaration overrides the parameter.
+
 .Ss Directors
 Directors choose from different backends based on health status and a
 per-director algorithm.



More information about the varnish-commit mailing list