Skip to content

Commit c3d6e7a

Browse files
committed
Merge pull request yaoweibin#34 from jbergstroem/nginx-1.7.2
Added the patch for nginx-1.7.2+
2 parents d40b9f9 + 5256efe commit c3d6e7a

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

check_1.7.2+.patch

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
commit 21116e1c0bba730ca59327ffba9320bc63f11462
2+
Author: Johan Bergström <[email protected]>
3+
Date: Thu Jun 19 10:17:22 2014 +1000
4+
5+
Add support for upstream_check to nginx 1.7.2
6+
7+
diff --git src/http/modules/ngx_http_upstream_ip_hash_module.c src/http/modules/ngx_http_upstream_ip_hash_module.c
8+
index 148d73a..be9e03d 100644
9+
--- src/http/modules/ngx_http_upstream_ip_hash_module.c
10+
+++ src/http/modules/ngx_http_upstream_ip_hash_module.c
11+
@@ -9,6 +9,9 @@
12+
#include <ngx_core.h>
13+
#include <ngx_http.h>
14+
15+
+#if (NGX_UPSTREAM_CHECK_MODULE)
16+
+#include "ngx_http_upstream_check_handler.h"
17+
+#endif
18+
19+
typedef struct {
20+
/* the round robin data must be first */
21+
@@ -212,6 +215,15 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
22+
goto next_try;
23+
}
24+
25+
+#if (NGX_UPSTREAM_CHECK_MODULE)
26+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
27+
+ "get ip_hash peer, check_index: %ui",
28+
+ peer->check_index);
29+
+ if (ngx_http_check_peer_down(peer->check_index)) {
30+
+ goto next_try;
31+
+ }
32+
+#endif
33+
+
34+
if (peer->max_fails
35+
&& peer->fails >= peer->max_fails
36+
&& now - peer->checked <= peer->fail_timeout)
37+
diff --git src/http/modules/ngx_http_upstream_least_conn_module.c src/http/modules/ngx_http_upstream_least_conn_module.c
38+
index dbef95d..14e9e40 100644
39+
--- src/http/modules/ngx_http_upstream_least_conn_module.c
40+
+++ src/http/modules/ngx_http_upstream_least_conn_module.c
41+
@@ -9,6 +9,9 @@
42+
#include <ngx_core.h>
43+
#include <ngx_http.h>
44+
45+
+#if (NGX_UPSTREAM_CHECK_MODULE)
46+
+#include "ngx_http_upstream_check_handler.h"
47+
+#endif
48+
49+
typedef struct {
50+
ngx_uint_t *conns;
51+
@@ -203,6 +206,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
52+
continue;
53+
}
54+
55+
+#if (NGX_UPSTREAM_CHECK_MODULE)
56+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
57+
+ "get least_conn peer, check_index: %ui",
58+
+ peer->check_index);
59+
+
60+
+ if (ngx_http_check_peer_down(peer->check_index)) {
61+
+ continue;
62+
+ }
63+
+#endif
64+
+
65+
if (peer->max_fails
66+
&& peer->fails >= peer->max_fails
67+
&& now - peer->checked <= peer->fail_timeout)
68+
@@ -256,6 +269,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
69+
continue;
70+
}
71+
72+
+#if (NGX_UPSTREAM_CHECK_MODULE)
73+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
74+
+ "get least_conn peer, check_index: %ui",
75+
+ peer->check_index);
76+
+
77+
+ if (ngx_http_check_peer_down(peer->check_index)) {
78+
+ continue;
79+
+ }
80+
+#endif
81+
+
82+
if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) {
83+
continue;
84+
}
85+
diff --git src/http/ngx_http_upstream_round_robin.c src/http/ngx_http_upstream_round_robin.c
86+
index 37c835c..43ccdcf 100644
87+
--- src/http/ngx_http_upstream_round_robin.c
88+
+++ src/http/ngx_http_upstream_round_robin.c
89+
@@ -9,6 +9,9 @@
90+
#include <ngx_core.h>
91+
#include <ngx_http.h>
92+
93+
+#if (NGX_UPSTREAM_CHECK_MODULE)
94+
+#include "ngx_http_upstream_check_handler.h"
95+
+#endif
96+
97+
static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer(
98+
ngx_http_upstream_rr_peer_data_t *rrp);
99+
@@ -88,6 +91,14 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
100+
peer[n].fail_timeout = server[i].fail_timeout;
101+
peer[n].down = server[i].down;
102+
peer[n].server = server[i].name;
103+
+#if (NGX_UPSTREAM_CHECK_MODULE)
104+
+ if (!server[i].down) {
105+
+ peers->peer[n].check_index =
106+
+ ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
107+
+ } else {
108+
+ peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
109+
+ }
110+
+#endif
111+
n++;
112+
}
113+
}
114+
@@ -144,6 +155,15 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
115+
peer[n].fail_timeout = server[i].fail_timeout;
116+
peer[n].down = server[i].down;
117+
peer[n].server = server[i].name;
118+
+#if (NGX_UPSTREAM_CHECK_MODULE)
119+
+ if (!server[i].down) {
120+
+ backup->peer[n].check_index =
121+
+ ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
122+
+ }
123+
+ else {
124+
+ backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
125+
+ }
126+
+#endif
127+
n++;
128+
}
129+
}
130+
@@ -203,6 +223,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
131+
peer[i].current_weight = 0;
132+
peer[i].max_fails = 1;
133+
peer[i].fail_timeout = 10;
134+
+#if (NGX_UPSTREAM_CHECK_MODULE)
135+
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
136+
+#endif
137+
}
138+
139+
us->peer.data = peers;
140+
@@ -312,7 +335,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
141+
peer[0].current_weight = 0;
142+
peer[0].max_fails = 1;
143+
peer[0].fail_timeout = 10;
144+
-
145+
+#if (NGX_UPSTREAM_CHECK_MODULE)
146+
+ peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR;
147+
+#endif
148+
} else {
149+
150+
for (i = 0; i < ur->naddrs; i++) {
151+
@@ -352,6 +377,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
152+
peer[i].current_weight = 0;
153+
peer[i].max_fails = 1;
154+
peer[i].fail_timeout = 10;
155+
+#if (NGX_UPSTREAM_CHECK_MODULE)
156+
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
157+
+#endif
158+
}
159+
}
160+
161+
@@ -411,6 +439,12 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
162+
goto failed;
163+
}
164+
165+
+#if (NGX_UPSTREAM_CHECK_MODULE)
166+
+ if (ngx_http_check_peer_down(peer->check_index)) {
167+
+ goto failed;
168+
+ }
169+
+#endif
170+
+
171+
} else {
172+
173+
/* there are several peers */
174+
@@ -508,6 +542,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
175+
continue;
176+
}
177+
178+
+#if (NGX_UPSTREAM_CHECK_MODULE)
179+
+ if (ngx_http_check_peer_down(peer->check_index)) {
180+
+ continue;
181+
+ }
182+
+#endif
183+
+
184+
if (peer->max_fails
185+
&& peer->fails >= peer->max_fails
186+
&& now - peer->checked <= peer->fail_timeout)
187+
diff --git src/http/ngx_http_upstream_round_robin.h src/http/ngx_http_upstream_round_robin.h
188+
index 9db82a6..2fedd46 100644
189+
--- src/http/ngx_http_upstream_round_robin.h
190+
+++ src/http/ngx_http_upstream_round_robin.h
191+
@@ -31,6 +31,10 @@ typedef struct {
192+
ngx_uint_t max_fails;
193+
time_t fail_timeout;
194+
195+
+#if (NGX_UPSTREAM_CHECK_MODULE)
196+
+ ngx_uint_t check_index;
197+
+#endif
198+
+
199+
ngx_uint_t down; /* unsigned down:1; */
200+
201+
#if (NGX_HTTP_SSL)

0 commit comments

Comments
 (0)