-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnginx-1.6.2.patch
More file actions
212 lines (195 loc) · 7.2 KB
/
Copy pathnginx-1.6.2.patch
File metadata and controls
212 lines (195 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
diff --git i/src/http/modules/ngx_http_upstream_ip_hash_module.c w/src/http/modules/ngx_http_upstream_ip_hash_module.c
old mode 100644
new mode 100755
index 041883f..4491148
--- i/src/http/modules/ngx_http_upstream_ip_hash_module.c
+++ w/src/http/modules/ngx_http_upstream_ip_hash_module.c
@@ -212,6 +212,14 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
goto next_try;
}
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
+ "get ip_hash peer, check_index: %ui",
+ peer->check_index);
+
+ if (!ngx_http_upstream_check_peer_down(peer->check_index)) {
+#endif
+
if (peer->max_fails
&& peer->fails >= peer->max_fails
&& now - peer->checked <= peer->fail_timeout)
@@ -221,6 +229,10 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
break;
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ }
+#endif
+
next_try:
iphp->rrp.tried[n] |= m;
diff --git i/src/http/modules/ngx_http_upstream_least_conn_module.c w/src/http/modules/ngx_http_upstream_least_conn_module.c
old mode 100644
new mode 100755
index dbef95d..eb33282
--- i/src/http/modules/ngx_http_upstream_least_conn_module.c
+++ w/src/http/modules/ngx_http_upstream_least_conn_module.c
@@ -203,6 +203,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
continue;
}
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
+ "get least_conn peer, check_index: %ui",
+ peer->check_index);
+
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
+ continue;
+ }
+#endif
+
if (peer->max_fails
&& peer->fails >= peer->max_fails
&& now - peer->checked <= peer->fail_timeout)
@@ -256,6 +266,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
continue;
}
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
+ "get least_conn peer, check_index: %ui",
+ peer->check_index);
+
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
+ continue;
+ }
+#endif
+
if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) {
continue;
}
diff --git i/src/http/ngx_http_upstream.h w/src/http/ngx_http_upstream.h
old mode 100644
new mode 100755
index 9f96c50..159b343
--- i/src/http/ngx_http_upstream.h
+++ w/src/http/ngx_http_upstream.h
@@ -374,6 +374,17 @@ ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
#define ngx_http_conf_upstream_srv_conf(uscf, module) \
uscf->srv_conf[module.ctx_index]
+#if (NGX_HTTP_UPSTREAM_CHECK)
+
+ngx_uint_t ngx_http_upstream_check_add_peer(ngx_conf_t *cf,
+ ngx_http_upstream_srv_conf_t *us, ngx_addr_t *peer);
+
+ngx_uint_t ngx_http_upstream_check_peer_down(ngx_uint_t index);
+
+void ngx_http_upstream_check_get_peer(ngx_uint_t index);
+void ngx_http_upstream_check_free_peer(ngx_uint_t index);
+
+#endif
extern ngx_module_t ngx_http_upstream_module;
extern ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[];
diff --git i/src/http/ngx_http_upstream_round_robin.c w/src/http/ngx_http_upstream_round_robin.c
old mode 100644
new mode 100755
index 85ff558..6d49f2d
--- i/src/http/ngx_http_upstream_round_robin.c
+++ w/src/http/ngx_http_upstream_round_robin.c
@@ -85,6 +85,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
peers->peer[n].max_fails = server[i].max_fails;
peers->peer[n].fail_timeout = server[i].fail_timeout;
peers->peer[n].down = server[i].down;
+
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ if (!server[i].down) {
+ peers->peer[n].check_index =
+ ngx_http_upstream_check_add_peer(cf, us,
+ &server[i].addrs[j]);
+ } else {
+ peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
+ }
+#endif
+
n++;
}
}
@@ -139,6 +150,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
backup->peer[n].max_fails = server[i].max_fails;
backup->peer[n].fail_timeout = server[i].fail_timeout;
backup->peer[n].down = server[i].down;
+
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ if (!server[i].down) {
+ backup->peer[n].check_index =
+ ngx_http_upstream_check_add_peer(cf, us,
+ &server[i].addrs[j]);
+ } else {
+ backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
+ }
+#endif
+
n++;
}
}
@@ -196,6 +218,10 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
peers->peer[i].current_weight = 0;
peers->peer[i].max_fails = 1;
peers->peer[i].fail_timeout = 10;
+
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
+#endif
}
us->peer.data = peers;
@@ -303,6 +329,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
peers->peer[0].max_fails = 1;
peers->peer[0].fail_timeout = 10;
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR;
+#endif
} else {
for (i = 0; i < ur->naddrs; i++) {
@@ -342,6 +371,10 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
peers->peer[i].current_weight = 0;
peers->peer[i].max_fails = 1;
peers->peer[i].fail_timeout = 10;
+
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
+#endif
}
}
@@ -399,6 +432,11 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
goto failed;
}
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
+ goto failed;
+ }
+#endif
} else {
/* there are several peers */
@@ -498,6 +536,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
continue;
}
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
+ continue;
+ }
+#endif
+
if (peer->max_fails
&& peer->fails >= peer->max_fails
&& now - peer->checked <= peer->fail_timeout)
diff --git i/src/http/ngx_http_upstream_round_robin.h w/src/http/ngx_http_upstream_round_robin.h
old mode 100644
new mode 100755
index ea90ab9..a6fb33f
--- i/src/http/ngx_http_upstream_round_robin.h
+++ w/src/http/ngx_http_upstream_round_robin.h
@@ -30,6 +30,10 @@ typedef struct {
ngx_uint_t max_fails;
time_t fail_timeout;
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ ngx_uint_t check_index;
+#endif
+
ngx_uint_t down; /* unsigned down:1; */
#if (NGX_HTTP_SSL)