1 Star 0 Fork 0

hhao/nginx_upstream_check_module

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
check_1.7.5+.patch 8.15 KB
一键复制 编辑 原始数据 按行查看 历史
saravsars 提交于 2015-03-05 01:53 . Added support for upstream hash module
diff --git a/src/http/modules/ngx_http_upstream_hash_module.c b/src/http/modules/ngx_http_upstream_hash_module.c
index 777e180..b6b7830 100644
--- a/src/http/modules/ngx_http_upstream_hash_module.c
+++ b/src/http/modules/ngx_http_upstream_hash_module.c
@@ -9,6 +9,9 @@
#include <ngx_core.h>
#include <ngx_http.h>
+#if (NGX_HTTP_UPSTREAM_CHECK)
+#include "ngx_http_upstream_check_module.h"
+#endif
typedef struct {
uint32_t hash;
@@ -240,6 +243,15 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
goto next;
}
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
+ "get hash peer, check_index: %ui",
+ peer->check_index);
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
+ goto next;
+ }
+#endif
+
if (peer->max_fails
&& peer->fails >= peer->max_fails
&& now - peer->checked <= peer->fail_timeout)
@@ -506,6 +518,15 @@ ngx_http_upstream_get_chash_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 consistent_hash peer, check_index: %ui",
+ peer->check_index);
+ if (ngx_http_upstream_check_peer_down(peer->check_index)) {
+ continue;
+ }
+#endif
+
if (peer->server.len != server->len
|| ngx_strncmp(peer->server.data, server->data, server->len)
!= 0)
diff --git a/src/http/modules/ngx_http_upstream_ip_hash_module.c b/src/http/modules/ngx_http_upstream_ip_hash_module.c
index 148d73a..913e395 100644
--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c
+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c
@@ -9,6 +9,9 @@
#include <ngx_core.h>
#include <ngx_http.h>
+#if (NGX_HTTP_UPSTREAM_CHECK)
+#include "ngx_http_upstream_check_module.h"
+#endif
typedef struct {
/* the round robin data must be first */
@@ -212,6 +215,15 @@ 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)) {
+ goto next_try;
+ }
+#endif
+
if (peer->max_fails
&& peer->fails >= peer->max_fails
&& now - peer->checked <= peer->fail_timeout)
diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c
index 623bc9b..a223839 100644
--- a/src/http/modules/ngx_http_upstream_least_conn_module.c
+++ b/src/http/modules/ngx_http_upstream_least_conn_module.c
@@ -9,6 +9,9 @@
#include <ngx_core.h>
#include <ngx_http.h>
+#if (NGX_HTTP_UPSTREAM_CHECK)
+#include "ngx_http_upstream_check_module.h"
+#endif
typedef struct {
ngx_uint_t *conns;
@@ -203,6 +206,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 +269,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 a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
index 2d0649b..b9789eb 100644
--- a/src/http/ngx_http_upstream_round_robin.c
+++ b/src/http/ngx_http_upstream_round_robin.c
@@ -9,6 +9,9 @@
#include <ngx_core.h>
#include <ngx_http.h>
+#if (NGX_HTTP_UPSTREAM_CHECK)
+#include "ngx_http_upstream_check_module.h"
+#endif
#define ngx_http_upstream_tries(p) ((p)->number \
+ ((p)->next ? (p)->next->number : 0))
@@ -92,6 +95,14 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
peer[n].fail_timeout = server[i].fail_timeout;
peer[n].down = server[i].down;
peer[n].server = server[i].name;
+#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++;
}
}
@@ -148,6 +159,15 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
peer[n].fail_timeout = server[i].fail_timeout;
peer[n].down = server[i].down;
peer[n].server = server[i].name;
+#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++;
}
}
@@ -207,6 +227,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
peer[i].current_weight = 0;
peer[i].max_fails = 1;
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;
@@ -316,7 +339,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
peer[0].current_weight = 0;
peer[0].max_fails = 1;
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++) {
@@ -356,6 +381,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
peer[i].current_weight = 0;
peer[i].max_fails = 1;
peer[i].fail_timeout = 10;
+#if (NGX_HTTP_UPSTREAM_CHECK)
+ peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
+#endif
}
}
@@ -415,6 +443,12 @@ 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 */
@@ -507,6 +541,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 a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h
index 9db82a6..6e19a65 100644
--- a/src/http/ngx_http_upstream_round_robin.h
+++ b/src/http/ngx_http_upstream_round_robin.h
@@ -31,6 +31,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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hhao8580/nginx_upstream_check_module.git
git@gitee.com:hhao8580/nginx_upstream_check_module.git
hhao8580
nginx_upstream_check_module
nginx_upstream_check_module
master

搜索帮助