<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="font-family: Times; "><pre style="word-wrap: break-word; white-space: pre-wrap; ">Attached is a patch that implements quorum support. You specify the % of servers that need to be up, and if less than that is up it marks the entire director as down. This avoids the whack-a-mole problem when bringing up servers.</pre><pre style="word-wrap: break-word; white-space: pre-wrap; ">Comments please.</pre><pre style="word-wrap: break-word; white-space: pre-wrap; ">Artur</pre><pre style="word-wrap: break-word; white-space: pre-wrap; ">----------</pre><pre style="word-wrap: break-word; white-space: pre-wrap; "><br></pre><pre style="word-wrap: break-word; white-space: pre-wrap; ">diff -u -r varnish-2.1.3/bin/varnishd/cache_dir_random.c varnish-quorum/bin/varnishd/cache_dir_random.c
--- varnish-2.1.3/bin/varnishd/cache_dir_random.c       2010-03-24 09:44:13.000000000 +0000
+++ varnish-quorum/bin/varnishd/cache_dir_random.c      2010-10-07 18:07:37.126411696 +0000
@@ -75,6 +75,7 @@
 
        enum crit_e             criteria;
        unsigned                retries;
+       unsigned                quorum_weight;
        double                  tot_weight;
        struct vdi_random_host  *hosts;
        unsigned                nhosts;
@@ -155,7 +156,9 @@
                        if (VBE_Healthy_sp(sp, d2))
                                s1 += vs->hosts[i].weight;
                }
-
+               if (s1 < vs->quorum_weight)
+                       return (NULL);
+               
                if (s1 == 0.0)
                        return (NULL);
 
@@ -258,6 +261,7 @@
                vh->backend = bp[te->host];
                AN(vh->backend);
        }
+       vs->quorum_weight = (vs->tot_weight * t->quorum / 100);
        vs->nhosts = t->nmember;
        bp[idx] = &vs->dir;
 }
diff -u -r varnish-2.1.3/include/vrt.h varnish-quorum/include/vrt.h
--- varnish-2.1.3/include/vrt.h 2010-07-13 11:07:03.000000000 +0000
+++ varnish-quorum/include/vrt.h        2010-10-07 17:42:13.476408083 +0000
@@ -91,6 +91,7 @@
        const char                              *name;
        unsigned                                retries;
        unsigned                                nmember;
+       unsigned                                quorum;
        const struct vrt_dir_random_entry       *members;
 };
 
diff -u -r varnish-2.1.3/lib/libvcl/vcc_dir_random.c varnish-quorum/lib/libvcl/vcc_dir_random.c
--- varnish-2.1.3/lib/libvcl/vcc_dir_random.c   2010-07-28 11:11:58.000000000 +0000
+++ varnish-quorum/lib/libvcl/vcc_dir_random.c  2010-10-07 18:01:23.526408498 +0000
@@ -55,13 +55,14 @@
        struct token *t_field, *t_be;
        int nelem;
        struct fld_spec *fs, *mfs;
-       unsigned u, retries;
+       unsigned u, retries, quorum;
        const char *first;
        char *p;
 
-       fs = vcc_FldSpec(tl, "?retries", NULL);
+       fs = vcc_FldSpec(tl, "?retries","?quorum", NULL);
 
        retries = 0;
+       quorum = 0;
        while (tl->t->tok != '{') {
                vcc_IsField(tl, &t_field, fs);
                ERRCHK(tl);
@@ -70,6 +71,11 @@
                        retries = vcc_UintVal(tl);
                        ERRCHK(tl);
                        SkipToken(tl, ';');
+               } else if (vcc_IdIs(t_field, "quorum")) {
+                       ExpectErr(tl, CNUM);
+                       quorum = vcc_UintVal(tl);
+                       ERRCHK(tl);
+                       SkipToken(tl, ';');
                } else {
                        ErrInternal(tl);
                }
@@ -134,6 +140,7 @@
            PF(tl->t_dir));
        Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->t_dir));
        Fc(tl, 0, "\t.retries = %u,\n", retries);
+       Fc(tl, 0, "\t.quorum = %u,\n", quorum);
        Fc(tl, 0, "\t.nmember = %d,\n", nelem);
        Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(tl->t_dir));
        Fc(tl, 0, "};\n");
diff -u -r varnish-2.1.3/lib/libvcl/vcc_fixed_token.c varnish-quorum/lib/libvcl/vcc_fixed_token.c
--- varnish-2.1.3/lib/libvcl/vcc_fixed_token.c  2010-07-28 09:48:29.000000000 +0000
+++ varnish-quorum/lib/libvcl/vcc_fixed_token.c 2010-10-07 17:42:14.888909071 +0000
@@ -258,8 +258,9 @@
        vsb_cat(sb, "\tint\t\t\t\t\thost;\n\tdouble\t\t\t\t\tweight;\n");
        vsb_cat(sb, "};\n\nstruct vrt_dir_random {\n");
        vsb_cat(sb, "\tconst char\t\t\t\t*name;\n\tunsigned\t\t\t\tretries;");
-       vsb_cat(sb, "\n\tunsigned\t\t\t\tnmember;\n\tconst struct vrt_dir_r");
-       vsb_cat(sb, "andom_entry\t*members;\n};\n\n/*\n");
+       vsb_cat(sb, "\n\tunsigned\t\t\t\tnmember;\n\tunsigned              ");
+       vsb_cat(sb, "                  quorum;\n\tconst struct vrt_dir_rand");
+       vsb_cat(sb, "om_entry\t*members;\n};\n\n/*\n");
        vsb_cat(sb, " * A director with round robin selection\n");
        vsb_cat(sb, " */\n\nstruct vrt_dir_round_robin_entry {\n");
        vsb_cat(sb, "\tint\t\t\t\t\thost;\n};\n\nstruct vrt_dir_round_robin");</pre></span></body></html>