Skip to content

Instantly share code, notes, and snippets.

Created October 7, 2010 18:11
Show Gist options
  • Save anonymous/615570 to your computer and use it in GitHub Desktop.
Save anonymous/615570 to your computer and use it in GitHub Desktop.
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:22:42.506413284 +0000
@@ -75,6 +75,7 @@
enum crit_e criteria;
unsigned retries;
+ double 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;
}
Only in varnish-quorum/bin/varnishd: cache_dir_random.c~
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:36:44.678908834 +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,12 @@
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, '%');
+ SkipToken(tl, ';');
} else {
ErrInternal(tl);
}
@@ -134,6 +141,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");
Only in varnish-quorum/lib/libvcl: vcc_dir_random.c~
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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment