<div dir="ltr">Hi,<br><br>Any reason not to use rr->vd->n_backend directly as the round-robin director does?<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 29, 2014 at 1:48 PM, Martin Blix Grydeland <span dir="ltr"><<a href="mailto:martin@varnish-software.com" target="_blank">martin@varnish-software.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Fixes: #1575<br>
---<br>
bin/varnishtest/tests/r01575.vtc | 56 ++++++++++++++++++++++++++++++++++++++++<br>
lib/libvmod_directors/hash.c | 6 ++---<br>
lib/libvmod_directors/random.c | 6 ++---<br>
lib/libvmod_directors/vdir.c | 2 +-<br>
4 files changed, 63 insertions(+), 7 deletions(-)<br>
create mode 100644 bin/varnishtest/tests/r01575.vtc<br>
<br>
diff --git a/bin/varnishtest/tests/r01575.vtc b/bin/varnishtest/tests/r01575.vtc<br>
new file mode 100644<br>
index 0000000..11c82c1<br>
--- /dev/null<br>
+++ b/bin/varnishtest/tests/r01575.vtc<br>
@@ -0,0 +1,56 @@<br>
+varnishtest "#1575 - random director exhaust backend list"<br>
+<br>
+# Add 5 backends to a random director, with the 5th having very low weight.<br>
+# Mark the first 4 sick, and make sure that the 5th will be selected.<br>
+<br>
+server s1 {<br>
+ rxreq<br>
+ txresp<br>
+} -start<br>
+<br>
+server s2 {<br>
+ rxreq<br>
+ txresp<br>
+} -start<br>
+<br>
+server s3 {<br>
+ rxreq<br>
+ txresp<br>
+} -start<br>
+<br>
+server s4 {<br>
+ rxreq<br>
+ txresp<br>
+} -start<br>
+<br>
+server s5 {<br>
+ rxreq<br>
+ txresp<br>
+} -start<br>
+<br>
+varnish v1 -vcl+backend {<br>
+ import ${vmod_directors};<br>
+ sub vcl_init {<br>
+ new rd = directors.random();<br>
+ rd.add_backend(s1, 10000);<br>
+ rd.add_backend(s2, 10000);<br>
+ rd.add_backend(s3, 10000);<br>
+ rd.add_backend(s4, 10000);<br>
+ rd.add_backend(s5, 1);<br>
+ }<br>
+<br>
+ sub vcl_backend_fetch {<br>
+ set bereq.backend = rd.backend();<br>
+ }<br>
+} -start<br>
+<br>
+varnish v1 -cliok "backend.set_health s1 sick"<br>
+varnish v1 -cliok "backend.set_health s2 sick"<br>
+varnish v1 -cliok "backend.set_health s3 sick"<br>
+varnish v1 -cliok "backend.set_health s4 sick"<br>
+<br>
+client c1 {<br>
+ txreq<br>
+ rxresp<br>
+ expect resp.status == 200<br>
+} -run<br>
diff --git a/lib/libvmod_directors/hash.c b/lib/libvmod_directors/hash.c<br>
index afef7ed..090039f 100644<br>
--- a/lib/libvmod_directors/hash.c<br>
+++ b/lib/libvmod_directors/hash.c<br>
@@ -47,7 +47,7 @@ struct vmod_directors_hash {<br>
unsigned magic;<br>
#define VMOD_DIRECTORS_HASH_MAGIC 0xc08dd611<br>
struct vdir *vd;<br>
- unsigned nloops;<br>
+ unsigned n_backend;<br>
struct vbitmap *vbm;<br>
};<br>
<br>
@@ -64,7 +64,6 @@ vmod_hash__init(const struct vrt_ctx *ctx, struct vmod_directors_hash **rrp,<br>
AN(rr);<br>
rr->vbm = vbit_init(8);<br>
AN(rr->vbm);<br>
- rr->nloops = 3; //<br>
*rrp = rr;<br>
vdir_new(&rr->vd, vcl_name, NULL, NULL, rr);<br>
}<br>
@@ -90,6 +89,7 @@ vmod_hash_add_backend(const struct vrt_ctx *ctx,<br>
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);<br>
CHECK_OBJ_NOTNULL(rr, VMOD_DIRECTORS_HASH_MAGIC);<br>
(void)vdir_add_backend(rr->vd, be, w);<br>
+ rr->n_backend++;<br>
}<br>
<br>
VCL_BACKEND __match_proto__()<br>
@@ -120,6 +120,6 @@ vmod_hash_backend(const struct vrt_ctx *ctx, struct vmod_directors_hash *rr,<br>
r = vbe32dec(sha256);<br>
r = scalbn(r, -32);<br>
assert(r >= 0 && r <= 1.0);<br>
- be = vdir_pick_be(rr->vd, r, rr->nloops);<br>
+ be = vdir_pick_be(rr->vd, r, rr->n_backend);<br>
return (be);<br>
}<br>
diff --git a/lib/libvmod_directors/random.c b/lib/libvmod_directors/random.c<br>
index 22f0bb9..8ae36a7 100644<br>
--- a/lib/libvmod_directors/random.c<br>
+++ b/lib/libvmod_directors/random.c<br>
@@ -45,7 +45,7 @@ struct vmod_directors_random {<br>
unsigned magic;<br>
#define VMOD_DIRECTORS_RANDOM_MAGIC 0x4732d092<br>
struct vdir *vd;<br>
- unsigned nloops;<br>
+ unsigned n_backend;<br>
struct vbitmap *vbm;<br>
};<br>
<br>
@@ -68,7 +68,7 @@ vmod_rr_getfd(const struct director *dir, struct busyobj *bo)<br>
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);<br>
r = scalbn(random(), -31);<br>
assert(r >= 0 && r < 1.0);<br>
- be = vdir_pick_be(rr->vd, r, rr->nloops);<br>
+ be = vdir_pick_be(rr->vd, r, rr->n_backend);<br>
if (be == NULL)<br>
return (NULL);<br>
return (be->getfd(be, bo));<br>
@@ -87,7 +87,6 @@ vmod_random__init(const struct vrt_ctx *ctx, struct vmod_directors_random **rrp,<br>
AN(rr);<br>
rr->vbm = vbit_init(8);<br>
AN(rr->vbm);<br>
- rr->nloops = 3; //<br>
*rrp = rr;<br>
vdir_new(&rr->vd, vcl_name, vmod_rr_healthy, vmod_rr_getfd, rr);<br>
}<br>
@@ -113,6 +112,7 @@ vmod_random_add_backend(const struct vrt_ctx *ctx,<br>
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);<br>
CHECK_OBJ_NOTNULL(rr, VMOD_DIRECTORS_RANDOM_MAGIC);<br>
(void)vdir_add_backend(rr->vd, be, w);<br>
+ rr->n_backend++;<br>
}<br>
<br>
VCL_BACKEND __match_proto__()<br>
diff --git a/lib/libvmod_directors/vdir.c b/lib/libvmod_directors/vdir.c<br>
index 12268eb..aae7a14 100644<br>
--- a/lib/libvmod_directors/vdir.c<br>
+++ b/lib/libvmod_directors/vdir.c<br>
@@ -186,7 +186,7 @@ vdir_pick_be(struct vdir *vd, double w, unsigned nloops)<br>
nbe = vd->n_backend;<br>
assert(w >= 0.0 && w < 1.0);<br>
vdir_lock(vd);<br>
- for (l = 0; nbe > 0 && tw > 0.0 && l <nloops; l++) {<br>
+ for (l = 0; nbe > 0 && tw > 0.0 && l < nloops; l++) {<br>
u = vdir_pick_by_weight(vd, w * tw, vbm);<br>
be = vd->backend[u];<br>
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.0.rc1<br>
<br>
<br>
_______________________________________________<br>
varnish-dev mailing list<br>
<a href="mailto:varnish-dev@varnish-cache.org">varnish-dev@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev</a><br>
</font></span></blockquote></div><br></div>