Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge form yaoweibing #120

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 103 additions & 22 deletions nginx.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index ed86a38..19708d0 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -4146,6 +4146,17 @@ ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
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;
Expand All @@ -20,13 +19,13 @@ index ed86a38..19708d0 100644

if (u->naddrs == 1) {
uscf->servers = ngx_array_create(cf->pool, 1,
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index 97ec71b..ff2772a 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -111,6 +111,24 @@ struct ngx_http_upstream_srv_conf_s {
ngx_uint_t retries;
#endif
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
Expand All @@ -49,8 +48,10 @@ index 97ec71b..ff2772a 100644
ngx_uint_t flags;
ngx_str_t host;
u_char *file_name;
--- a/src/http/ngx_http_upstream_round_robin.c Mon Mar 8 20:55:32 2010
+++ b/src/http/ngx_http_upstream_round_robin.c Mon Mar 8 21:03:17 2010
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 @@
*/

Expand All @@ -60,32 +61,112 @@ index 97ec71b..ff2772a 100644
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
@@ -55,6 +57,7 @@
@@ -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;

@@ -91,6 +94,14 @@
if (server[i].backup) {
@@ -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;
--- a/src/http/ngx_http_upstream_round_robin.h Mon Mar 8 21:00:58 2010
+++ b/src/http/ngx_http_upstream_round_robin.h Mon Mar 8 21:00:06 2010
@@ -28,6 +28,7 @@
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;
Expand Down