Skip to content

Commit b935e1b

Browse files
committed
sync from yaoweibin branch of upstream_check_module
1 parent 6157885 commit b935e1b

4 files changed

+608
-0
lines changed

check_1.12.1+.patch

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

check_1.2.1.patch

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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 100ea34..642b01b 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_HTTP_UPSTREAM_CHECK)
10+
+#include "ngx_http_upstream_check_module.h"
11+
+#endif
12+
+
13+
14+
typedef struct {
15+
/* the round robin data must be first */
16+
@@ -182,6 +186,12 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
17+
18+
if (!peer->down) {
19+
20+
+#if (NGX_HTTP_UPSTREAM_CHECK)
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_upstream_check_peer_down(peer->check_index)) {
25+
+#endif
26+
if (peer->max_fails == 0 || peer->fails < peer->max_fails) {
27+
break;
28+
}
29+
@@ -190,6 +200,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_HTTP_UPSTREAM_CHECK)
34+
+ }
35+
+#endif
36+
}
37+
38+
iphp->rrp.tried[n] |= m;
39+
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
40+
index 214de7b..309725b 100644
41+
--- a/src/http/ngx_http_upstream_round_robin.c
42+
+++ b/src/http/ngx_http_upstream_round_robin.c
43+
@@ -9,6 +9,9 @@
44+
#include <ngx_core.h>
45+
#include <ngx_http.h>
46+
47+
+#if (NGX_HTTP_UPSTREAM_CHECK)
48+
+#include "ngx_http_upstream_check_module.h"
49+
+#endif
50+
51+
static ngx_int_t ngx_http_upstream_cmp_servers(const void *one,
52+
const void *two);
53+
@@ -83,7 +86,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
54+
peers->peer[n].weight = server[i].weight;
55+
peers->peer[n].effective_weight = server[i].weight;
56+
peers->peer[n].current_weight = 0;
57+
- n++;
58+
+
59+
+#if (NGX_HTTP_UPSTREAM_CHECK)
60+
+ if (!server[i].down) {
61+
+ peers->peer[n].check_index =
62+
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
63+
+ }
64+
+ else {
65+
+ peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
66+
+ }
67+
+#endif
68+
+ n++;
69+
}
70+
}
71+
72+
@@ -137,6 +150,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
73+
backup->peer[n].max_fails = server[i].max_fails;
74+
backup->peer[n].fail_timeout = server[i].fail_timeout;
75+
backup->peer[n].down = server[i].down;
76+
+
77+
+#if (NGX_HTTP_UPSTREAM_CHECK)
78+
+ if (!server[i].down) {
79+
+ backup->peer[n].check_index =
80+
+ ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
81+
+ }
82+
+ else {
83+
+ backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
84+
+ }
85+
+#endif
86+
+
87+
n++;
88+
}
89+
}
90+
@@ -196,6 +220,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
91+
peers->peer[i].current_weight = 0;
92+
peers->peer[i].max_fails = 1;
93+
peers->peer[i].fail_timeout = 10;
94+
+#if (NGX_HTTP_UPSTREAM_CHECK)
95+
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
96+
+#endif
97+
}
98+
99+
us->peer.data = peers;
100+
@@ -313,6 +340,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
101+
peers->peer[0].current_weight = 0;
102+
peers->peer[0].max_fails = 1;
103+
peers->peer[0].fail_timeout = 10;
104+
+#if (NGX_HTTP_UPSTREAM_CHECK)
105+
+ peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR;
106+
+#endif
107+
108+
} else {
109+
110+
@@ -346,6 +376,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
111+
peers->peer[i].current_weight = 0;
112+
peers->peer[i].max_fails = 1;
113+
peers->peer[i].fail_timeout = 10;
114+
+#if (NGX_HTTP_UPSTREAM_CHECK)
115+
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
116+
+#endif
117+
}
118+
}
119+
120+
@@ -419,7 +452,11 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
121+
122+
if (rrp->peers->single) {
123+
peer = &rrp->peers->peer[0];
124+
-
125+
+#if (NGX_HTTP_UPSTREAM_CHECK)
126+
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
127+
+ return NGX_BUSY;
128+
+ }
129+
+#endif
130+
} else {
131+
132+
/* there are several peers */
133+
@@ -517,6 +554,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
134+
continue;
135+
}
136+
137+
+#if (NGX_HTTP_UPSTREAM_CHECK)
138+
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
139+
+ continue;
140+
+ }
141+
+#endif
142+
+
143+
if (peer->max_fails
144+
&& peer->fails >= peer->max_fails
145+
&& now - peer->checked <= peer->fail_timeout)
146+
diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h
147+
index 4de3cae..164867b 100644
148+
--- a/src/http/ngx_http_upstream_round_robin.h
149+
+++ b/src/http/ngx_http_upstream_round_robin.h
150+
@@ -30,6 +30,10 @@ typedef struct {
151+
ngx_uint_t max_fails;
152+
time_t fail_timeout;
153+
154+
+#if (NGX_HTTP_UPSTREAM_CHECK)
155+
+ ngx_uint_t check_index;
156+
+#endif
157+
+
158+
ngx_uint_t down; /* unsigned down:1; */
159+
160+
#if (NGX_HTTP_SSL)

0 commit comments

Comments
 (0)