Mailing List Archive

r3174 - in trunk/varnish-cache/bin: varnishd varnishtest/tests
Author: phk
Date: 2008-09-08 20:12:19 +0200 (Mon, 08 Sep 2008)
New Revision: 3174

Added:
trunk/varnish-cache/bin/varnishtest/tests/r00306.vtc
Modified:
trunk/varnish-cache/bin/varnishd/cache_dir_random.c
Log:
Fix an off-by-one error in the random director, which made it unable to
use the single remaining healthy backend.

Add regression test.

Fixes: ticket #306



Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-09-08 17:34:16 UTC (rev 3173)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-09-08 18:12:19 UTC (rev 3174)
@@ -96,14 +96,14 @@
r *= s1;

s2 = 0;
- j = 0;
for (i = 0; i < vs->nhosts; i++) {
if (!vs->hosts[i].backend->healthy)
continue;
s2 += vs->hosts[i].weight;
- if (r > s2)
- j = i + 1;
+ if (r < s2)
+ break;
}
+
if (s2 != s1) {
/*
* Health bit changed in an unusable way while we
@@ -112,7 +112,7 @@
*/
continue;
}
- vbe = VBE_GetVbe(sp, vs->hosts[j].backend);
+ vbe = VBE_GetVbe(sp, vs->hosts[i].backend);
if (vbe != NULL)
return (vbe);
k++;

Added: trunk/varnish-cache/bin/varnishtest/tests/r00306.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/r00306.vtc (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/r00306.vtc 2008-09-08 18:12:19 UTC (rev 3174)
@@ -0,0 +1,53 @@
+# $Id: v00007.vtc 3060 2008-08-01 12:44:53Z phk $
+
+test "Regression test for ticket #306, random director ignoring good backend"
+
+server s1 {
+
+ rxreq
+ expect req.url == /foo
+ txresp -body "foo1"
+
+ rxreq
+ expect req.url == /bar
+ txresp -body "bar1"
+
+} -start
+
+server s2 -listen 127.0.0.1:9180 {
+ rxreq
+ txresp -status 404
+} -start
+
+varnish v1 -vcl {
+ backend s1 {
+ .host = "127.0.0.1"; .port = "9080";
+ }
+ backend s2 {
+ .host = "127.0.0.1"; .port = "9180";
+ .probe = {
+ .url = "/";
+ }
+ }
+ director foo random {
+ { .backend = s2; .weight = 1; }
+ { .backend = s1; .weight = 1; }
+ }
+
+ sub vcl_recv {
+ set req.backend = foo;
+ }
+} -start
+
+client c1 {
+ timeout 10
+
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+
+ txreq -url "/bar"
+ rxresp
+ expect resp.status == 200
+
+} -run