From 266b1a8336bcb9a2d5de772a14b9d84af25bcf81 Mon Sep 17 00:00:00 2001 From: Michal Idzikowski Date: Mon, 27 Mar 2017 14:45:49 +0200 Subject: [PATCH] MEDIUM: server: Inherit CLI weight changes and agent-check weight responses When agent-check or CLI command executes relative weight change this patch propagates it to tracking server allowing grouping many backends running on same server underneath. Additionaly in case with many src IPs many backends can have shared state checker, so there won't be unnecessary health checks. [wt: Note: this will induce some behaviour change on some setups] --- doc/configuration.txt | 4 ++++ doc/management.txt | 4 ++++ src/server.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index 05f07019f..291458167 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -11422,6 +11422,10 @@ track [/] enabled. If is omitted the current one is used. If disable-on-404 is used, it has to be enabled on both proxies. + Note: + Relative weight changes are propagated to all tracking servers. Each + tracking server will have its weight recalculated separately. + tlsv10 This option may be used as "server" setting to reset any "no-tlsv10" setting which would have been inherited from "default-server" directive as diff --git a/doc/management.txt b/doc/management.txt index 1d34f8436..d4b7b6850 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -1694,6 +1694,10 @@ set weight / [%] "admin". Both the backend and the server may be specified either by their name or by their numeric ID, prefixed with a sharp ('#'). + Note: + Relative weight changes are propagated to all tracking servers. Each + tracking server will have its weight recalculated separately. + show cli sockets List CLI sockets. The output format is composed of 3 fields separated by spaces. The first field is the socket address, it can be a unix socket, a diff --git a/src/server.c b/src/server.c index b5d889005..721de33bc 100644 --- a/src/server.c +++ b/src/server.c @@ -47,6 +47,9 @@ static void srv_update_state(struct server *srv, int version, char **params); static int srv_apply_lastaddr(struct server *srv, int *err_code); +const char *server_propagate_weight_change_request(struct server *sv, + const char *weight_str); + /* List head of all known server keywords */ static struct srv_kw_list srv_keywords = { .list = LIST_HEAD_INIT(srv_keywords.list) @@ -1445,6 +1448,8 @@ const char *server_parse_weight_change_request(struct server *sv, struct proxy *px; long int w; char *end; + const char *msg; + int relative = 0; px = sv->proxy; @@ -1466,6 +1471,8 @@ const char *server_parse_weight_change_request(struct server *sv, w = sv->iweight * w / 100; if (w > 256) w = 256; + + relative = 1; } else if (w < 0 || w > 256) return "Absolute weight can only be between 0 and 256 inclusive.\n"; @@ -1478,6 +1485,28 @@ const char *server_parse_weight_change_request(struct server *sv, sv->uweight = w; server_recalc_eweight(sv); + if (relative) { + msg = server_propagate_weight_change_request(sv, weight_str); + if (msg != NULL) { + return msg; + } + } + + return NULL; +} + +const char *server_propagate_weight_change_request(struct server *sv, + const char *weight_str) +{ + struct server *tracker; + const char *msg; + + for (tracker = sv->trackers; tracker; tracker = tracker->tracknext) { + msg = server_parse_weight_change_request(tracker, weight_str); + if (msg) + return msg; + } + return NULL; }