[MINOR] backend: export some functions to recount servers

Those functions will be used by new LB algorithms.
This commit is contained in:
Willy Tarreau 2009-10-01 09:17:05 +02:00
parent 2f9cc8ab52
commit c5d9c80182
2 changed files with 18 additions and 36 deletions

View File

@ -42,6 +42,22 @@ int be_downtime(struct proxy *px);
void init_server_map(struct proxy *p);
void fwrr_init_server_groups(struct proxy *p);
void fwlc_init_server_tree(struct proxy *p);
void recount_servers(struct proxy *px);
void update_backend_weight(struct proxy *px);
/* This function returns non-zero if a server with the given weight and state
* is usable for LB, otherwise zero.
*/
static inline int srv_is_usable(int state, int weight)
{
if (!weight)
return 0;
if (state & SRV_GOINGDOWN)
return 0;
if (!(state & SRV_RUNNING))
return 0;
return 1;
}
/*
* This function tries to find a running server with free connection slots for
@ -90,26 +106,6 @@ static inline struct server *get_server_rr_with_conns(struct proxy *px, struct s
}
/*
* This function tries to find a running server for the proxy <px> following
* the round-robin method.
* If any server is found, it will be returned and px->lbprm.map.rr_idx will be updated
* to point to the next server. If no valid server is found, NULL is returned.
*/
static inline struct server *get_server_rr(struct proxy *px)
{
if (px->lbprm.tot_weight == 0)
return NULL;
if (px->lbprm.map.state & PR_MAP_RECALC)
recalc_server_map(px);
if (px->lbprm.map.rr_idx < 0 || px->lbprm.map.rr_idx >= px->lbprm.tot_weight)
px->lbprm.map.rr_idx = 0;
return px->lbprm.map.srv[px->lbprm.map.rr_idx++];
}
/*
* This function tries to find a running server for the proxy <px> following
* the source hash method. Depending on the number of active/backup servers,

View File

@ -44,20 +44,6 @@ static inline void fwrr_dequeue_srv(struct server *s);
static void fwrr_get_srv(struct server *s);
static void fwrr_queue_srv(struct server *s);
/* This function returns non-zero if a server with the given weight and state
* is usable for LB, otherwise zero.
*/
static inline int srv_is_usable(int state, int weight)
{
if (!weight)
return 0;
if (state & SRV_GOINGDOWN)
return 0;
if (!(state & SRV_RUNNING))
return 0;
return 1;
}
/*
* 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.
@ -65,7 +51,7 @@ static inline int srv_is_usable(int state, int weight)
* it does not update tot_weight nor tot_used. Use update_backend_weight() for
* this.
*/
static void recount_servers(struct proxy *px)
void recount_servers(struct proxy *px)
{
struct server *srv;
@ -93,7 +79,7 @@ static void recount_servers(struct proxy *px)
* after servers weights have been updated. It is designed to be used after
* recount_servers() or equivalent.
*/
static void update_backend_weight(struct proxy *px)
void update_backend_weight(struct proxy *px)
{
if (px->srv_act) {
px->lbprm.tot_weight = px->lbprm.tot_wact;