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:
Vladimir Homutov
2014-08-28 11:53:49 +04:00
committed by Aleksei Bavshin
parent c5036ad30c
commit d12dd2405d
3 changed files with 36 additions and 7 deletions
+13
View File
@@ -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) {
+19 -7
View File
@@ -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;
}
+4
View File
@@ -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;