Mailing List Archive

r3138 - in trunk/varnish-cache: bin/varnishd include lib/libvcl
Author: phk
Date: 2008-08-28 11:11:41 +0200 (Thu, 28 Aug 2008)
New Revision: 3138

Modified:
trunk/varnish-cache/bin/varnishd/cache_dir_random.c
trunk/varnish-cache/include/vrt.h
trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
Make it possible to configure the number of retries the random director
will make at getting a backend connection. By default it tries as many
times as it has members.



Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-08-27 14:22:03 UTC (rev 3137)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-08-28 09:11:41 UTC (rev 3138)
@@ -57,6 +57,8 @@
unsigned magic;
#define VDI_RANDOM_MAGIC 0x3771ae23
struct director dir;
+
+ unsigned retries;
struct vdi_random_host *hosts;
unsigned nhosts;
};
@@ -74,7 +76,7 @@
CAST_OBJ_NOTNULL(vs, sp->director->priv, VDI_RANDOM_MAGIC);

k = 0;
- for (k = 0; k < 4; ) { /* XXX: 4 is arbitrary */
+ for (k = 0; k < vs->retries; ) {

r = random() / 2147483648.0; /* 2^31 */
assert(r >= 0.0 && r < 1.0);
@@ -143,7 +145,6 @@
struct vdi_random *vs;
const struct vrt_dir_random_entry *te;
struct vdi_random_host *vh;
- double s;
int i;

(void)cli;
@@ -159,7 +160,9 @@
vs->dir.getfd = vdi_random_getfd;
vs->dir.fini = vdi_random_fini;

- s = 0;
+ vs->retries = t->retries;
+ if (vs->retries == 0)
+ vs->retries = t->nmember;
vh = vs->hosts;
te = t->members;
for (i = 0; i < t->nmember; i++, vh++, te++) {

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h 2008-08-27 14:22:03 UTC (rev 3137)
+++ trunk/varnish-cache/include/vrt.h 2008-08-28 09:11:41 UTC (rev 3138)
@@ -93,6 +93,7 @@

struct vrt_dir_random {
const char *name;
+ unsigned retries;
unsigned nmember;
const struct vrt_dir_random_entry *members;
};

Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-08-27 14:22:03 UTC (rev 3137)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-08-28 09:11:41 UTC (rev 3138)
@@ -54,12 +54,30 @@
{
struct token *t_field, *t_be;
int nbh, nelem;
- struct fld_spec *fs;
- unsigned u;
+ struct fld_spec *fs, *mfs;
+ unsigned u, retries;
const char *first;

- fs = vcc_FldSpec(tl, "!backend", "!weight", NULL);
+ fs = vcc_FldSpec(tl, "?retries", NULL);

+ retries = 0;
+ while (tl->t->tok != '{') {
+ vcc_IsField(tl, &t_field, fs);
+ ERRCHK(tl);
+ if (vcc_IdIs(t_field, "retries")) {
+ ExpectErr(tl, CNUM);
+ retries = vcc_UintVal(tl);
+ ERRCHK(tl);
+ vcc_NextToken(tl);
+ ExpectErr(tl, ';');
+ vcc_NextToken(tl);
+ } else {
+ ErrInternal(tl);
+ }
+ }
+
+ mfs = vcc_FldSpec(tl, "!backend", "!weight", NULL);
+
Fc(tl, 0,
"\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n",
PF(t_dir));
@@ -67,7 +85,7 @@
for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */
first = "";
t_be = tl->t;
- vcc_ResetFldSpec(fs);
+ vcc_ResetFldSpec(mfs);
nbh = -1;

ExpectErr(tl, '{');
@@ -75,7 +93,7 @@
Fc(tl, 0, "\t{");

while (tl->t->tok != '}') { /* Member fields */
- vcc_IsField(tl, &t_field, fs);
+ vcc_IsField(tl, &t_field, mfs);
ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) {
vcc_ParseBackendHost(tl, &nbh,
@@ -85,6 +103,7 @@
} else if (vcc_IdIs(t_field, "weight")) {
ExpectErr(tl, CNUM);
u = vcc_UintVal(tl);
+ ERRCHK(tl);
if (u == 0) {
vsb_printf(tl->sb,
"The .weight must be higher "
@@ -103,7 +122,7 @@
}
first = ", ";
}
- vcc_FieldsOk(tl, fs);
+ vcc_FieldsOk(tl, mfs);
if (tl->err) {
vsb_printf(tl->sb,
"\nIn member host specfication starting at:\n");
@@ -118,6 +137,7 @@
"\nstatic const struct vrt_dir_random vdr_%.*s = {\n",
PF(t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir));
+ Fc(tl, 0, "\t.retries = %u,\n", retries);
Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir));
Fc(tl, 0, "};\n");

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-08-27 14:22:03 UTC (rev 3137)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-08-28 09:11:41 UTC (rev 3138)
@@ -373,6 +373,7 @@
vsb_cat(sb, "\n");
vsb_cat(sb, "struct vrt_dir_random {\n");
vsb_cat(sb, " const char *name;\n");
+ vsb_cat(sb, " unsigned retries;\n");
vsb_cat(sb, " unsigned nmember;\n");
vsb_cat(sb, " const struct vrt_dir_random_entry *members;\n");
vsb_cat(sb, "};\n");