r3886 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

kristian at projects.linpro.no kristian at projects.linpro.no
Thu Mar 5 14:12:37 CET 2009


Author: kristian
Date: 2009-03-05 14:12:36 +0100 (Thu, 05 Mar 2009)
New Revision: 3886

Added:
   trunk/varnish-cache/bin/varnishtest/tests/s00002.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_hash.c
Log:
Use a graced object if a backend is unhealthy


Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-03-05 10:36:51 UTC (rev 3885)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-03-05 13:12:36 UTC (rev 3886)
@@ -67,6 +67,7 @@
 #include "stevedore.h"
 #include "hash_slinger.h"
 #include "vsha256.h"
+#include "cache_backend.h"
 
 static const struct hash_slinger *hash;
 unsigned	save_hash;
@@ -362,6 +363,7 @@
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
 	AN(hash);
 	w = sp->wrk;
 
@@ -419,14 +421,16 @@
 	}
 
 	/*
-	 * If we have seen a busy object, and have an object in grace,
-	 * use it, if req.grace is also satisified.
+	 * If we have seen a busy object or the backend is unhealthy, and
+	 * have an object in grace, use it, if req.grace is also
+	 * satisified.
 	 * XXX: Interesting footnote:  The busy object might be for a
 	 * XXX: different "Vary:" than we sought.  We have no way of knowing
 	 * XXX: this until the object is unbusy'ed, so in practice we
 	 * XXX: serialize fetch of all Vary's if grace is possible.
 	 */
-	if (oc == NULL && grace_oc != NULL && busy_oc != NULL) {
+	if (oc == NULL && grace_oc != NULL && 
+	    (busy_oc != NULL || !sp->director->healthy(sp))) {
 		o = grace_oc->obj;
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 		if (o->ttl + HSH_Grace(sp->grace) >= sp->t_req)

Added: trunk/varnish-cache/bin/varnishtest/tests/s00002.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/s00002.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/s00002.vtc	2009-03-05 13:12:36 UTC (rev 3886)
@@ -0,0 +1,44 @@
+# $Id$
+
+test "Check grace with sick backends"
+
+server s1 -listen 127.0.0.1:9080 -repeat 4 {
+	rxreq
+	expect req.url == "/"
+	txresp -body "hi"
+} -start
+
+varnish v1 -vcl {
+	backend b { 
+		.host = "127.0.0.1"; 
+		.port = "9080"; 
+		.probe = { 
+			.url = "/"; 
+			.timeout = 30ms; 
+			.interval = 1s; 
+			.window = 2; 
+			.threshold = 1; 
+			} 
+		}
+	sub vcl_fetch { 
+		set beresp.ttl = 1s; 
+		set beresp.grace = 1m; 
+		set beresp.cacheable = true; 
+	}
+} -start
+
+delay 2
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+} -run
+
+delay 3
+
+client c2 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+} -run



More information about the varnish-commit mailing list