]> err.no Git - varnish/commitdiff
Fix an off-by-one error in the random director, which made it unable to
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 8 Sep 2008 18:12:19 +0000 (18:12 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 8 Sep 2008 18:12:19 +0000 (18:12 +0000)
use the single remaining healthy backend.

Add regression test.

Fixes: ticket #306
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3174 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_dir_random.c
varnish-cache/bin/varnishtest/tests/r00306.vtc [new file with mode: 0644]

index f514cedcd05580ca5f1848ff8c9ecb5993d20501..bb386f79ef40a4adae479f66a3c902d02613f88b 100644 (file)
@@ -96,14 +96,14 @@ vdi_random_getfd(struct sess *sp)
                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 @@ vdi_random_getfd(struct sess *sp)
                         */
                        continue;
                }
-               vbe = VBE_GetVbe(sp, vs->hosts[j].backend);
+               vbe = VBE_GetVbe(sp, vs->hosts[i].backend);
                if (vbe != NULL)
                        return (vbe);
                k++;
diff --git a/varnish-cache/bin/varnishtest/tests/r00306.vtc b/varnish-cache/bin/varnishtest/tests/r00306.vtc
new file mode 100644 (file)
index 0000000..283769e
--- /dev/null
@@ -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