Skip to content

Commit 327249c

Browse files
committed
added the patch for nginx-1.2.6+ and nginx-1.3.9+
1 parent fd8383b commit 327249c

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed

README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ Note
152152
If you use nginx-1.2.2+ or nginx-1.3.1+, It added the upstream
153153
least_conn module. You should use the patch named 'check_1.2.2+.patch'.
154154

155+
If you use nginx-1.2.6+ or nginx-1.3.9+, It adjusted the round robin
156+
module. You should use the patch named 'check_1.2.6+.patch'.
157+
155158
The patch just adds the support for the official Round-Robin, Ip_hash
156159
and least_conn upstream module. But it's easy to expand my module to
157160
other upstream modules. See the patch for detail.

check_1.2.6+.patch

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c
2+
index 89ccc2b..a552044 100644
3+
--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c
4+
+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c
5+
@@ -9,6 +9,10 @@
6+
#include <ngx_core.h>
7+
#include <ngx_http.h>
8+
9+
+#if (NGX_UPSTREAM_CHECK_MODULE)
10+
+#include "ngx_http_upstream_check_handler.h"
11+
+#endif
12+
+
13+
14+
typedef struct {
15+
/* the round robin data must be first */
16+
@@ -208,6 +212,12 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
17+
18+
if (!peer->down) {
19+
20+
+#if (NGX_UPSTREAM_CHECK_MODULE)
21+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
22+
+ "get ip_hash peer, check_index: %ui",
23+
+ peer->check_index);
24+
+ if (!ngx_http_check_peer_down(peer->check_index)) {
25+
+#endif
26+
if (peer->max_fails == 0 || peer->fails < peer->max_fails) {
27+
break;
28+
}
29+
@@ -216,6 +226,9 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
30+
peer->checked = now;
31+
break;
32+
}
33+
+#if (NGX_UPSTREAM_CHECK_MODULE)
34+
+ }
35+
+#endif
36+
}
37+
38+
iphp->rrp.tried[n] |= m;
39+
diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c
40+
index 21156ae..c57393d 100644
41+
--- a/src/http/modules/ngx_http_upstream_least_conn_module.c
42+
+++ b/src/http/modules/ngx_http_upstream_least_conn_module.c
43+
@@ -9,6 +9,10 @@
44+
#include <ngx_core.h>
45+
#include <ngx_http.h>
46+
47+
+#if (NGX_UPSTREAM_CHECK_MODULE)
48+
+#include "ngx_http_upstream_check_handler.h"
49+
+#endif
50+
+
51+
52+
typedef struct {
53+
ngx_uint_t *conns;
54+
@@ -203,6 +207,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
55+
continue;
56+
}
57+
58+
+#if (NGX_UPSTREAM_CHECK_MODULE)
59+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
60+
+ "get least_conn peer, check_index: %ui",
61+
+ peer->check_index);
62+
+
63+
+ if (ngx_http_check_peer_down(peer->check_index)) {
64+
+ continue;
65+
+ }
66+
+#endif
67+
+
68+
if (peer->max_fails
69+
&& peer->fails >= peer->max_fails
70+
&& now - peer->checked <= peer->fail_timeout)
71+
@@ -256,6 +270,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
72+
continue;
73+
}
74+
75+
+#if (NGX_UPSTREAM_CHECK_MODULE)
76+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
77+
+ "get least_conn peer, check_index: %ui",
78+
+ peer->check_index);
79+
+
80+
+ if (ngx_http_check_peer_down(peer->check_index)) {
81+
+ continue;
82+
+ }
83+
+#endif
84+
+
85+
if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) {
86+
continue;
87+
}
88+
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
89+
index 4b78cff..f077b46 100644
90+
--- a/src/http/ngx_http_upstream_round_robin.c
91+
+++ b/src/http/ngx_http_upstream_round_robin.c
92+
@@ -9,6 +9,9 @@
93+
#include <ngx_core.h>
94+
#include <ngx_http.h>
95+
96+
+#if (NGX_UPSTREAM_CHECK_MODULE)
97+
+#include "ngx_http_upstream_check_handler.h"
98+
+#endif
99+
100+
static ngx_int_t ngx_http_upstream_cmp_servers(const void *one,
101+
const void *two);
102+
@@ -87,7 +90,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
103+
peers->peer[n].weight = server[i].weight;
104+
peers->peer[n].effective_weight = server[i].weight;
105+
peers->peer[n].current_weight = 0;
106+
- n++;
107+
+
108+
+#if (NGX_UPSTREAM_CHECK_MODULE)
109+
+ if (!server[i].down) {
110+
+ peers->peer[n].check_index =
111+
+ ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
112+
+ }
113+
+ else {
114+
+ peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
115+
+ }
116+
+#endif
117+
+ n++;
118+
}
119+
}
120+
121+
@@ -145,6 +158,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
122+
backup->peer[n].max_fails = server[i].max_fails;
123+
backup->peer[n].fail_timeout = server[i].fail_timeout;
124+
backup->peer[n].down = server[i].down;
125+
+
126+
+#if (NGX_UPSTREAM_CHECK_MODULE)
127+
+ if (!server[i].down) {
128+
+ backup->peer[n].check_index =
129+
+ ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
130+
+ }
131+
+ else {
132+
+ backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
133+
+ }
134+
+#endif
135+
+
136+
n++;
137+
}
138+
}
139+
@@ -206,6 +230,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
140+
peers->peer[i].current_weight = 0;
141+
peers->peer[i].max_fails = 1;
142+
peers->peer[i].fail_timeout = 10;
143+
+#if (NGX_UPSTREAM_CHECK_MODULE)
144+
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
145+
+#endif
146+
}
147+
148+
us->peer.data = peers;
149+
@@ -323,6 +350,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
150+
peers->peer[0].current_weight = 0;
151+
peers->peer[0].max_fails = 1;
152+
peers->peer[0].fail_timeout = 10;
153+
+#if (NGX_UPSTREAM_CHECK_MODULE)
154+
+ peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR;
155+
+#endif
156+
157+
} else {
158+
159+
@@ -356,6 +386,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
160+
peers->peer[i].current_weight = 0;
161+
peers->peer[i].max_fails = 1;
162+
peers->peer[i].fail_timeout = 10;
163+
+#if (NGX_UPSTREAM_CHECK_MODULE)
164+
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
165+
+#endif
166+
}
167+
}
168+
169+
@@ -434,6 +467,12 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
170+
goto failed;
171+
}
172+
173+
+#if (NGX_UPSTREAM_CHECK_MODULE)
174+
+ if (ngx_http_check_peer_down(peer->check_index)) {
175+
+ goto failed;
176+
+ }
177+
+#endif
178+
+
179+
} else {
180+
181+
/* there are several peers */
182+
@@ -531,6 +570,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
183+
continue;
184+
}
185+
186+
+#if (NGX_UPSTREAM_CHECK_MODULE)
187+
+ if (ngx_http_check_peer_down(peer->check_index)) {
188+
+ continue;
189+
+ }
190+
+#endif
191+
+
192+
if (peer->max_fails
193+
&& peer->fails >= peer->max_fails
194+
&& now - peer->checked <= peer->fail_timeout)
195+
diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h
196+
index 3f8cbf8..1613168 100644
197+
--- a/src/http/ngx_http_upstream_round_robin.h
198+
+++ b/src/http/ngx_http_upstream_round_robin.h
199+
@@ -30,6 +30,10 @@ typedef struct {
200+
ngx_uint_t max_fails;
201+
time_t fail_timeout;
202+
203+
+#if (NGX_UPSTREAM_CHECK_MODULE)
204+
+ ngx_uint_t check_index;
205+
+#endif
206+
+
207+
ngx_uint_t down; /* unsigned down:1; */
208+
209+
#if (NGX_HTTP_SSL)

doc/README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ Note
152152
If you use nginx-1.2.2+ or nginx-1.3.1+, It added the upstream
153153
least_conn module. You should use the patch named 'check_1.2.2+.patch'.
154154

155+
If you use nginx-1.2.6+ or nginx-1.3.9+, It adjusted the round robin
156+
module. You should use the patch named 'check_1.2.6+.patch'.
157+
155158
The patch just adds the support for the official Round-Robin, Ip_hash
156159
and least_conn upstream module. But it's easy to expand my module to
157160
other upstream modules. See the patch for detail.

doc/README.wiki

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ If you use nginx-1.2.1 or nginx-1.3.0, the nginx upstream round robin module cha
136136

137137
If you use nginx-1.2.2+ or nginx-1.3.1+, It added the upstream least_conn module. You should use the patch named 'check_1.2.2+.patch'.
138138

139+
If you use nginx-1.2.6+ or nginx-1.3.9+, It adjusted the round robin module. You should use the patch named 'check_1.2.6+.patch'.
140+
139141
The patch just adds the support for the official Round-Robin, Ip_hash and least_conn upstream module. But it's easy to expand my module to other upstream modules. See the patch for detail.
140142

141143
If you want to add the support for upstream fair module, you can do it like this:

0 commit comments

Comments
 (0)