|
| 1 | +diff --git a/src/http/modules/ngx_http_upstream_hash_module.c b/src/http/modules/ngx_http_upstream_hash_module.c |
| 2 | +index 6c247b5..1ae9cce 100644 |
| 3 | +--- a/src/http/modules/ngx_http_upstream_hash_module.c |
| 4 | ++++ b/src/http/modules/ngx_http_upstream_hash_module.c |
| 5 | +@@ -9,6 +9,9 @@ |
| 6 | + #include <ngx_core.h> |
| 7 | + #include <ngx_http.h> |
| 8 | + |
| 9 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 10 | ++#include "ngx_http_upstream_check_module.h" |
| 11 | ++#endif |
| 12 | + |
| 13 | + typedef struct { |
| 14 | + uint32_t hash; |
| 15 | +@@ -238,6 +241,14 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data) |
| 16 | + goto next; |
| 17 | + } |
| 18 | + |
| 19 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 20 | ++ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
| 21 | ++ "get hash peer, check_index: %ui", peer->check_index); |
| 22 | ++ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 23 | ++ goto next; |
| 24 | ++ } |
| 25 | ++#endif |
| 26 | ++ |
| 27 | + if (peer->max_fails |
| 28 | + && peer->fails >= peer->max_fails |
| 29 | + && now - peer->checked <= peer->fail_timeout) |
| 30 | +@@ -560,6 +571,15 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data) |
| 31 | + continue; |
| 32 | + } |
| 33 | + |
| 34 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 35 | ++ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
| 36 | ++ "get consistent_hash peer, check_index: %ui", |
| 37 | ++ peer->check_index); |
| 38 | ++ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 39 | ++ continue; |
| 40 | ++ } |
| 41 | ++#endif |
| 42 | ++ |
| 43 | + if (peer->server.len != server->len |
| 44 | + || ngx_strncmp(peer->server.data, server->data, server->len) |
| 45 | + != 0) |
| 46 | +diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c |
| 47 | +index 1fa01d9..366aca9 100644 |
| 48 | +--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c |
| 49 | ++++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c |
| 50 | +@@ -9,6 +9,9 @@ |
| 51 | + #include <ngx_core.h> |
| 52 | + #include <ngx_http.h> |
| 53 | + |
| 54 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 55 | ++#include "ngx_http_upstream_check_module.h" |
| 56 | ++#endif |
| 57 | + |
| 58 | + typedef struct { |
| 59 | + /* the round robin data must be first */ |
| 60 | +@@ -208,6 +211,15 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data) |
| 61 | + goto next; |
| 62 | + } |
| 63 | + |
| 64 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 65 | ++ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
| 66 | ++ "get ip_hash peer, check_index: %ui", |
| 67 | ++ peer->check_index); |
| 68 | ++ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 69 | ++ goto next; |
| 70 | ++ } |
| 71 | ++#endif |
| 72 | ++ |
| 73 | + if (peer->max_fails |
| 74 | + && peer->fails >= peer->max_fails |
| 75 | + && now - peer->checked <= peer->fail_timeout) |
| 76 | +diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c |
| 77 | +index ebe0627..3525035 100644 |
| 78 | +--- a/src/http/modules/ngx_http_upstream_least_conn_module.c |
| 79 | ++++ b/src/http/modules/ngx_http_upstream_least_conn_module.c |
| 80 | +@@ -9,6 +9,9 @@ |
| 81 | + #include <ngx_core.h> |
| 82 | + #include <ngx_http.h> |
| 83 | + |
| 84 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 85 | ++#include "ngx_http_upstream_check_module.h" |
| 86 | ++#endif |
| 87 | + |
| 88 | + static ngx_int_t ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r, |
| 89 | + ngx_http_upstream_srv_conf_t *us); |
| 90 | +@@ -147,6 +150,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data) |
| 91 | + continue; |
| 92 | + } |
| 93 | + |
| 94 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 95 | ++ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
| 96 | ++ "get least_conn peer, check_index: %ui", |
| 97 | ++ peer->check_index); |
| 98 | ++ |
| 99 | ++ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 100 | ++ continue; |
| 101 | ++ } |
| 102 | ++#endif |
| 103 | ++ |
| 104 | + if (peer->max_fails |
| 105 | + && peer->fails >= peer->max_fails |
| 106 | + && now - peer->checked <= peer->fail_timeout) |
| 107 | +@@ -202,6 +215,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data) |
| 108 | + continue; |
| 109 | + } |
| 110 | + |
| 111 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 112 | ++ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
| 113 | ++ "get least_conn peer, check_index: %ui", |
| 114 | ++ peer->check_index); |
| 115 | ++ |
| 116 | ++ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 117 | ++ continue; |
| 118 | ++ } |
| 119 | ++#endif |
| 120 | ++ |
| 121 | + if (peer->conns * best->weight != best->conns * peer->weight) { |
| 122 | + continue; |
| 123 | + } |
| 124 | +diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c |
| 125 | +index f72de3e..78b3342 100644 |
| 126 | +--- a/src/http/ngx_http_upstream_round_robin.c |
| 127 | ++++ b/src/http/ngx_http_upstream_round_robin.c |
| 128 | +@@ -9,6 +9,9 @@ |
| 129 | + #include <ngx_core.h> |
| 130 | + #include <ngx_http.h> |
| 131 | + |
| 132 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 133 | ++#include "ngx_http_upstream_check_module.h" |
| 134 | ++#endif |
| 135 | + |
| 136 | + #define ngx_http_upstream_tries(p) ((p)->number \ |
| 137 | + + ((p)->next ? (p)->next->number : 0)) |
| 138 | +@@ -98,6 +101,15 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, |
| 139 | + peer[n].down = server[i].down; |
| 140 | + peer[n].server = server[i].name; |
| 141 | + |
| 142 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 143 | ++ if (!server[i].down) { |
| 144 | ++ peer[n].check_index = |
| 145 | ++ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]); |
| 146 | ++ } else { |
| 147 | ++ peer[n].check_index = (ngx_uint_t) NGX_ERROR; |
| 148 | ++ } |
| 149 | ++#endif |
| 150 | ++ |
| 151 | + *peerp = &peer[n]; |
| 152 | + peerp = &peer[n].next; |
| 153 | + n++; |
| 154 | +@@ -162,6 +174,16 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, |
| 155 | + peer[n].down = server[i].down; |
| 156 | + peer[n].server = server[i].name; |
| 157 | + |
| 158 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 159 | ++ if (!server[i].down) { |
| 160 | ++ peer[n].check_index = |
| 161 | ++ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]); |
| 162 | ++ } |
| 163 | ++ else { |
| 164 | ++ peer[n].check_index = (ngx_uint_t) NGX_ERROR; |
| 165 | ++ } |
| 166 | ++#endif |
| 167 | ++ |
| 168 | + *peerp = &peer[n]; |
| 169 | + peerp = &peer[n].next; |
| 170 | + n++; |
| 171 | +@@ -228,6 +250,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf, |
| 172 | + peer[i].max_conns = 0; |
| 173 | + peer[i].max_fails = 1; |
| 174 | + peer[i].fail_timeout = 10; |
| 175 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 176 | ++ peer[i].check_index = (ngx_uint_t) NGX_ERROR; |
| 177 | ++#endif |
| 178 | + *peerp = &peer[i]; |
| 179 | + peerp = &peer[i].next; |
| 180 | + } |
| 181 | +@@ -344,6 +369,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r, |
| 182 | + peer[0].max_conns = 0; |
| 183 | + peer[0].max_fails = 1; |
| 184 | + peer[0].fail_timeout = 10; |
| 185 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 186 | ++ peer[0].check_index = (ngx_uint_t) NGX_ERROR; |
| 187 | ++#endif |
| 188 | + peers->peer = peer; |
| 189 | + |
| 190 | + } else { |
| 191 | +@@ -378,6 +406,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r, |
| 192 | + peer[i].max_conns = 0; |
| 193 | + peer[i].max_fails = 1; |
| 194 | + peer[i].fail_timeout = 10; |
| 195 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 196 | ++ peer[i].check_index = (ngx_uint_t) NGX_ERROR; |
| 197 | ++#endif |
| 198 | + *peerp = &peer[i]; |
| 199 | + peerp = &peer[i].next; |
| 200 | + } |
| 201 | +@@ -443,6 +474,12 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data) |
| 202 | + goto failed; |
| 203 | + } |
| 204 | + |
| 205 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 206 | ++ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 207 | ++ goto failed; |
| 208 | ++ } |
| 209 | ++#endif |
| 210 | ++ |
| 211 | + rrp->current = peer; |
| 212 | + |
| 213 | + } else { |
| 214 | +@@ -537,6 +574,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp) |
| 215 | + continue; |
| 216 | + } |
| 217 | + |
| 218 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 219 | ++ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 220 | ++ continue; |
| 221 | ++ } |
| 222 | ++#endif |
| 223 | ++ |
| 224 | + if (peer->max_fails |
| 225 | + && peer->fails >= peer->max_fails |
| 226 | + && now - peer->checked <= peer->fail_timeout) |
| 227 | +diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h |
| 228 | +index 45f258d..dee91d0 100644 |
| 229 | +--- a/src/http/ngx_http_upstream_round_robin.h |
| 230 | ++++ b/src/http/ngx_http_upstream_round_robin.h |
| 231 | +@@ -38,6 +38,10 @@ struct ngx_http_upstream_rr_peer_s { |
| 232 | + ngx_msec_t slow_start; |
| 233 | + ngx_msec_t start_time; |
| 234 | + |
| 235 | ++#if (NGX_HTTP_UPSTREAM_CHECK) |
| 236 | ++ ngx_uint_t check_index; |
| 237 | ++#endif |
| 238 | ++ |
| 239 | + ngx_uint_t down; |
| 240 | + |
| 241 | + #if (NGX_HTTP_SSL || NGX_COMPAT) |
0 commit comments