[MINOR] backend: separate declarations of LB algos from their lookup method
LB algo macros were composed of the LB algo by itself without any indication
of the method to use to look up a server (the lb function itself). This
method was implied by the LB algo, which was not very convenient to add
more algorithms. Now we have several fields in the LB macros, some to
describe what to look for in the requests, some to describe how to transform
that (kind of algo) and some to describe what lookup function to use.
The next patch will make it possible to factor out some code for all algos
which rely on a map.
diff --git a/src/backend.c b/src/backend.c
index 444daff..3e0bc8e 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -494,7 +494,7 @@
*/
s->srv = NULL;
- if (s->be->lbprm.algo & BE_LB_ALGO) {
+ if (s->be->lbprm.algo & BE_LB_KIND) {
int len;
/* we must check if we have at least one server available */
if (!s->be->lbprm.tot_weight) {
@@ -646,7 +646,7 @@
fprintf(stderr,"assign_server_address : s=%p\n",s);
#endif
- if ((s->flags & SN_DIRECT) || (s->be->lbprm.algo & BE_LB_ALGO)) {
+ if ((s->flags & SN_DIRECT) || (s->be->lbprm.algo & BE_LB_KIND)) {
/* A server is necessarily known for this session */
if (!(s->flags & SN_ASSIGNED))
return SRV_STATUS_INTERNAL;
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 70662b9..de84f37 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -3985,7 +3985,7 @@
}
if ((curproxy->cap & PR_CAP_BE) && (curproxy->mode != PR_MODE_HEALTH)) {
- if (curproxy->lbprm.algo & BE_LB_ALGO) {
+ if (curproxy->lbprm.algo & BE_LB_KIND) {
if (curproxy->options & PR_O_TRANSP) {
Alert("config : %s '%s' cannot use both transparent and balance mode.\n",
proxy_type_str(curproxy), curproxy->id);
@@ -4189,13 +4189,25 @@
curproxy->lbprm.wmult = 1; /* default weight multiplier */
curproxy->lbprm.wdiv = 1; /* default weight divider */
- /* round robin relies on a weight tree */
- if ((curproxy->lbprm.algo & BE_LB_ALGO) == BE_LB_ALGO_RR)
+ /* We have to initialize the server lookup mechanism depending
+ * on what LB algorithm was choosen.
+ */
+
+ curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN);
+ switch (curproxy->lbprm.algo & BE_LB_KIND) {
+ case BE_LB_KIND_RR:
+ curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
fwrr_init_server_groups(curproxy);
- else if ((curproxy->lbprm.algo & BE_LB_ALGO) == BE_LB_ALGO_LC)
+ break;
+ case BE_LB_KIND_LC:
+ curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
fwlc_init_server_tree(curproxy);
- else
+ break;
+ case BE_LB_KIND_HI:
+ curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
init_server_map(curproxy);
+ break;
+ }
if (curproxy->options & PR_O_LOGASAP)
curproxy->to_log &= ~LW_BYTES;
diff --git a/src/proxy.c b/src/proxy.c
index 7dce8c8..05ed05a 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -323,7 +323,7 @@
Warning("config : monitor-uri will be ignored for %s '%s' (needs 'mode http').\n",
proxy_type_str(curproxy), curproxy->id);
}
- if (curproxy->lbprm.algo & BE_LB_PROP_L7) {
+ if (curproxy->lbprm.algo & BE_LB_NEED_HTTP) {
curproxy->lbprm.algo &= ~BE_LB_ALGO;
curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Warning("config : Layer 7 hash not possible for %s '%s' (needs 'mode http'). Falling back to round robin.\n",