diff options
| author | Vladimir Homutov <vl@nginx.com> | 2014-08-28 11:53:49 +0400 |
|---|---|---|
| committer | Aleksei Bavshin <a.bavshin@f5.com> | 2026-03-09 11:08:30 -0600 |
| commit | d12dd2405d659707f75eaa93d45ed762cc5bdd5d (patch) | |
| tree | 661d238dfa4dc8556682ddd8a8dc6fd6a5a1d4b8 | |
| parent | c5036ad30cfafb233494fa81c0b328aac3eb0e9b (diff) | |
| download | nginx-d12dd2405d659707f75eaa93d45ed762cc5bdd5d.tar.gz nginx-d12dd2405d659707f75eaa93d45ed762cc5bdd5d.tar.bz2 | |
Sticky: added "draining" peer state.
While peer is draining, only sticky requests are served and the peer is never
selected to process new requests.
Co-authored-by: Ruslan Ermilov <ru@nginx.com>
| -rw-r--r-- | src/http/ngx_http_upstream.c | 13 | ||||
| -rw-r--r-- | src/http/ngx_http_upstream_round_robin.c | 26 | ||||
| -rw-r--r-- | src/http/ngx_http_upstream_round_robin.h | 4 |
3 files changed, 36 insertions, 7 deletions
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 270e5dac6..88d954f17 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -6535,6 +6535,19 @@ ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) continue; } +#if (NGX_HTTP_UPSTREAM_STICKY) + if (ngx_strcmp(value[i].data, "drain") == 0) { + + if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) { + goto not_supported; + } + + us->down = NGX_HTTP_UPSTREAM_DRAINING; + + continue; + } +#endif + #if (NGX_HTTP_UPSTREAM_SID) if (ngx_strncmp(value[i].data, "route=", 6) == 0) { diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c index afbb1f23e..412281767 100644 --- a/src/http/ngx_http_upstream_round_robin.c +++ b/src/http/ngx_http_upstream_round_robin.c @@ -719,15 +719,23 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data) #endif if (peers->single) { - peer = peers->peer; +#if (NGX_HTTP_UPSTREAM_SID) + peer = ngx_http_upstream_get_rr_peer_by_sid(rrp, pc->hint, &i, 0); - if (peer->down) { - goto failed; - } + if (peer == NULL) { +#endif + peer = peers->peer; - if (peer->max_conns && peer->conns >= peer->max_conns) { - goto failed; + if (peer->down) { + goto failed; + } + + if (peer->max_conns && peer->conns >= peer->max_conns) { + goto failed; + } +#if (NGX_HTTP_UPSTREAM_SID) } +#endif rrp->current = peer; ngx_http_upstream_rr_peer_ref(peers, peer); @@ -962,7 +970,11 @@ found: ngx_http_upstream_rr_peer_lock(rrp->peers, peer); } - if (peer->down) { + if (peer->down +#if (NGX_HTTP_UPSTREAM_STICKY) + & ~NGX_HTTP_UPSTREAM_DRAINING +#endif + ) { goto failed; } diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h index 544d0fa20..95c7ae190 100644 --- a/src/http/ngx_http_upstream_round_robin.h +++ b/src/http/ngx_http_upstream_round_robin.h @@ -20,6 +20,10 @@ #define NGX_HTTP_UPSTREAM_FAILED 1 +#if (NGX_HTTP_UPSTREAM_STICKY) +#define NGX_HTTP_UPSTREAM_DRAINING 8 +#endif + typedef struct ngx_http_upstream_rr_peers_s ngx_http_upstream_rr_peers_t; typedef struct ngx_http_upstream_rr_peer_s ngx_http_upstream_rr_peer_t; |
