You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
242 lines
8.2 KiB
242 lines
8.2 KiB
diff --git a/src/http/modules/ngx_http_upstream_hash_module.c b/src/http/modules/ngx_http_upstream_hash_module.c
|
|
index 6c247b5..1ae9cce 100644
|
|
--- a/src/http/modules/ngx_http_upstream_hash_module.c
|
|
+++ b/src/http/modules/ngx_http_upstream_hash_module.c
|
|
@@ -9,6 +9,9 @@
|
|
#include <ngx_core.h>
|
|
#include <ngx_http.h>
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+#include "ngx_http_upstream_check_module.h"
|
|
+#endif
|
|
|
|
typedef struct {
|
|
uint32_t hash;
|
|
@@ -238,6 +241,14 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
|
goto next;
|
|
}
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
|
+ "get hash peer, check_index: %ui", peer->check_index);
|
|
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
|
|
+ goto next;
|
|
+ }
|
|
+#endif
|
|
+
|
|
if (peer->max_fails
|
|
&& peer->fails >= peer->max_fails
|
|
&& now - peer->checked <= peer->fail_timeout)
|
|
@@ -560,6 +571,15 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
|
|
continue;
|
|
}
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
|
+ "get consistent_hash peer, check_index: %ui",
|
|
+ peer->check_index);
|
|
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
|
|
+ continue;
|
|
+ }
|
|
+#endif
|
|
+
|
|
if (peer->server.len != server->len
|
|
|| ngx_strncmp(peer->server.data, server->data, server->len)
|
|
!= 0)
|
|
diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c
|
|
index 1fa01d9..366aca9 100644
|
|
--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c
|
|
+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c
|
|
@@ -9,6 +9,9 @@
|
|
#include <ngx_core.h>
|
|
#include <ngx_http.h>
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+#include "ngx_http_upstream_check_module.h"
|
|
+#endif
|
|
|
|
typedef struct {
|
|
/* the round robin data must be first */
|
|
@@ -208,6 +211,15 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
|
|
goto next;
|
|
}
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
|
+ "get ip_hash peer, check_index: %ui",
|
|
+ peer->check_index);
|
|
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
|
|
+ goto next;
|
|
+ }
|
|
+#endif
|
|
+
|
|
if (peer->max_fails
|
|
&& peer->fails >= peer->max_fails
|
|
&& now - peer->checked <= peer->fail_timeout)
|
|
diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c
|
|
index ebe0627..3525035 100644
|
|
--- a/src/http/modules/ngx_http_upstream_least_conn_module.c
|
|
+++ b/src/http/modules/ngx_http_upstream_least_conn_module.c
|
|
@@ -9,6 +9,9 @@
|
|
#include <ngx_core.h>
|
|
#include <ngx_http.h>
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+#include "ngx_http_upstream_check_module.h"
|
|
+#endif
|
|
|
|
static ngx_int_t ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r,
|
|
ngx_http_upstream_srv_conf_t *us);
|
|
@@ -147,6 +150,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
|
|
continue;
|
|
}
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
|
+ "get least_conn peer, check_index: %ui",
|
|
+ peer->check_index);
|
|
+
|
|
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
|
|
+ continue;
|
|
+ }
|
|
+#endif
|
|
+
|
|
if (peer->max_fails
|
|
&& peer->fails >= peer->max_fails
|
|
&& now - peer->checked <= peer->fail_timeout)
|
|
@@ -202,6 +215,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
|
|
continue;
|
|
}
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
|
|
+ "get least_conn peer, check_index: %ui",
|
|
+ peer->check_index);
|
|
+
|
|
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
|
|
+ continue;
|
|
+ }
|
|
+#endif
|
|
+
|
|
if (peer->conns * best->weight != best->conns * peer->weight) {
|
|
continue;
|
|
}
|
|
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
|
|
index f72de3e..78b3342 100644
|
|
--- a/src/http/ngx_http_upstream_round_robin.c
|
|
+++ b/src/http/ngx_http_upstream_round_robin.c
|
|
@@ -9,6 +9,9 @@
|
|
#include <ngx_core.h>
|
|
#include <ngx_http.h>
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+#include "ngx_http_upstream_check_module.h"
|
|
+#endif
|
|
|
|
#define ngx_http_upstream_tries(p) ((p)->number \
|
|
+ ((p)->next ? (p)->next->number : 0))
|
|
@@ -98,6 +101,15 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
|
|
peer[n].down = server[i].down;
|
|
peer[n].server = server[i].name;
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ if (!server[i].down) {
|
|
+ peer[n].check_index =
|
|
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
|
|
+ } else {
|
|
+ peer[n].check_index = (ngx_uint_t) NGX_ERROR;
|
|
+ }
|
|
+#endif
|
|
+
|
|
*peerp = &peer[n];
|
|
peerp = &peer[n].next;
|
|
n++;
|
|
@@ -162,6 +174,16 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
|
|
peer[n].down = server[i].down;
|
|
peer[n].server = server[i].name;
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ if (!server[i].down) {
|
|
+ peer[n].check_index =
|
|
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
|
|
+ }
|
|
+ else {
|
|
+ peer[n].check_index = (ngx_uint_t) NGX_ERROR;
|
|
+ }
|
|
+#endif
|
|
+
|
|
*peerp = &peer[n];
|
|
peerp = &peer[n].next;
|
|
n++;
|
|
@@ -228,6 +250,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
|
|
peer[i].max_conns = 0;
|
|
peer[i].max_fails = 1;
|
|
peer[i].fail_timeout = 10;
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ peer[i].check_index = (ngx_uint_t) NGX_ERROR;
|
|
+#endif
|
|
*peerp = &peer[i];
|
|
peerp = &peer[i].next;
|
|
}
|
|
@@ -344,6 +369,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
|
|
peer[0].max_conns = 0;
|
|
peer[0].max_fails = 1;
|
|
peer[0].fail_timeout = 10;
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ peer[0].check_index = (ngx_uint_t) NGX_ERROR;
|
|
+#endif
|
|
peers->peer = peer;
|
|
|
|
} else {
|
|
@@ -378,6 +406,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
|
|
peer[i].max_conns = 0;
|
|
peer[i].max_fails = 1;
|
|
peer[i].fail_timeout = 10;
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ peer[i].check_index = (ngx_uint_t) NGX_ERROR;
|
|
+#endif
|
|
*peerp = &peer[i];
|
|
peerp = &peer[i].next;
|
|
}
|
|
@@ -443,6 +474,12 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
|
|
goto failed;
|
|
}
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
|
|
+ goto failed;
|
|
+ }
|
|
+#endif
|
|
+
|
|
rrp->current = peer;
|
|
|
|
} else {
|
|
@@ -537,6 +574,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
|
|
continue;
|
|
}
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
|
|
+ continue;
|
|
+ }
|
|
+#endif
|
|
+
|
|
if (peer->max_fails
|
|
&& peer->fails >= peer->max_fails
|
|
&& now - peer->checked <= peer->fail_timeout)
|
|
diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h
|
|
index 45f258d..dee91d0 100644
|
|
--- a/src/http/ngx_http_upstream_round_robin.h
|
|
+++ b/src/http/ngx_http_upstream_round_robin.h
|
|
@@ -38,6 +38,10 @@ struct ngx_http_upstream_rr_peer_s {
|
|
ngx_msec_t slow_start;
|
|
ngx_msec_t start_time;
|
|
|
|
+#if (NGX_HTTP_UPSTREAM_CHECK)
|
|
+ ngx_uint_t check_index;
|
|
+#endif
|
|
+
|
|
ngx_uint_t down;
|
|
|
|
#if (NGX_HTTP_SSL || NGX_COMPAT)
|