]> git.kaiwu.me - nginx.git/commitdiff
Sticky: added "draining" peer state.
authorVladimir Homutov <vl@nginx.com>
Thu, 28 Aug 2014 07:53:49 +0000 (11:53 +0400)
committerAleksei Bavshin <a.bavshin@f5.com>
Mon, 9 Mar 2026 17:08:30 +0000 (11:08 -0600)
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>
src/http/ngx_http_upstream.c
src/http/ngx_http_upstream_round_robin.c
src/http/ngx_http_upstream_round_robin.h

index 270e5dac6072608f2eecd22fbc35a5dce6c5447c..88d954f17801dec62f424411d13f13199695f57c 100644 (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) {
 
index afbb1f23e1f79506124b97db50893b1e6e82c328..41228176726ce638f70b8c5fe75bb34e41d4e436 100644 (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;
     }
 
index 544d0fa20a95139c2d6228739da2118102d1162d..95c7ae19060a19d7496473ce566edeb813ad9094 100644 (file)
 
 #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;