Commit 0c582627 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.



git-svn-id: http://www.varnish-cache.org/svn/trunk@3138 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent cdc6e633
......@@ -57,6 +57,8 @@ struct vdi_random {
unsigned magic;
#define VDI_RANDOM_MAGIC 0x3771ae23
struct director dir;
unsigned retries;
struct vdi_random_host *hosts;
unsigned nhosts;
};
......@@ -74,7 +76,7 @@ vdi_random_getfd(struct sess *sp)
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 @@ VRT_init_dir_random(struct cli *cli, struct director **bp, const struct vrt_dir_
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 @@ VRT_init_dir_random(struct cli *cli, struct director **bp, const struct vrt_dir_
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++) {
......
......@@ -93,6 +93,7 @@ struct vrt_dir_random_entry {
struct vrt_dir_random {
const char *name;
unsigned retries;
unsigned nmember;
const struct vrt_dir_random_entry *members;
};
......
......@@ -54,11 +54,29 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, cons
{
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",
......@@ -67,7 +85,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, cons
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 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, cons
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 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, cons
} 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 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, cons
}
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 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, cons
"\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");
......
......@@ -373,6 +373,7 @@ vcl_output_lang_h(struct vsb *sb)
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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment