Link Here
|
|
|
1 |
--- src/http/ngx_http_upstream_round_robin.c.orig 2016-02-24 14:53:24 UTC |
2 |
+++ src/http/ngx_http_upstream_round_robin.c |
3 |
@@ -9,6 +9,9 @@ |
4 |
#include <ngx_core.h> |
5 |
#include <ngx_http.h> |
6 |
|
7 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
8 |
+#include "ngx_http_upstream_check_module.h" |
9 |
+#endif |
10 |
|
11 |
#define ngx_http_upstream_tries(p) ((p)->number \ |
12 |
+ ((p)->next ? (p)->next->number : 0)) |
13 |
@@ -96,7 +99,14 @@ ngx_http_upstream_init_round_robin(ngx_c |
14 |
peer[n].fail_timeout = server[i].fail_timeout; |
15 |
peer[n].down = server[i].down; |
16 |
peer[n].server = server[i].name; |
17 |
- |
18 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
19 |
+ if (!server[i].down) { |
20 |
+ peer[n].check_index = |
21 |
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]); |
22 |
+ } else { |
23 |
+ peer[n].check_index = (ngx_uint_t) NGX_ERROR; |
24 |
+ } |
25 |
+#endif |
26 |
*peerp = &peer[n]; |
27 |
peerp = &peer[n].next; |
28 |
n++; |
29 |
@@ -159,7 +169,15 @@ ngx_http_upstream_init_round_robin(ngx_c |
30 |
peer[n].fail_timeout = server[i].fail_timeout; |
31 |
peer[n].down = server[i].down; |
32 |
peer[n].server = server[i].name; |
33 |
- |
34 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
35 |
+ if (!server[i].down) { |
36 |
+ peer[n].check_index = |
37 |
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]); |
38 |
+ } |
39 |
+ else { |
40 |
+ peer[n].check_index = (ngx_uint_t) NGX_ERROR; |
41 |
+ } |
42 |
+#endif |
43 |
*peerp = &peer[n]; |
44 |
peerp = &peer[n].next; |
45 |
n++; |
46 |
@@ -225,6 +243,9 @@ ngx_http_upstream_init_round_robin(ngx_c |
47 |
peer[i].current_weight = 0; |
48 |
peer[i].max_fails = 1; |
49 |
peer[i].fail_timeout = 10; |
50 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
51 |
+ peer[i].check_index = (ngx_uint_t) NGX_ERROR; |
52 |
+#endif |
53 |
*peerp = &peer[i]; |
54 |
peerp = &peer[i].next; |
55 |
} |
56 |
@@ -339,6 +360,9 @@ ngx_http_upstream_create_round_robin_pee |
57 |
peer[0].current_weight = 0; |
58 |
peer[0].max_fails = 1; |
59 |
peer[0].fail_timeout = 10; |
60 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
61 |
+ peer[0].check_index = (ngx_uint_t) NGX_ERROR; |
62 |
+#endif |
63 |
peers->peer = peer; |
64 |
|
65 |
} else { |
66 |
@@ -381,6 +405,9 @@ ngx_http_upstream_create_round_robin_pee |
67 |
peer[i].current_weight = 0; |
68 |
peer[i].max_fails = 1; |
69 |
peer[i].fail_timeout = 10; |
70 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
71 |
+ peer[i].check_index = (ngx_uint_t) NGX_ERROR; |
72 |
+#endif |
73 |
*peerp = &peer[i]; |
74 |
peerp = &peer[i].next; |
75 |
} |
76 |
@@ -441,6 +468,12 @@ ngx_http_upstream_get_round_robin_peer(n |
77 |
goto failed; |
78 |
} |
79 |
|
80 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
81 |
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
82 |
+ goto failed; |
83 |
+ } |
84 |
+#endif |
85 |
+ |
86 |
rrp->current = peer; |
87 |
|
88 |
} else { |
89 |
@@ -542,6 +575,12 @@ ngx_http_upstream_get_peer(ngx_http_upst |
90 |
continue; |
91 |
} |
92 |
|
93 |
+#if (NGX_HTTP_UPSTREAM_CHECK) |
94 |
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
95 |
+ continue; |
96 |
+ } |
97 |
+#endif |
98 |
+ |
99 |
if (peer->max_fails |
100 |
&& peer->fails >= peer->max_fails |
101 |
&& now - peer->checked <= peer->fail_timeout) |