]> err.no Git - varnish/commitdiff
Make it possible to configure the number of retries the random director
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 28 Aug 2008 09:11:41 +0000 (09:11 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 28 Aug 2008 09:11:41 +0000 (09:11 +0000)
will make at getting a backend connection.  By default it tries as many
times as it has members.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3138 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_dir_random.c
varnish-cache/include/vrt.h
varnish-cache/lib/libvcl/vcc_dir_random.c
varnish-cache/lib/libvcl/vcc_fixed_token.c

index dcb09ce8ebc9a924d7d52bb7c4584b5ec45b9278..dcdb91337900e3c7c5aaadf0b1ae2de1911353ec 100644 (file)
@@ -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++) {
index 243c5d659d22601e24936dd0fadaf3a3bb3b07e8..9b35682631b2c2fcff2d2ee718245ac70c3d6fa6 100644 (file)
@@ -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;
 };
index 8f817199ceed125750a58673776cc650fd9c2c3d..bd681c4277f1cefc7d9d38d07cd8a73f8472fbda 100644 (file)
@@ -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");
index 3ee45b2575b63224079773465807f478a6d2497f..3d5510c17faae88d9751cae2d9f3dcfc616687d2 100644 (file)
@@ -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");