[CLEANUP] proxy: move last lb-specific bits to their respective files
The lbprm structure has moved to backend.h, where it should be, and
all algo-specific types and declarations have moved to their specific
files. The proxy struct is now much more readable.
diff --git a/include/types/backend.h b/include/types/backend.h
index 983d009..7e5b342 100644
--- a/include/types/backend.h
+++ b/include/types/backend.h
@@ -1,30 +1,34 @@
/*
- include/types/backend.h
- This file assembles definitions for backends
-
- Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation, version 2.1
- exclusively.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ * include/types/backend.h
+ * This file assembles definitions for backends
+ *
+ * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
#ifndef _TYPES_BACKEND_H
#define _TYPES_BACKEND_H
#include <common/config.h>
+#include <types/lb_fwlc.h>
+#include <types/lb_fwrr.h>
+#include <types/lb_map.h>
+#include <types/server.h>
-/* Parameters for proxy->lbprm.algo.
+/* Parameters for lbprm.algo.
* The low part of the value is unique for each algo so that applying the mask
* BE_LB_ALGO returns a unique algorithm.
* The high part indicates specific properties.
@@ -58,6 +62,26 @@
*/
#define BE_WEIGHT_SCALE 16
+/* LB parameters for all algorithms */
+struct lbprm {
+ int algo; /* load balancing algorithm and variants: BE_LB_ALGO_* */
+ int tot_wact, tot_wbck; /* total effective weights of active and backup servers */
+ int tot_weight; /* total effective weight of servers participating to LB */
+ int tot_used; /* total number of servers used for LB */
+ int wmult; /* ratio between user weight and effective weight */
+ int wdiv; /* ratio between effective weight and user weight */
+ struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */
+ struct lb_map map; /* LB parameters for map-based algorithms */
+ struct lb_fwrr fwrr;
+ struct lb_fwlc fwlc;
+ /* Call backs for some actions. Some may be NULL (thus should be ignored). */
+ void (*update_server_eweight)(struct server *); /* to be called after eweight change */
+ void (*set_server_status_up)(struct server *); /* to be called after status changes to UP */
+ void (*set_server_status_down)(struct server *); /* to be called after status changes to DOWN */
+ void (*server_take_conn)(struct server *); /* to be called when connection is assigned */
+ void (*server_drop_conn)(struct server *); /* to be called when connection is dropped */
+};
+
#endif /* _TYPES_BACKEND_H */
/*
diff --git a/include/types/lb_fwlc.h b/include/types/lb_fwlc.h
new file mode 100644
index 0000000..cad4d13
--- /dev/null
+++ b/include/types/lb_fwlc.h
@@ -0,0 +1,40 @@
+/*
+ * include/types/lb_fwlc.h
+ * Types for Fast Weighted Least Connection load balancing algorithm.
+ *
+ * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TYPES_LB_FWLC_H
+#define _TYPES_LB_FWLC_H
+
+#include <common/config.h>
+#include <common/ebtree.h>
+
+struct lb_fwlc {
+ struct eb_root act; /* weighted least conns on the active servers */
+ struct eb_root bck; /* weighted least conns on the backup servers */
+};
+
+#endif /* _TYPES_LB_FWLC_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/lb_fwrr.h b/include/types/lb_fwrr.h
new file mode 100644
index 0000000..600a511
--- /dev/null
+++ b/include/types/lb_fwrr.h
@@ -0,0 +1,51 @@
+/*
+ * include/types/lb_fwrr.h
+ * Types for Fast Weighted Round Robin load balancing algorithm.
+ *
+ * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TYPES_LB_FWRR_H
+#define _TYPES_LB_FWRR_H
+
+#include <common/config.h>
+#include <common/ebtree.h>
+
+/* This structure is used to apply fast weighted round robin on a server group */
+struct fwrr_group {
+ struct eb_root curr; /* tree for servers in "current" time range */
+ struct eb_root t0, t1; /* "init" and "next" servers */
+ struct eb_root *init; /* servers waiting to be placed */
+ struct eb_root *next; /* servers to be placed at next run */
+ int curr_pos; /* current position in the tree */
+ int curr_weight; /* total weight of the current time range */
+ int next_weight; /* total weight of the next time range */
+};
+
+struct lb_fwrr {
+ struct fwrr_group act; /* weighted round robin on the active servers */
+ struct fwrr_group bck; /* weighted round robin on the backup servers */
+};
+
+#endif /* _TYPES_LB_FWRR_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/lb_map.h b/include/types/lb_map.h
new file mode 100644
index 0000000..4c12089
--- /dev/null
+++ b/include/types/lb_map.h
@@ -0,0 +1,44 @@
+/*
+ * include/types/lb_map.h
+ * Types for map-based load-balancing (RR and HASH)
+ *
+ * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _TYPES_LB_MAP_H
+#define _TYPES_LB_MAP_H
+
+#include <common/config.h>
+#include <types/server.h>
+
+/* values for map.state */
+#define LB_MAP_RECALC (1 << 0)
+
+struct lb_map {
+ struct server **srv; /* the server map used to apply weights */
+ int rr_idx; /* next server to be elected in round robin mode */
+ int state; /* LB_MAP_RECALC */
+};
+
+#endif /* _TYPES_LB_MAP_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ */
diff --git a/include/types/proxy.h b/include/types/proxy.h
index 2cdf689..6af0a24 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -1,23 +1,23 @@
/*
- include/types/proxy.h
- This file defines everything related to proxies.
-
- Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation, version 2.1
- exclusively.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ * include/types/proxy.h
+ * This file defines everything related to proxies.
+ *
+ * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
#ifndef _TYPES_PROXY_H
#define _TYPES_PROXY_H
@@ -29,13 +29,13 @@
#include <common/appsession.h>
#include <common/config.h>
-#include <common/ebtree.h>
#include <common/mini-clist.h>
#include <common/regex.h>
#include <common/sessionhash.h>
#include <common/tools.h>
#include <types/acl.h>
+#include <types/backend.h>
#include <types/buffers.h>
#include <types/freq_ctr.h>
#include <types/httperr.h>
@@ -57,9 +57,6 @@
#define PR_MODE_HTTP 1
#define PR_MODE_HEALTH 2
-/* values for proxy->lbprm.map.state */
-#define PR_MAP_RECALC (1 << 0)
-
/* flag values for proxy->cap. This is a bitmask of capabilities supported by the proxy */
#define PR_CAP_NONE 0x0000
#define PR_CAP_FE 0x0001
@@ -123,17 +120,6 @@
#define PR_O2_CLFLOG 0x00000400 /* log into clf format */
#define PR_O2_LOGHCHKS 0x00000800 /* log health checks */
-/* This structure is used to apply fast weighted round robin on a server group */
-struct fwrr_group {
- struct eb_root curr; /* tree for servers in "current" time range */
- struct eb_root t0, t1; /* "init" and "next" servers */
- struct eb_root *init; /* servers waiting to be placed */
- struct eb_root *next; /* servers to be placed at next run */
- int curr_pos; /* current position in the tree */
- int curr_weight; /* total weight of the current time range */
- int next_weight; /* total weight of the next time range */
-};
-
struct error_snapshot {
struct timeval when; /* date of this event, (tv_sec == 0) means "never" */
unsigned int len; /* original length of the last invalid request/response */
@@ -170,35 +156,7 @@
int acl_requires; /* Elements required to satisfy all ACLs (ACL_USE_*) */
struct server *srv; /* known servers */
int srv_act, srv_bck; /* # of servers eligible for LB (UP|!checked) AND (enabled+weight!=0) */
-
- struct {
- int algo; /* load balancing algorithm and variants: BE_LB_ALGO* */
- int tot_wact, tot_wbck; /* total effective weights of active and backup servers */
- int tot_weight; /* total effective weight of servers participating to LB */
- int tot_used; /* total number of servers used for LB */
- int wmult; /* ratio between user weight and effective weight */
- int wdiv; /* ratio between effective weight and user weight */
- struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */
- struct {
- struct server **srv; /* the server map used to apply weights */
- int rr_idx; /* next server to be elected in round robin mode */
- int state; /* PR_MAP_RECALC */
- } map; /* LB parameters for map-based algorithms */
- struct {
- struct fwrr_group act; /* weighted round robin on the active servers */
- struct fwrr_group bck; /* weighted round robin on the backup servers */
- } fwrr;
- struct {
- struct eb_root act; /* weighted least conns on the active servers */
- struct eb_root bck; /* weighted least conns on the backup servers */
- } fwlc;
- void (*update_server_eweight)(struct server *);/* if non-NULL, to be called after eweight change */
- void (*set_server_status_up)(struct server *);/* to be called after status changes to UP */
- void (*set_server_status_down)(struct server *);/* to be called after status changes to DOWN */
- void (*server_take_conn)(struct server *);/* to be called when connection is assigned */
- void (*server_drop_conn)(struct server *);/* to be called when connection is dropped */
- } lbprm; /* LB parameters for all algorithms */
-
+ struct lbprm lbprm; /* load-balancing parameters */
char *cookie_domain; /* domain used to insert the cookie */
char *cookie_name; /* name of the cookie to look for */
int cookie_len; /* strlen(cookie_name), computed only once */
diff --git a/src/lb_map.c b/src/lb_map.c
index 27e8e85..2918c26 100644
--- a/src/lb_map.c
+++ b/src/lb_map.c
@@ -38,7 +38,7 @@
/* FIXME: could be optimized since we know what changed */
recount_servers(p);
update_backend_weight(p);
- p->lbprm.map.state |= PR_MAP_RECALC;
+ p->lbprm.map.state |= LB_MAP_RECALC;
out_update_state:
srv->prev_state = srv->state;
srv->prev_eweight = srv->eweight;
@@ -59,7 +59,7 @@
/* FIXME: could be optimized since we know what changed */
recount_servers(p);
update_backend_weight(p);
- p->lbprm.map.state |= PR_MAP_RECALC;
+ p->lbprm.map.state |= LB_MAP_RECALC;
out_update_state:
srv->prev_state = srv->state;
srv->prev_eweight = srv->eweight;
@@ -77,7 +77,7 @@
switch (px->lbprm.tot_used) {
case 0: /* no server */
- px->lbprm.map.state &= ~PR_MAP_RECALC;
+ px->lbprm.map.state &= ~LB_MAP_RECALC;
return;
case 1: /* only one server, just fill first entry */
tot = 1;
@@ -132,7 +132,7 @@
px->lbprm.map.srv[o] = best;
best->wscore -= tot;
}
- px->lbprm.map.state &= ~PR_MAP_RECALC;
+ px->lbprm.map.state &= ~LB_MAP_RECALC;
}
/* This function is responsible of building the server MAP for map-based LB
@@ -201,7 +201,7 @@
p->lbprm.map.srv = (struct server **)calloc(act, sizeof(struct server *));
/* recounts servers and their weights */
- p->lbprm.map.state = PR_MAP_RECALC;
+ p->lbprm.map.state = LB_MAP_RECALC;
recount_servers(p);
update_backend_weight(p);
recalc_server_map(p);
@@ -221,7 +221,7 @@
if (px->lbprm.tot_weight == 0)
return NULL;
- if (px->lbprm.map.state & PR_MAP_RECALC)
+ if (px->lbprm.map.state & LB_MAP_RECALC)
recalc_server_map(px);
if (px->lbprm.map.rr_idx < 0 || px->lbprm.map.rr_idx >= px->lbprm.tot_weight)
@@ -264,7 +264,7 @@
if (px->lbprm.tot_weight == 0)
return NULL;
- if (px->lbprm.map.state & PR_MAP_RECALC)
+ if (px->lbprm.map.state & LB_MAP_RECALC)
recalc_server_map(px);
return px->lbprm.map.srv[hash % px->lbprm.tot_weight];