You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
6.9 KiB

  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 89ccc2b..a552044 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. +#if (NGX_UPSTREAM_CHECK_MODULE)
  9. +#include "ngx_http_upstream_check_handler.h"
  10. +#endif
  11. +
  12. typedef struct {
  13. /* the round robin data must be first */
  14. @@ -208,6 +212,12 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
  15. if (!peer->down) {
  16. +#if (NGX_UPSTREAM_CHECK_MODULE)
  17. + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
  18. + "get ip_hash peer, check_index: %ui",
  19. + peer->check_index);
  20. + if (!ngx_http_check_peer_down(peer->check_index)) {
  21. +#endif
  22. if (peer->max_fails == 0 || peer->fails < peer->max_fails) {
  23. break;
  24. }
  25. @@ -216,6 +226,9 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
  26. peer->checked = now;
  27. break;
  28. }
  29. +#if (NGX_UPSTREAM_CHECK_MODULE)
  30. + }
  31. +#endif
  32. }
  33. iphp->rrp.tried[n] |= m;
  34. diff --git a/src/http/modules/ngx_http_upstream_least_conn_module.c b/src/http/modules/ngx_http_upstream_least_conn_module.c
  35. index 21156ae..c57393d 100644
  36. --- a/src/http/modules/ngx_http_upstream_least_conn_module.c
  37. +++ b/src/http/modules/ngx_http_upstream_least_conn_module.c
  38. @@ -9,6 +9,10 @@
  39. #include <ngx_core.h>
  40. #include <ngx_http.h>
  41. +#if (NGX_UPSTREAM_CHECK_MODULE)
  42. +#include "ngx_http_upstream_check_handler.h"
  43. +#endif
  44. +
  45. typedef struct {
  46. ngx_uint_t *conns;
  47. @@ -203,6 +207,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
  48. continue;
  49. }
  50. +#if (NGX_UPSTREAM_CHECK_MODULE)
  51. + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
  52. + "get least_conn peer, check_index: %ui",
  53. + peer->check_index);
  54. +
  55. + if (ngx_http_check_peer_down(peer->check_index)) {
  56. + continue;
  57. + }
  58. +#endif
  59. +
  60. if (peer->max_fails
  61. && peer->fails >= peer->max_fails
  62. && now - peer->checked <= peer->fail_timeout)
  63. @@ -256,6 +270,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
  64. continue;
  65. }
  66. +#if (NGX_UPSTREAM_CHECK_MODULE)
  67. + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
  68. + "get least_conn peer, check_index: %ui",
  69. + peer->check_index);
  70. +
  71. + if (ngx_http_check_peer_down(peer->check_index)) {
  72. + continue;
  73. + }
  74. +#endif
  75. +
  76. if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) {
  77. continue;
  78. }
  79. diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
  80. index 4b78cff..f077b46 100644
  81. --- a/src/http/ngx_http_upstream_round_robin.c
  82. +++ b/src/http/ngx_http_upstream_round_robin.c
  83. @@ -9,6 +9,9 @@
  84. #include <ngx_core.h>
  85. #include <ngx_http.h>
  86. +#if (NGX_UPSTREAM_CHECK_MODULE)
  87. +#include "ngx_http_upstream_check_handler.h"
  88. +#endif
  89. static ngx_int_t ngx_http_upstream_cmp_servers(const void *one,
  90. const void *two);
  91. @@ -87,7 +90,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
  92. peers->peer[n].weight = server[i].weight;
  93. peers->peer[n].effective_weight = server[i].weight;
  94. peers->peer[n].current_weight = 0;
  95. - n++;
  96. +
  97. +#if (NGX_UPSTREAM_CHECK_MODULE)
  98. + if (!server[i].down) {
  99. + peers->peer[n].check_index =
  100. + ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
  101. + }
  102. + else {
  103. + peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
  104. + }
  105. +#endif
  106. + n++;
  107. }
  108. }
  109. @@ -145,6 +158,17 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
  110. backup->peer[n].max_fails = server[i].max_fails;
  111. backup->peer[n].fail_timeout = server[i].fail_timeout;
  112. backup->peer[n].down = server[i].down;
  113. +
  114. +#if (NGX_UPSTREAM_CHECK_MODULE)
  115. + if (!server[i].down) {
  116. + backup->peer[n].check_index =
  117. + ngx_http_check_add_peer(cf, us, &server[i].addrs[j]);
  118. + }
  119. + else {
  120. + backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
  121. + }
  122. +#endif
  123. +
  124. n++;
  125. }
  126. }
  127. @@ -206,6 +230,9 @@ ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
  128. peers->peer[i].current_weight = 0;
  129. peers->peer[i].max_fails = 1;
  130. peers->peer[i].fail_timeout = 10;
  131. +#if (NGX_UPSTREAM_CHECK_MODULE)
  132. + peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
  133. +#endif
  134. }
  135. us->peer.data = peers;
  136. @@ -323,6 +350,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
  137. peers->peer[0].current_weight = 0;
  138. peers->peer[0].max_fails = 1;
  139. peers->peer[0].fail_timeout = 10;
  140. +#if (NGX_UPSTREAM_CHECK_MODULE)
  141. + peers->peer[0].check_index = (ngx_uint_t) NGX_ERROR;
  142. +#endif
  143. } else {
  144. @@ -356,6 +386,9 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
  145. peers->peer[i].current_weight = 0;
  146. peers->peer[i].max_fails = 1;
  147. peers->peer[i].fail_timeout = 10;
  148. +#if (NGX_UPSTREAM_CHECK_MODULE)
  149. + peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
  150. +#endif
  151. }
  152. }
  153. @@ -434,6 +467,12 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
  154. goto failed;
  155. }
  156. +#if (NGX_UPSTREAM_CHECK_MODULE)
  157. + if (ngx_http_check_peer_down(peer->check_index)) {
  158. + goto failed;
  159. + }
  160. +#endif
  161. +
  162. } else {
  163. /* there are several peers */
  164. @@ -531,6 +570,12 @@ ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp)
  165. continue;
  166. }
  167. +#if (NGX_UPSTREAM_CHECK_MODULE)
  168. + if (ngx_http_check_peer_down(peer->check_index)) {
  169. + continue;
  170. + }
  171. +#endif
  172. +
  173. if (peer->max_fails
  174. && peer->fails >= peer->max_fails
  175. && now - peer->checked <= peer->fail_timeout)
  176. diff --git a/src/http/ngx_http_upstream_round_robin.h b/src/http/ngx_http_upstream_round_robin.h
  177. index 3f8cbf8..1613168 100644
  178. --- a/src/http/ngx_http_upstream_round_robin.h
  179. +++ b/src/http/ngx_http_upstream_round_robin.h
  180. @@ -30,6 +30,10 @@ typedef struct {
  181. ngx_uint_t max_fails;
  182. time_t fail_timeout;
  183. +#if (NGX_UPSTREAM_CHECK_MODULE)
  184. + ngx_uint_t check_index;
  185. +#endif
  186. +
  187. ngx_uint_t down; /* unsigned down:1; */
  188. #if (NGX_HTTP_SSL)