MEDIUM: checks: simplify stopping mode notification using srv_set_stopping()

Function check_set_server_drain() used to set a server into stopping state.
Now it first checks if all configured checks are UP, and if the possibly
tracked servers is not stopped, and only calls set_srv_stopping() after
that. That also simplified the conditions to call the function, and its
logic. The function was also renamed check_notify_stopping() to better
report this change.
This commit is contained in:
Willy Tarreau 2014-05-21 13:57:23 +02:00
parent 3e04838b8a
commit db58b79ccd

View File

@ -348,51 +348,32 @@ static void check_notify_success(struct check *check)
srv_set_running(s, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check_reason_string(check) : NULL); srv_set_running(s, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check_reason_string(check) : NULL);
} }
/* Marks the check <check> as valid and tries to set its server into drain mode, /* Marks the check <check> as valid and tries to set its server into stopping mode
* provided it isn't in maintenance and other checks comply. Notifies by all * if it was running or starting, and provided it isn't in maintenance and other
* available means, recounts the remaining servers on the proxy and tries to * checks comply. The conditions for the server to be marked in stopping mode are
* grab requests from the proxy. It automatically recomputes the number of * the same as for it to be turned up. Also, only the health checks support the
* servers, but not the map. Maintenance servers are ignored. Those that were * nolb mode.
* not in perfect health are simply refreshed.
*/ */
static void check_set_server_drain(struct check *check) static void check_notify_stopping(struct check *check)
{ {
struct server *s = check->server; struct server *s = check->server;
struct server *srv;
int xferred;
if (s->admin & SRV_ADMF_MAINT) if (s->admin & SRV_ADMF_MAINT)
return; return;
s->state = SRV_ST_STOPPING; if (check->state & CHK_ST_AGENT)
if (s->proxy->lbprm.set_server_status_down) return;
s->proxy->lbprm.set_server_status_down(s);
/* we might have sessions queued on this server and waiting for if (s->track && s->track->state == SRV_ST_STOPPED)
* a connection. Those which are redispatchable will be queued return;
* to another server or to the proxy itself.
*/
xferred = pendconn_redistribute(s);
chunk_printf(&trash, if ((s->check.state & CHK_ST_ENABLED) && (s->check.health < s->check.rise))
"%sServer %s/%s is stopping", s->flags & SRV_F_BACKUP ? "Backup " : "", return;
s->proxy->id, s->id);
srv_append_status(&trash, s, if ((s->agent.state & CHK_ST_ENABLED) && (s->agent.health < s->agent.rise))
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check_reason_string(check) : NULL), return;
xferred, 0);
Warning("%s.\n", trash.str); srv_set_stopping(s, (!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? check_reason_string(check) : NULL);
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str);
if (!s->proxy->srv_bck && !s->proxy->srv_act)
set_backend_down(s->proxy);
for (srv = s->trackers; srv; srv = srv->tracknext)
check_set_server_drain(&srv->check);
if (check->health >= check->rise)
check->health = check->rise + check->fall - 1; /* OK now */
} }
/* note: use health_adjust() only, which first checks that the observe mode is /* note: use health_adjust() only, which first checks that the observe mode is
@ -1451,10 +1432,9 @@ static struct task *process_chk(struct task *t)
/* a failure or timeout detected */ /* a failure or timeout detected */
check_notify_failure(check); check_notify_failure(check);
} }
else if (check->result == CHK_RES_CONDPASS && s->state != SRV_ST_STOPPED && !(s->admin & SRV_ADMF_MAINT)) { else if (check->result == CHK_RES_CONDPASS) {
/* check is OK but asks for drain mode */ /* check is OK but asks for stopping mode */
if (check->health >= check->rise && check->server->state != SRV_ST_STOPPING) check_notify_stopping(check);
check_set_server_drain(check);
} }
else if (check->result == CHK_RES_PASSED) { else if (check->result == CHK_RES_PASSED) {
/* a success was detected */ /* a success was detected */