mirror of
https://github.com/nginx/nginx.git
synced 2026-05-06 07:46:38 -04:00
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>
This commit is contained in:
committed by
Aleksei Bavshin
parent
c5036ad30c
commit
d12dd2405d
@@ -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) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user