Permalink
Switch branches/tags
Nothing to show
Find file
dc158e4 Nov 30, 2011
@PiotrSikora @mschenck @cep21
177 lines (150 sloc) 6.76 KB
diff -ru nginx-1.0.10/src/http/ngx_http_upstream.c nginx-1.0.10-patched/src/http/ngx_http_upstream.c
--- nginx-1.0.10/src/http/ngx_http_upstream.c 2011-11-01 10:18:10.000000000 -0400
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream.c 2011-11-30 20:34:10.000000000 -0500
@@ -4293,6 +4293,17 @@
uscf->line = cf->conf_file->line;
uscf->port = u->port;
uscf->default_port = u->default_port;
+#if (NGX_HTTP_HEALTHCHECK)
+ uscf->healthcheck_enabled = 0;
+ uscf->health_delay = 10000;
+ uscf->health_timeout = 2000;
+ uscf->health_failcount = 2;
+ uscf->health_buffersize = 1000;
+ uscf->health_send.data = (u_char*)"";
+ uscf->health_send.len = 0;
+ uscf->health_expected.len = NGX_CONF_UNSET_SIZE;
+ uscf->health_expected.data = NGX_CONF_UNSET_PTR;
+#endif
if (u->naddrs == 1) {
uscf->servers = ngx_array_create(cf->pool, 1,
Only in nginx-1.0.10-patched/src/http: ngx_http_upstream.c.orig
diff -ru nginx-1.0.10/src/http/ngx_http_upstream.h nginx-1.0.10-patched/src/http/ngx_http_upstream.h
--- nginx-1.0.10/src/http/ngx_http_upstream.h 2011-11-01 10:18:10.000000000 -0400
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream.h 2011-11-30 20:34:10.000000000 -0500
@@ -109,6 +109,24 @@
ngx_array_t *servers; /* ngx_http_upstream_server_t */
+#if (NGX_HTTP_HEALTHCHECK)
+ // If true, healthchecking is enabled for this upstream
+ unsigned healthcheck_enabled:1;
+ // Delay between healthchecks (in sec)
+ time_t health_delay;
+ // Total time a healthcheck is allowed to execute
+ ngx_msec_t health_timeout;
+ // Number of good/bad results indicate the node is up/down
+ ngx_int_t health_failcount;
+ // Size of the body+headers buffer
+ ngx_int_t health_buffersize;
+ // What is sent to initiate the healthcheck
+ ngx_str_t health_send;
+ // Expected from healthcheck, excluding headers
+ ngx_str_t health_expected;
+#endif
+
+
ngx_uint_t flags;
ngx_str_t host;
u_char *file_name;
Only in nginx-1.0.10-patched/src/http: ngx_http_upstream.h.orig
diff -ru nginx-1.0.10/src/http/ngx_http_upstream_round_robin.c nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.c
--- nginx-1.0.10/src/http/ngx_http_upstream_round_robin.c 2011-09-30 10:30:01.000000000 -0400
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.c 2011-11-30 20:34:10.000000000 -0500
@@ -4,6 +4,8 @@
*/
+/* on top, so it won't collide with ngx_supervisord's patch */
+#include <ngx_http_healthcheck_module.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
@@ -12,7 +14,8 @@
static ngx_int_t ngx_http_upstream_cmp_servers(const void *one,
const void *two);
static ngx_uint_t
-ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers);
+ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers,
+ ngx_log_t * log);
#if (NGX_HTTP_SSL)
@@ -32,6 +35,7 @@
ngx_uint_t i, j, n;
ngx_http_upstream_server_t *server;
ngx_http_upstream_rr_peers_t *peers, *backup;
+ ngx_int_t health_index;
us->peer.init = ngx_http_upstream_init_round_robin_peer;
@@ -66,6 +70,14 @@
continue;
}
+ /* on top, so it won't collide with ngx_supervisord's patch */
+ health_index = ngx_http_healthcheck_add_peer(us,
+ &server[i].addrs[j], cf->pool);
+ if (health_index == NGX_ERROR) {
+ return NGX_ERROR;
+ }
+ peers->peer[n].health_index = health_index;
+
peers->peer[n].sockaddr = server[i].addrs[j].sockaddr;
peers->peer[n].socklen = server[i].addrs[j].socklen;
peers->peer[n].name = server[i].addrs[j].name;
@@ -377,6 +389,7 @@
ngx_connection_t *c;
ngx_http_upstream_rr_peer_t *peer;
ngx_http_upstream_rr_peers_t *peers;
+ ngx_int_t healthy;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"get rr peer, try: %ui", pc->tries);
@@ -422,7 +435,7 @@
i = pc->tries;
for ( ;; ) {
- rrp->current = ngx_http_upstream_get_peer(rrp->peers);
+ rrp->current = ngx_http_upstream_get_peer(rrp->peers, pc->log);
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"get rr peer, current: %ui %i",
@@ -483,7 +496,11 @@
peer = &rrp->peers->peer[rrp->current];
- if (!peer->down) {
+ healthy = !ngx_http_healthcheck_is_down(
+ peer->health_index,
+ pc->log);
+
+ if ((!peer->down) && healthy) {
if (peer->max_fails == 0
|| peer->fails < peer->max_fails)
@@ -588,12 +605,14 @@
static ngx_uint_t
-ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers)
+ngx_http_upstream_get_peer(ngx_http_upstream_rr_peers_t *peers, ngx_log_t *log)
{
ngx_uint_t i, n, reset = 0;
ngx_http_upstream_rr_peer_t *peer;
+ ngx_uint_t health_check_rounds;
peer = &peers->peer[0];
+ health_check_rounds = 2;
for ( ;; ) {
@@ -613,6 +632,11 @@
continue;
}
+ if (health_check_rounds && ngx_http_healthcheck_is_down(
+ peer[i].health_index,
+ log))
+ continue;
+
if (peer[n].current_weight * 1000 / peer[i].current_weight
> peer[n].weight * 1000 / peer[i].weight)
{
@@ -633,6 +657,9 @@
return 0;
}
+ if (health_check_rounds)
+ --health_check_rounds;
+
for (i = 0; i < peers->number; i++) {
peer[i].current_weight = peer[i].weight;
}
Only in nginx-1.0.10-patched/src/http: ngx_http_upstream_round_robin.c.orig
diff -ru nginx-1.0.10/src/http/ngx_http_upstream_round_robin.h nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.h
--- nginx-1.0.10/src/http/ngx_http_upstream_round_robin.h 2009-11-02 07:41:56.000000000 -0500
+++ nginx-1.0.10-patched/src/http/ngx_http_upstream_round_robin.h 2011-11-30 20:34:10.000000000 -0500
@@ -26,6 +26,7 @@
ngx_uint_t max_fails;
time_t fail_timeout;
+ ngx_int_t health_index;
ngx_uint_t down; /* unsigned down:1; */