MEDIUM: check: server states and weight propagation re-work
The server state and weight was reworked to handle
"pending" values updated by checks/CLI/LUA/agent.
These values are commited to be propagated to the
LB stack.
In further dev related to multi-thread, the commit
will be handled into a sync point.
Pending values are named using the prefix 'next_'
Current values used by the LB stack are named 'cur_'
diff --git a/include/proto/backend.h b/include/proto/backend.h
index 430a6a1..69ee31c 100644
--- a/include/proto/backend.h
+++ b/include/proto/backend.h
@@ -63,18 +63,19 @@
be->be_counters.last_sess = now.tv_sec;
}
-/* This function returns non-zero if the designated server is usable for LB
- * according to its current weight and current state. Otherwise it returns 0.
+/* This function returns non-zero if the designated server will be
+ * usable for LB according to pending weight and state.
+ * Otherwise it returns 0.
*/
-static inline int srv_is_usable(const struct server *srv)
+static inline int srv_willbe_usable(const struct server *srv)
{
- enum srv_state state = srv->state;
+ enum srv_state state = srv->next_state;
- if (!srv->eweight)
+ if (!srv->next_eweight)
return 0;
- if (srv->admin & SRV_ADMF_MAINT)
+ if (srv->next_admin & SRV_ADMF_MAINT)
return 0;
- if (srv->admin & SRV_ADMF_DRAIN)
+ if (srv->next_admin & SRV_ADMF_DRAIN)
return 0;
switch (state) {
case SRV_ST_STARTING:
@@ -88,17 +89,17 @@
}
/* This function returns non-zero if the designated server was usable for LB
- * according to its current weight and previous state. Otherwise it returns 0.
+ * according to its current weight and state. Otherwise it returns 0.
*/
-static inline int srv_was_usable(const struct server *srv)
+static inline int srv_currently_usable(const struct server *srv)
{
- enum srv_state state = srv->prev_state;
+ enum srv_state state = srv->cur_state;
- if (!srv->prev_eweight)
+ if (!srv->cur_eweight)
return 0;
- if (srv->prev_admin & SRV_ADMF_MAINT)
+ if (srv->cur_admin & SRV_ADMF_MAINT)
return 0;
- if (srv->prev_admin & SRV_ADMF_DRAIN)
+ if (srv->cur_admin & SRV_ADMF_DRAIN)
return 0;
switch (state) {
case SRV_ST_STARTING:
@@ -111,14 +112,14 @@
return 0;
}
-/* This function commits the current server state and weight onto the previous
+/* This function commits the next server state and weight onto the current
* ones in order to detect future changes.
*/
static inline void srv_lb_commit_status(struct server *srv)
{
- srv->prev_state = srv->state;
- srv->prev_admin = srv->admin;
- srv->prev_eweight = srv->eweight;
+ srv->cur_state = srv->next_state;
+ srv->cur_admin = srv->next_admin;
+ srv->cur_eweight = srv->next_eweight;
}
/* This function returns true when a server has experienced a change since last
@@ -126,9 +127,9 @@
*/
static inline int srv_lb_status_changed(const struct server *srv)
{
- return (srv->state != srv->prev_state ||
- srv->admin != srv->prev_admin ||
- srv->eweight != srv->prev_eweight);
+ return (srv->next_state != srv->cur_state ||
+ srv->next_admin != srv->cur_admin ||
+ srv->next_eweight != srv->cur_eweight);
}
/* sends a log message when a backend goes down, and also sets last
diff --git a/include/proto/queue.h b/include/proto/queue.h
index 81b1dda..19212d4 100644
--- a/include/proto/queue.h
+++ b/include/proto/queue.h
@@ -54,7 +54,7 @@
* for and if/else usage.
*/
static inline int may_dequeue_tasks(const struct server *s, const struct proxy *p) {
- return (s && (s->nbpend || (p->nbpend && srv_is_usable(s))) &&
+ return (s && (s->nbpend || (p->nbpend && srv_currently_usable(s))) &&
(!s->maxconn || s->cur_sess < srv_dynamic_maxconn(s)));
}
diff --git a/include/proto/server.h b/include/proto/server.h
index 6663770..0b238a5 100644
--- a/include/proto/server.h
+++ b/include/proto/server.h
@@ -103,7 +103,7 @@
if (!sv->uweight)
return 100;
- return (100U * px->lbprm.wmult * sv->eweight + px->lbprm.wdiv - 1) / (px->lbprm.wdiv * sv->uweight);
+ return (100U * px->lbprm.wmult * sv->cur_eweight + px->lbprm.wdiv - 1) / (px->lbprm.wdiv * sv->uweight);
}
/*
@@ -134,7 +134,7 @@
*/
static inline int server_is_draining(const struct server *s)
{
- return !s->uweight || (s->admin & SRV_ADMF_DRAIN);
+ return !s->uweight || (s->cur_admin & SRV_ADMF_DRAIN);
}
/* Shutdown all connections of a server. The caller must pass a termination