]> git.kaiwu.me - haproxy.git/commitdiff
[BUG] option allbackups was not working anymore in roundrobin mode
authorWilly Tarreau <w@1wt.eu>
Sat, 8 Mar 2008 20:42:54 +0000 (21:42 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 8 Mar 2008 20:59:15 +0000 (21:59 +0100)
Commit 3168223a7b33a1d5aad1e11b8f2ad917645d7f27 broke option
"allbackups" in roundrobin mode due to an erroneous structure
member replacement in backend.c. The PR_O_USE_ALL_BK flag was
not tested in the right member anymore.

This bug uncoverred another one, by which all backup servers would
be used whatever the option's value, if all of them had been seen
as simultaneously failed at one moment.

This patch fixes the two stupid errors. Correctness has been tested
using the test-fwrr.cfg config example.
(cherry picked from commit f4cca45b5e6c6ed88a0062cf92ae57e01405ab12)

src/backend.c

index 88db588830896183ae1133ca988658cc0bf7aaad..e0b7ee533e2b56f853c5d905227f48fbe175c2c8 100644 (file)
@@ -73,7 +73,7 @@ static inline int srv_is_usable(int state, int weight)
  * This function recounts the number of usable active and backup servers for
  * proxy <p>. These numbers are returned into the p->srv_act and p->srv_bck.
  * This function also recomputes the total active and backup weights. However,
- * it does nout update tot_weight nor tot_used. Use update_backend_weight() for
+ * it does not update tot_weight nor tot_used. Use update_backend_weight() for
  * this.
  */
 static void recount_servers(struct proxy *px)
@@ -89,7 +89,7 @@ static void recount_servers(struct proxy *px)
 
                if (srv->state & SRV_BACKUP) {
                        if (!px->srv_bck &&
-                           !(px->lbprm.algo & PR_O_USE_ALL_BK))
+                           !(px->options & PR_O_USE_ALL_BK))
                                px->lbprm.fbck = srv;
                        px->srv_bck++;
                        px->lbprm.tot_wbck += srv->eweight;
@@ -379,16 +379,21 @@ static void fwrr_set_server_status_up(struct server *srv)
                p->lbprm.tot_wbck = p->lbprm.fwrr.bck.next_weight;
                p->srv_bck++;
 
-               if (p->lbprm.fbck) {
-                       /* we may have restored a backup server prior to fbck,
-                        * in which case it should replace it.
-                        */
-                       struct server *srv2 = srv;
-                       do {
-                               srv2 = srv2->next;
-                       } while (srv2 && (srv2 != p->lbprm.fbck));
-                       if (srv2)
+               if (!(p->options & PR_O_USE_ALL_BK)) {
+                       if (!p->lbprm.fbck) {
+                               /* there was no backup server anymore */
                                p->lbprm.fbck = srv;
+                       } else {
+                               /* we may have restored a backup server prior to fbck,
+                                * in which case it should replace it.
+                                */
+                               struct server *srv2 = srv;
+                               do {
+                                       srv2 = srv2->next;
+                               } while (srv2 && (srv2 != p->lbprm.fbck));
+                               if (srv2)
+                                       p->lbprm.fbck = srv;
+                       }
                }
        } else {
                p->lbprm.tot_wact = p->lbprm.fwrr.act.next_weight;