Latest update - GitHub 569948a
This commit is contained in:
@@ -2877,7 +2877,7 @@ ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
|
||||
* conf->upstream.store_lengths = NULL;
|
||||
* conf->upstream.store_values = NULL;
|
||||
*
|
||||
* conf->index.len = { 0, NULL };
|
||||
* conf->index = { 0, NULL };
|
||||
*/
|
||||
|
||||
conf->upstream.store = NGX_CONF_UNSET;
|
||||
|
||||
@@ -4475,12 +4475,16 @@ ngx_http_grpc_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
|
||||
prev->upstream.ssl_session_reuse, 1);
|
||||
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
|NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
|
||||
#endif
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#else
|
||||
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#endif
|
||||
|
||||
ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
|
||||
"DEFAULT");
|
||||
|
||||
@@ -3176,7 +3176,10 @@ ngx_http_mp4_crop_stsc_data(ngx_http_mp4_file_t *mp4,
|
||||
|
||||
start_sample -= n;
|
||||
|
||||
prev_samples = samples;
|
||||
if (next_chunk > chunk) {
|
||||
prev_samples = samples;
|
||||
}
|
||||
|
||||
chunk = next_chunk;
|
||||
samples = ngx_mp4_get_32value(entry->samples);
|
||||
id = ngx_mp4_get_32value(entry->id);
|
||||
@@ -3186,6 +3189,13 @@ ngx_http_mp4_crop_stsc_data(ngx_http_mp4_file_t *mp4,
|
||||
|
||||
next_chunk = trak->chunks + 1;
|
||||
|
||||
if (next_chunk < chunk) {
|
||||
ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
|
||||
"unordered mp4 stsc chunks in \"%s\"",
|
||||
mp4->file.name.data);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
|
||||
"sample:%uD, chunk:%uD, chunks:%uD, samples:%uD",
|
||||
start_sample, chunk, next_chunk - chunk, samples);
|
||||
@@ -3211,6 +3221,12 @@ found:
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (chunk == 0) {
|
||||
ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
|
||||
"zero chunk in \"%s\"", mp4->file.name.data);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
target_chunk = chunk - 1;
|
||||
target_chunk += start_sample / samples;
|
||||
chunk_samples = start_sample % samples;
|
||||
|
||||
@@ -3733,12 +3733,16 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
|
||||
prev->upstream.ssl_session_reuse, 1);
|
||||
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
|NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
|
||||
#endif
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#else
|
||||
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#endif
|
||||
|
||||
ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
|
||||
"DEFAULT");
|
||||
|
||||
@@ -1283,6 +1283,21 @@ ngx_http_scgi_create_loc_conf(ngx_conf_t *cf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* set by ngx_pcalloc():
|
||||
*
|
||||
* conf->upstream.bufs.num = 0;
|
||||
* conf->upstream.ignore_headers = 0;
|
||||
* conf->upstream.next_upstream = 0;
|
||||
* conf->upstream.cache_zone = NULL;
|
||||
* conf->upstream.cache_use_stale = 0;
|
||||
* conf->upstream.cache_methods = 0;
|
||||
* conf->upstream.temp_path = NULL;
|
||||
* conf->upstream.hide_headers_hash = { NULL, 0 };
|
||||
* conf->upstream.store_lengths = NULL;
|
||||
* conf->upstream.store_values = NULL;
|
||||
*/
|
||||
|
||||
conf->upstream.store = NGX_CONF_UNSET;
|
||||
conf->upstream.store_access = NGX_CONF_UNSET_UINT;
|
||||
conf->upstream.next_upstream_tries = NGX_CONF_UNSET_UINT;
|
||||
|
||||
@@ -691,12 +691,16 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
ngx_conf_merge_value(conf->early_data, prev->early_data, 1);
|
||||
ngx_conf_merge_value(conf->reject_handshake, prev->reject_handshake, 0);
|
||||
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
|NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
|
||||
#endif
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#else
|
||||
ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#endif
|
||||
|
||||
ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
|
||||
NGX_SSL_BUFSIZE);
|
||||
|
||||
@@ -24,6 +24,9 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
ngx_http_complex_value_t key;
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
ngx_uint_t config;
|
||||
#endif
|
||||
ngx_http_upstream_chash_points_t *points;
|
||||
} ngx_http_upstream_hash_srv_conf_t;
|
||||
|
||||
@@ -49,6 +52,8 @@ static ngx_int_t ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc,
|
||||
|
||||
static ngx_int_t ngx_http_upstream_init_chash(ngx_conf_t *cf,
|
||||
ngx_http_upstream_srv_conf_t *us);
|
||||
static ngx_int_t ngx_http_upstream_update_chash(ngx_pool_t *pool,
|
||||
ngx_http_upstream_srv_conf_t *us);
|
||||
static int ngx_libc_cdecl
|
||||
ngx_http_upstream_chash_cmp_points(const void *one, const void *two);
|
||||
static ngx_uint_t ngx_http_upstream_find_chash_point(
|
||||
@@ -178,11 +183,18 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
|
||||
ngx_http_upstream_rr_peers_rlock(hp->rrp.peers);
|
||||
|
||||
if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
|
||||
if (hp->tries > 20 || hp->rrp.peers->number < 2 || hp->key.len == 0) {
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
return hp->get_rr_peer(pc, &hp->rrp);
|
||||
}
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (hp->rrp.peers->config && hp->rrp.config != *hp->rrp.peers->config) {
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
return hp->get_rr_peer(pc, &hp->rrp);
|
||||
}
|
||||
#endif
|
||||
|
||||
now = ngx_time();
|
||||
|
||||
pc->cached = 0;
|
||||
@@ -262,6 +274,7 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
}
|
||||
|
||||
hp->rrp.current = peer;
|
||||
ngx_http_upstream_rr_peer_ref(hp->rrp.peers, peer);
|
||||
|
||||
pc->sockaddr = peer->sockaddr;
|
||||
pc->socklen = peer->socklen;
|
||||
@@ -284,6 +297,26 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_upstream_init_chash(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
|
||||
{
|
||||
if (ngx_http_upstream_init_round_robin(cf, us) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
us->peer.init = ngx_http_upstream_init_chash_peer;
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (us->shm_zone) {
|
||||
return NGX_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ngx_http_upstream_update_chash(cf->pool, us);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_upstream_update_chash(ngx_pool_t *pool,
|
||||
ngx_http_upstream_srv_conf_t *us)
|
||||
{
|
||||
u_char *host, *port, c;
|
||||
size_t host_len, port_len, size;
|
||||
@@ -299,25 +332,32 @@ ngx_http_upstream_init_chash(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
|
||||
u_char byte[4];
|
||||
} prev_hash;
|
||||
|
||||
if (ngx_http_upstream_init_round_robin(cf, us) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
hcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_hash_module);
|
||||
|
||||
us->peer.init = ngx_http_upstream_init_chash_peer;
|
||||
if (hcf->points) {
|
||||
ngx_free(hcf->points);
|
||||
hcf->points = NULL;
|
||||
}
|
||||
|
||||
peers = us->peer.data;
|
||||
npoints = peers->total_weight * 160;
|
||||
|
||||
size = sizeof(ngx_http_upstream_chash_points_t)
|
||||
+ sizeof(ngx_http_upstream_chash_point_t) * (npoints - 1);
|
||||
- sizeof(ngx_http_upstream_chash_point_t)
|
||||
+ sizeof(ngx_http_upstream_chash_point_t) * npoints;
|
||||
|
||||
points = ngx_palloc(cf->pool, size);
|
||||
points = pool ? ngx_palloc(pool, size) : ngx_alloc(size, ngx_cycle->log);
|
||||
if (points == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
points->number = 0;
|
||||
|
||||
if (npoints == 0) {
|
||||
hcf->points = points;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
for (peer = peers->peer; peer; peer = peer->next) {
|
||||
server = &peer->server;
|
||||
|
||||
@@ -401,7 +441,6 @@ ngx_http_upstream_init_chash(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
|
||||
|
||||
points->number = i + 1;
|
||||
|
||||
hcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_hash_module);
|
||||
hcf->points = points;
|
||||
|
||||
return NGX_OK;
|
||||
@@ -481,7 +520,22 @@ ngx_http_upstream_init_chash_peer(ngx_http_request_t *r,
|
||||
|
||||
ngx_http_upstream_rr_peers_rlock(hp->rrp.peers);
|
||||
|
||||
hp->hash = ngx_http_upstream_find_chash_point(hcf->points, hash);
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (hp->rrp.peers->config
|
||||
&& (hcf->points == NULL || hcf->config != *hp->rrp.peers->config))
|
||||
{
|
||||
if (ngx_http_upstream_update_chash(NULL, us) != NGX_OK) {
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
hcf->config = *hp->rrp.peers->config;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (hcf->points->number) {
|
||||
hp->hash = ngx_http_upstream_find_chash_point(hcf->points, hash);
|
||||
}
|
||||
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
|
||||
@@ -517,6 +571,20 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
pc->cached = 0;
|
||||
pc->connection = NULL;
|
||||
|
||||
if (hp->rrp.peers->number == 0) {
|
||||
pc->name = hp->rrp.peers->name;
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
return NGX_BUSY;
|
||||
}
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (hp->rrp.peers->config && hp->rrp.config != *hp->rrp.peers->config) {
|
||||
pc->name = hp->rrp.peers->name;
|
||||
ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
|
||||
return NGX_BUSY;
|
||||
}
|
||||
#endif
|
||||
|
||||
now = ngx_time();
|
||||
hcf = hp->conf;
|
||||
|
||||
@@ -597,6 +665,7 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
found:
|
||||
|
||||
hp->rrp.current = best;
|
||||
ngx_http_upstream_rr_peer_ref(hp->rrp.peers, best);
|
||||
|
||||
pc->sockaddr = best->sockaddr;
|
||||
pc->socklen = best->socklen;
|
||||
@@ -664,6 +733,7 @@ ngx_http_upstream_hash(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
}
|
||||
|
||||
uscf->flags = NGX_HTTP_UPSTREAM_CREATE
|
||||
|NGX_HTTP_UPSTREAM_MODIFY
|
||||
|NGX_HTTP_UPSTREAM_WEIGHT
|
||||
|NGX_HTTP_UPSTREAM_MAX_CONNS
|
||||
|NGX_HTTP_UPSTREAM_MAX_FAILS
|
||||
|
||||
@@ -163,11 +163,19 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
|
||||
ngx_http_upstream_rr_peers_rlock(iphp->rrp.peers);
|
||||
|
||||
if (iphp->tries > 20 || iphp->rrp.peers->single) {
|
||||
if (iphp->tries > 20 || iphp->rrp.peers->number < 2) {
|
||||
ngx_http_upstream_rr_peers_unlock(iphp->rrp.peers);
|
||||
return iphp->get_rr_peer(pc, &iphp->rrp);
|
||||
}
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (iphp->rrp.peers->config && iphp->rrp.config != *iphp->rrp.peers->config)
|
||||
{
|
||||
ngx_http_upstream_rr_peers_unlock(iphp->rrp.peers);
|
||||
return iphp->get_rr_peer(pc, &iphp->rrp);
|
||||
}
|
||||
#endif
|
||||
|
||||
now = ngx_time();
|
||||
|
||||
pc->cached = 0;
|
||||
@@ -232,6 +240,7 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
|
||||
}
|
||||
|
||||
iphp->rrp.current = peer;
|
||||
ngx_http_upstream_rr_peer_ref(iphp->rrp.peers, peer);
|
||||
|
||||
pc->sockaddr = peer->sockaddr;
|
||||
pc->socklen = peer->socklen;
|
||||
@@ -268,6 +277,7 @@ ngx_http_upstream_ip_hash(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
uscf->peer.init_upstream = ngx_http_upstream_init_ip_hash;
|
||||
|
||||
uscf->flags = NGX_HTTP_UPSTREAM_CREATE
|
||||
|NGX_HTTP_UPSTREAM_MODIFY
|
||||
|NGX_HTTP_UPSTREAM_WEIGHT
|
||||
|NGX_HTTP_UPSTREAM_MAX_CONNS
|
||||
|NGX_HTTP_UPSTREAM_MAX_FAILS
|
||||
|
||||
@@ -124,6 +124,12 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
|
||||
|
||||
ngx_http_upstream_rr_peers_wlock(peers);
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (peers->config && rrp->config != *peers->config) {
|
||||
goto busy;
|
||||
}
|
||||
#endif
|
||||
|
||||
best = NULL;
|
||||
total = 0;
|
||||
|
||||
@@ -244,6 +250,7 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
|
||||
best->conns++;
|
||||
|
||||
rrp->current = best;
|
||||
ngx_http_upstream_rr_peer_ref(peers, best);
|
||||
|
||||
n = p / (8 * sizeof(uintptr_t));
|
||||
m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t));
|
||||
@@ -280,6 +287,10 @@ failed:
|
||||
ngx_http_upstream_rr_peers_wlock(peers);
|
||||
}
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
busy:
|
||||
#endif
|
||||
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
|
||||
pc->name = peers->name;
|
||||
@@ -303,6 +314,7 @@ ngx_http_upstream_least_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
uscf->peer.init_upstream = ngx_http_upstream_init_least_conn;
|
||||
|
||||
uscf->flags = NGX_HTTP_UPSTREAM_CREATE
|
||||
|NGX_HTTP_UPSTREAM_MODIFY
|
||||
|NGX_HTTP_UPSTREAM_WEIGHT
|
||||
|NGX_HTTP_UPSTREAM_MAX_CONNS
|
||||
|NGX_HTTP_UPSTREAM_MAX_FAILS
|
||||
|
||||
@@ -17,6 +17,9 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
ngx_uint_t two;
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
ngx_uint_t config;
|
||||
#endif
|
||||
ngx_http_upstream_random_range_t *ranges;
|
||||
} ngx_http_upstream_random_srv_conf_t;
|
||||
|
||||
@@ -127,6 +130,11 @@ ngx_http_upstream_update_random(ngx_pool_t *pool,
|
||||
|
||||
rcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_random_module);
|
||||
|
||||
if (rcf->ranges) {
|
||||
ngx_free(rcf->ranges);
|
||||
rcf->ranges = NULL;
|
||||
}
|
||||
|
||||
peers = us->peer.data;
|
||||
|
||||
size = peers->number * sizeof(ngx_http_upstream_random_range_t);
|
||||
@@ -186,11 +194,15 @@ ngx_http_upstream_init_random_peer(ngx_http_request_t *r,
|
||||
ngx_http_upstream_rr_peers_rlock(rp->rrp.peers);
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (rp->rrp.peers->shpool && rcf->ranges == NULL) {
|
||||
if (rp->rrp.peers->config
|
||||
&& (rcf->ranges == NULL || rcf->config != *rp->rrp.peers->config))
|
||||
{
|
||||
if (ngx_http_upstream_update_random(NULL, us) != NGX_OK) {
|
||||
ngx_http_upstream_rr_peers_unlock(rp->rrp.peers);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
rcf->config = *rp->rrp.peers->config;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -220,11 +232,18 @@ ngx_http_upstream_get_random_peer(ngx_peer_connection_t *pc, void *data)
|
||||
|
||||
ngx_http_upstream_rr_peers_rlock(peers);
|
||||
|
||||
if (rp->tries > 20 || peers->single) {
|
||||
if (rp->tries > 20 || peers->number < 2) {
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
return ngx_http_upstream_get_round_robin_peer(pc, rrp);
|
||||
}
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (peers->config && rrp->config != *peers->config) {
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
return ngx_http_upstream_get_round_robin_peer(pc, rrp);
|
||||
}
|
||||
#endif
|
||||
|
||||
pc->cached = 0;
|
||||
pc->connection = NULL;
|
||||
|
||||
@@ -274,6 +293,7 @@ ngx_http_upstream_get_random_peer(ngx_peer_connection_t *pc, void *data)
|
||||
}
|
||||
|
||||
rrp->current = peer;
|
||||
ngx_http_upstream_rr_peer_ref(peers, peer);
|
||||
|
||||
if (now - peer->checked > peer->fail_timeout) {
|
||||
peer->checked = now;
|
||||
@@ -314,11 +334,18 @@ ngx_http_upstream_get_random2_peer(ngx_peer_connection_t *pc, void *data)
|
||||
|
||||
ngx_http_upstream_rr_peers_wlock(peers);
|
||||
|
||||
if (rp->tries > 20 || peers->single) {
|
||||
if (rp->tries > 20 || peers->number < 2) {
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
return ngx_http_upstream_get_round_robin_peer(pc, rrp);
|
||||
}
|
||||
|
||||
#if (NGX_HTTP_UPSTREAM_ZONE)
|
||||
if (peers->config && rrp->config != *peers->config) {
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
return ngx_http_upstream_get_round_robin_peer(pc, rrp);
|
||||
}
|
||||
#endif
|
||||
|
||||
pc->cached = 0;
|
||||
pc->connection = NULL;
|
||||
|
||||
@@ -384,6 +411,7 @@ ngx_http_upstream_get_random2_peer(ngx_peer_connection_t *pc, void *data)
|
||||
}
|
||||
|
||||
rrp->current = peer;
|
||||
ngx_http_upstream_rr_peer_ref(peers, peer);
|
||||
|
||||
if (now - peer->checked > peer->fail_timeout) {
|
||||
peer->checked = now;
|
||||
@@ -467,6 +495,7 @@ ngx_http_upstream_random(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
uscf->peer.init_upstream = ngx_http_upstream_init_random;
|
||||
|
||||
uscf->flags = NGX_HTTP_UPSTREAM_CREATE
|
||||
|NGX_HTTP_UPSTREAM_MODIFY
|
||||
|NGX_HTTP_UPSTREAM_WEIGHT
|
||||
|NGX_HTTP_UPSTREAM_MAX_CONNS
|
||||
|NGX_HTTP_UPSTREAM_MAX_FAILS
|
||||
|
||||
@@ -15,9 +15,22 @@ static char *ngx_http_upstream_zone(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
static ngx_int_t ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone,
|
||||
void *data);
|
||||
static ngx_http_upstream_rr_peers_t *ngx_http_upstream_zone_copy_peers(
|
||||
ngx_slab_pool_t *shpool, ngx_http_upstream_srv_conf_t *uscf);
|
||||
ngx_slab_pool_t *shpool, ngx_http_upstream_srv_conf_t *uscf,
|
||||
ngx_http_upstream_srv_conf_t *ouscf);
|
||||
static ngx_http_upstream_rr_peer_t *ngx_http_upstream_zone_copy_peer(
|
||||
ngx_http_upstream_rr_peers_t *peers, ngx_http_upstream_rr_peer_t *src);
|
||||
static ngx_int_t ngx_http_upstream_zone_preresolve(
|
||||
ngx_http_upstream_rr_peer_t *resolve,
|
||||
ngx_http_upstream_rr_peers_t *peers,
|
||||
ngx_http_upstream_rr_peer_t *oresolve,
|
||||
ngx_http_upstream_rr_peers_t *opeers);
|
||||
static void ngx_http_upstream_zone_set_single(
|
||||
ngx_http_upstream_srv_conf_t *uscf);
|
||||
static void ngx_http_upstream_zone_remove_peer_locked(
|
||||
ngx_http_upstream_rr_peers_t *peers, ngx_http_upstream_rr_peer_t *peer);
|
||||
static ngx_int_t ngx_http_upstream_zone_init_worker(ngx_cycle_t *cycle);
|
||||
static void ngx_http_upstream_zone_resolve_timer(ngx_event_t *event);
|
||||
static void ngx_http_upstream_zone_resolve_handler(ngx_resolver_ctx_t *ctx);
|
||||
|
||||
|
||||
static ngx_command_t ngx_http_upstream_zone_commands[] = {
|
||||
@@ -55,7 +68,7 @@ ngx_module_t ngx_http_upstream_zone_module = {
|
||||
NGX_HTTP_MODULE, /* module type */
|
||||
NULL, /* init master */
|
||||
NULL, /* init module */
|
||||
NULL, /* init process */
|
||||
ngx_http_upstream_zone_init_worker, /* init process */
|
||||
NULL, /* init thread */
|
||||
NULL, /* exit thread */
|
||||
NULL, /* exit process */
|
||||
@@ -121,11 +134,11 @@ static ngx_int_t
|
||||
ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
||||
{
|
||||
size_t len;
|
||||
ngx_uint_t i;
|
||||
ngx_uint_t i, j;
|
||||
ngx_slab_pool_t *shpool;
|
||||
ngx_http_upstream_rr_peers_t *peers, **peersp;
|
||||
ngx_http_upstream_srv_conf_t *uscf, **uscfp;
|
||||
ngx_http_upstream_main_conf_t *umcf;
|
||||
ngx_http_upstream_srv_conf_t *uscf, *ouscf, **uscfp, **ouscfp;
|
||||
ngx_http_upstream_main_conf_t *umcf, *oumcf;
|
||||
|
||||
shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
|
||||
umcf = shm_zone->data;
|
||||
@@ -162,6 +175,7 @@ ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
||||
/* copy peers to shared memory */
|
||||
|
||||
peersp = (ngx_http_upstream_rr_peers_t **) (void *) &shpool->data;
|
||||
oumcf = data;
|
||||
|
||||
for (i = 0; i < umcf->upstreams.nelts; i++) {
|
||||
uscf = uscfp[i];
|
||||
@@ -170,7 +184,38 @@ ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
||||
continue;
|
||||
}
|
||||
|
||||
peers = ngx_http_upstream_zone_copy_peers(shpool, uscf);
|
||||
ouscf = NULL;
|
||||
|
||||
if (oumcf) {
|
||||
ouscfp = oumcf->upstreams.elts;
|
||||
|
||||
for (j = 0; j < oumcf->upstreams.nelts; j++) {
|
||||
|
||||
if (ouscfp[j]->shm_zone == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ouscfp[j]->shm_zone->shm.name.len != shm_zone->shm.name.len
|
||||
|| ngx_memcmp(ouscfp[j]->shm_zone->shm.name.data,
|
||||
shm_zone->shm.name.data,
|
||||
shm_zone->shm.name.len)
|
||||
!= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ouscfp[j]->host.len == uscf->host.len
|
||||
&& ngx_memcmp(ouscfp[j]->host.data, uscf->host.data,
|
||||
uscf->host.len)
|
||||
== 0)
|
||||
{
|
||||
ouscf = ouscfp[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
peers = ngx_http_upstream_zone_copy_peers(shpool, uscf, ouscf);
|
||||
if (peers == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
@@ -185,11 +230,19 @@ ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
||||
|
||||
static ngx_http_upstream_rr_peers_t *
|
||||
ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
||||
ngx_http_upstream_srv_conf_t *uscf)
|
||||
ngx_http_upstream_srv_conf_t *uscf, ngx_http_upstream_srv_conf_t *ouscf)
|
||||
{
|
||||
ngx_str_t *name;
|
||||
ngx_uint_t *config;
|
||||
ngx_http_upstream_rr_peer_t *peer, **peerp;
|
||||
ngx_http_upstream_rr_peers_t *peers, *backup;
|
||||
ngx_http_upstream_rr_peers_t *peers, *opeers, *backup;
|
||||
|
||||
opeers = (ouscf ? ouscf->peer.data : NULL);
|
||||
|
||||
config = ngx_slab_calloc(shpool, sizeof(ngx_uint_t));
|
||||
if (config == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
peers = ngx_slab_alloc(shpool, sizeof(ngx_http_upstream_rr_peers_t));
|
||||
if (peers == NULL) {
|
||||
@@ -214,6 +267,7 @@ ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
||||
peers->name = name;
|
||||
|
||||
peers->shpool = shpool;
|
||||
peers->config = config;
|
||||
|
||||
for (peerp = &peers->peer; *peerp; peerp = &peer->next) {
|
||||
/* pool is unlocked */
|
||||
@@ -223,6 +277,27 @@ ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
||||
}
|
||||
|
||||
*peerp = peer;
|
||||
(*peers->config)++;
|
||||
}
|
||||
|
||||
for (peerp = &peers->resolve; *peerp; peerp = &peer->next) {
|
||||
peer = ngx_http_upstream_zone_copy_peer(peers, *peerp);
|
||||
if (peer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*peerp = peer;
|
||||
(*peers->config)++;
|
||||
}
|
||||
|
||||
if (opeers) {
|
||||
|
||||
if (ngx_http_upstream_zone_preresolve(peers->resolve, peers,
|
||||
opeers->resolve, opeers)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (peers->next == NULL) {
|
||||
@@ -239,6 +314,7 @@ ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
||||
backup->name = name;
|
||||
|
||||
backup->shpool = shpool;
|
||||
backup->config = config;
|
||||
|
||||
for (peerp = &backup->peer; *peerp; peerp = &peer->next) {
|
||||
/* pool is unlocked */
|
||||
@@ -248,14 +324,45 @@ ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
|
||||
}
|
||||
|
||||
*peerp = peer;
|
||||
(*backup->config)++;
|
||||
}
|
||||
|
||||
for (peerp = &backup->resolve; *peerp; peerp = &peer->next) {
|
||||
peer = ngx_http_upstream_zone_copy_peer(backup, *peerp);
|
||||
if (peer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*peerp = peer;
|
||||
(*backup->config)++;
|
||||
}
|
||||
|
||||
peers->next = backup;
|
||||
|
||||
if (opeers && opeers->next) {
|
||||
|
||||
if (ngx_http_upstream_zone_preresolve(peers->resolve, backup,
|
||||
opeers->resolve, opeers->next)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ngx_http_upstream_zone_preresolve(backup->resolve, backup,
|
||||
opeers->next->resolve,
|
||||
opeers->next)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
uscf->peer.data = peers;
|
||||
|
||||
ngx_http_upstream_zone_set_single(uscf);
|
||||
|
||||
return peers;
|
||||
}
|
||||
|
||||
@@ -279,6 +386,7 @@ ngx_http_upstream_zone_copy_peer(ngx_http_upstream_rr_peers_t *peers,
|
||||
dst->sockaddr = NULL;
|
||||
dst->name.data = NULL;
|
||||
dst->server.data = NULL;
|
||||
dst->host = NULL;
|
||||
}
|
||||
|
||||
dst->sockaddr = ngx_slab_calloc_locked(pool, sizeof(ngx_sockaddr_t));
|
||||
@@ -301,12 +409,53 @@ ngx_http_upstream_zone_copy_peer(ngx_http_upstream_rr_peers_t *peers,
|
||||
}
|
||||
|
||||
ngx_memcpy(dst->server.data, src->server.data, src->server.len);
|
||||
|
||||
if (src->host) {
|
||||
dst->host = ngx_slab_calloc_locked(pool,
|
||||
sizeof(ngx_http_upstream_host_t));
|
||||
if (dst->host == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
dst->host->name.data = ngx_slab_alloc_locked(pool,
|
||||
src->host->name.len);
|
||||
if (dst->host->name.data == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
dst->host->peers = peers;
|
||||
dst->host->peer = dst;
|
||||
|
||||
dst->host->name.len = src->host->name.len;
|
||||
ngx_memcpy(dst->host->name.data, src->host->name.data,
|
||||
src->host->name.len);
|
||||
|
||||
if (src->host->service.len) {
|
||||
dst->host->service.data = ngx_slab_alloc_locked(pool,
|
||||
src->host->service.len);
|
||||
if (dst->host->service.data == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
dst->host->service.len = src->host->service.len;
|
||||
ngx_memcpy(dst->host->service.data, src->host->service.data,
|
||||
src->host->service.len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
|
||||
failed:
|
||||
|
||||
if (dst->host) {
|
||||
if (dst->host->name.data) {
|
||||
ngx_slab_free_locked(pool, dst->host->name.data);
|
||||
}
|
||||
|
||||
ngx_slab_free_locked(pool, dst->host);
|
||||
}
|
||||
|
||||
if (dst->server.data) {
|
||||
ngx_slab_free_locked(pool, dst->server.data);
|
||||
}
|
||||
@@ -323,3 +472,536 @@ failed:
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_upstream_zone_preresolve(ngx_http_upstream_rr_peer_t *resolve,
|
||||
ngx_http_upstream_rr_peers_t *peers,
|
||||
ngx_http_upstream_rr_peer_t *oresolve,
|
||||
ngx_http_upstream_rr_peers_t *opeers)
|
||||
{
|
||||
in_port_t port;
|
||||
ngx_str_t *server;
|
||||
ngx_http_upstream_host_t *host;
|
||||
ngx_http_upstream_rr_peer_t *peer, *template, *opeer, **peerp;
|
||||
|
||||
if (resolve == NULL || oresolve == NULL) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
for (peerp = &peers->peer; *peerp; peerp = &(*peerp)->next) {
|
||||
/* void */
|
||||
}
|
||||
|
||||
ngx_http_upstream_rr_peers_rlock(opeers);
|
||||
|
||||
for (template = resolve; template; template = template->next) {
|
||||
for (opeer = oresolve; opeer; opeer = opeer->next) {
|
||||
|
||||
if (opeer->host->name.len != template->host->name.len
|
||||
|| ngx_memcmp(opeer->host->name.data,
|
||||
template->host->name.data,
|
||||
template->host->name.len)
|
||||
!= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (opeer->host->service.len != template->host->service.len
|
||||
|| ngx_memcmp(opeer->host->service.data,
|
||||
template->host->service.data,
|
||||
template->host->service.len)
|
||||
!= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
host = opeer->host;
|
||||
|
||||
for (opeer = opeers->peer; opeer; opeer = opeer->next) {
|
||||
|
||||
if (opeer->host != host) {
|
||||
continue;
|
||||
}
|
||||
|
||||
peer = ngx_http_upstream_zone_copy_peer(peers, NULL);
|
||||
if (peer == NULL) {
|
||||
ngx_http_upstream_rr_peers_unlock(opeers);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_memcpy(peer->sockaddr, opeer->sockaddr, opeer->socklen);
|
||||
|
||||
if (template->host->service.len == 0) {
|
||||
port = ngx_inet_get_port(template->sockaddr);
|
||||
ngx_inet_set_port(peer->sockaddr, port);
|
||||
}
|
||||
|
||||
peer->socklen = opeer->socklen;
|
||||
|
||||
peer->name.len = ngx_sock_ntop(peer->sockaddr, peer->socklen,
|
||||
peer->name.data,
|
||||
NGX_SOCKADDR_STRLEN, 1);
|
||||
|
||||
peer->host = template->host;
|
||||
|
||||
template->host->valid = host->valid;
|
||||
|
||||
server = template->host->service.len ? &opeer->server
|
||||
: &template->server;
|
||||
|
||||
peer->server.data = ngx_slab_alloc(peers->shpool, server->len);
|
||||
if (peer->server.data == NULL) {
|
||||
ngx_http_upstream_rr_peers_unlock(opeers);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_memcpy(peer->server.data, server->data, server->len);
|
||||
peer->server.len = server->len;
|
||||
|
||||
if (host->service.len == 0) {
|
||||
peer->weight = template->weight;
|
||||
|
||||
} else {
|
||||
peer->weight = (template->weight != 1 ? template->weight
|
||||
: opeer->weight);
|
||||
}
|
||||
|
||||
peer->effective_weight = peer->weight;
|
||||
peer->max_conns = template->max_conns;
|
||||
peer->max_fails = template->max_fails;
|
||||
peer->fail_timeout = template->fail_timeout;
|
||||
peer->down = template->down;
|
||||
|
||||
(*peers->config)++;
|
||||
|
||||
*peerp = peer;
|
||||
peerp = &peer->next;
|
||||
|
||||
peers->number++;
|
||||
peers->tries += (peer->down == 0);
|
||||
peers->total_weight += peer->weight;
|
||||
peers->weighted = (peers->total_weight != peers->number);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ngx_http_upstream_rr_peers_unlock(opeers);
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_http_upstream_zone_set_single(ngx_http_upstream_srv_conf_t *uscf)
|
||||
{
|
||||
ngx_http_upstream_rr_peers_t *peers;
|
||||
|
||||
peers = uscf->peer.data;
|
||||
|
||||
if (peers->number == 1
|
||||
&& (peers->next == NULL || peers->next->number == 0))
|
||||
{
|
||||
peers->single = 1;
|
||||
|
||||
} else {
|
||||
peers->single = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_http_upstream_zone_remove_peer_locked(ngx_http_upstream_rr_peers_t *peers,
|
||||
ngx_http_upstream_rr_peer_t *peer)
|
||||
{
|
||||
peers->total_weight -= peer->weight;
|
||||
peers->number--;
|
||||
peers->tries -= (peer->down == 0);
|
||||
(*peers->config)++;
|
||||
peers->weighted = (peers->total_weight != peers->number);
|
||||
|
||||
ngx_http_upstream_rr_peer_free(peers, peer);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_upstream_zone_init_worker(ngx_cycle_t *cycle)
|
||||
{
|
||||
time_t now;
|
||||
ngx_msec_t timer;
|
||||
ngx_uint_t i;
|
||||
ngx_event_t *event;
|
||||
ngx_http_upstream_rr_peer_t *peer;
|
||||
ngx_http_upstream_rr_peers_t *peers;
|
||||
ngx_http_upstream_srv_conf_t *uscf, **uscfp;
|
||||
ngx_http_upstream_main_conf_t *umcf;
|
||||
|
||||
if (ngx_process != NGX_PROCESS_WORKER
|
||||
&& ngx_process != NGX_PROCESS_SINGLE)
|
||||
{
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
now = ngx_time();
|
||||
umcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_upstream_module);
|
||||
|
||||
if (umcf == NULL) {
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
uscfp = umcf->upstreams.elts;
|
||||
|
||||
for (i = 0; i < umcf->upstreams.nelts; i++) {
|
||||
|
||||
uscf = uscfp[i];
|
||||
|
||||
if (uscf->shm_zone == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
peers = uscf->peer.data;
|
||||
|
||||
do {
|
||||
ngx_http_upstream_rr_peers_wlock(peers);
|
||||
|
||||
for (peer = peers->resolve; peer; peer = peer->next) {
|
||||
|
||||
if (peer->host->worker != ngx_worker) {
|
||||
continue;
|
||||
}
|
||||
|
||||
event = &peer->host->event;
|
||||
ngx_memzero(event, sizeof(ngx_event_t));
|
||||
|
||||
event->data = uscf;
|
||||
event->handler = ngx_http_upstream_zone_resolve_timer;
|
||||
event->log = cycle->log;
|
||||
event->cancelable = 1;
|
||||
|
||||
timer = (peer->host->valid > now)
|
||||
? (ngx_msec_t) 1000 * (peer->host->valid - now) : 1;
|
||||
|
||||
ngx_add_timer(event, timer);
|
||||
}
|
||||
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
|
||||
peers = peers->next;
|
||||
|
||||
} while (peers);
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_http_upstream_zone_resolve_timer(ngx_event_t *event)
|
||||
{
|
||||
ngx_resolver_ctx_t *ctx;
|
||||
ngx_http_upstream_host_t *host;
|
||||
ngx_http_upstream_srv_conf_t *uscf;
|
||||
|
||||
host = (ngx_http_upstream_host_t *) event;
|
||||
uscf = event->data;
|
||||
|
||||
ctx = ngx_resolve_start(uscf->resolver, NULL);
|
||||
if (ctx == NULL) {
|
||||
goto retry;
|
||||
}
|
||||
|
||||
if (ctx == NGX_NO_RESOLVER) {
|
||||
ngx_log_error(NGX_LOG_ERR, event->log, 0,
|
||||
"no resolver defined to resolve %V", &host->name);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->name = host->name;
|
||||
ctx->handler = ngx_http_upstream_zone_resolve_handler;
|
||||
ctx->data = host;
|
||||
ctx->timeout = uscf->resolver_timeout;
|
||||
ctx->service = host->service;
|
||||
ctx->cancelable = 1;
|
||||
|
||||
if (ngx_resolve_name(ctx) == NGX_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
retry:
|
||||
|
||||
ngx_add_timer(event, ngx_max(uscf->resolver_timeout, 1000));
|
||||
}
|
||||
|
||||
|
||||
#define ngx_http_upstream_zone_addr_marked(addr) \
|
||||
((uintptr_t) (addr)->sockaddr & 1)
|
||||
|
||||
#define ngx_http_upstream_zone_mark_addr(addr) \
|
||||
(addr)->sockaddr = (struct sockaddr *) ((uintptr_t) (addr)->sockaddr | 1)
|
||||
|
||||
#define ngx_http_upstream_zone_unmark_addr(addr) \
|
||||
(addr)->sockaddr = \
|
||||
(struct sockaddr *) ((uintptr_t) (addr)->sockaddr & ~((uintptr_t) 1))
|
||||
|
||||
static void
|
||||
ngx_http_upstream_zone_resolve_handler(ngx_resolver_ctx_t *ctx)
|
||||
{
|
||||
time_t now;
|
||||
u_short min_priority;
|
||||
in_port_t port;
|
||||
ngx_str_t *server;
|
||||
ngx_msec_t timer;
|
||||
ngx_uint_t i, j, backup, addr_backup;
|
||||
ngx_event_t *event;
|
||||
ngx_resolver_addr_t *addr;
|
||||
ngx_resolver_srv_name_t *srv;
|
||||
ngx_http_upstream_host_t *host;
|
||||
ngx_http_upstream_rr_peer_t *peer, *template, **peerp;
|
||||
ngx_http_upstream_rr_peers_t *peers;
|
||||
ngx_http_upstream_srv_conf_t *uscf;
|
||||
|
||||
host = ctx->data;
|
||||
event = &host->event;
|
||||
uscf = event->data;
|
||||
peers = host->peers;
|
||||
template = host->peer;
|
||||
|
||||
ngx_http_upstream_rr_peers_wlock(peers);
|
||||
|
||||
now = ngx_time();
|
||||
|
||||
for (i = 0; i < ctx->nsrvs; i++) {
|
||||
srv = &ctx->srvs[i];
|
||||
|
||||
if (srv->state) {
|
||||
ngx_log_error(NGX_LOG_ERR, event->log, 0,
|
||||
"%V could not be resolved (%i: %s) "
|
||||
"while resolving service %V of %V",
|
||||
&srv->name, srv->state,
|
||||
ngx_resolver_strerror(srv->state), &ctx->service,
|
||||
&ctx->name);
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->state) {
|
||||
if (ctx->service.len) {
|
||||
ngx_log_error(NGX_LOG_ERR, event->log, 0,
|
||||
"service %V of %V could not be resolved (%i: %s)",
|
||||
&ctx->service, &ctx->name, ctx->state,
|
||||
ngx_resolver_strerror(ctx->state));
|
||||
|
||||
} else {
|
||||
ngx_log_error(NGX_LOG_ERR, event->log, 0,
|
||||
"%V could not be resolved (%i: %s)",
|
||||
&ctx->name, ctx->state,
|
||||
ngx_resolver_strerror(ctx->state));
|
||||
}
|
||||
|
||||
if (ctx->state != NGX_RESOLVE_NXDOMAIN) {
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
|
||||
ngx_resolve_name_done(ctx);
|
||||
|
||||
ngx_add_timer(event, ngx_max(uscf->resolver_timeout, 1000));
|
||||
return;
|
||||
}
|
||||
|
||||
/* NGX_RESOLVE_NXDOMAIN */
|
||||
|
||||
ctx->naddrs = 0;
|
||||
}
|
||||
|
||||
backup = 0;
|
||||
min_priority = 65535;
|
||||
|
||||
for (i = 0; i < ctx->naddrs; i++) {
|
||||
min_priority = ngx_min(ctx->addrs[i].priority, min_priority);
|
||||
}
|
||||
|
||||
#if (NGX_DEBUG)
|
||||
{
|
||||
u_char text[NGX_SOCKADDR_STRLEN];
|
||||
size_t len;
|
||||
|
||||
for (i = 0; i < ctx->naddrs; i++) {
|
||||
len = ngx_sock_ntop(ctx->addrs[i].sockaddr, ctx->addrs[i].socklen,
|
||||
text, NGX_SOCKADDR_STRLEN, 1);
|
||||
|
||||
ngx_log_debug7(NGX_LOG_DEBUG_HTTP, event->log, 0,
|
||||
"name %V was resolved to %*s "
|
||||
"s:\"%V\" n:\"%V\" w:%d %s",
|
||||
&host->name, len, text, &host->service,
|
||||
&ctx->addrs[i].name, ctx->addrs[i].weight,
|
||||
ctx->addrs[i].priority != min_priority ? "backup" : "");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
again:
|
||||
|
||||
for (peerp = &peers->peer; *peerp; /* void */ ) {
|
||||
peer = *peerp;
|
||||
|
||||
if (peer->host != host) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
for (j = 0; j < ctx->naddrs; j++) {
|
||||
|
||||
addr = &ctx->addrs[j];
|
||||
|
||||
addr_backup = (addr->priority != min_priority);
|
||||
if (addr_backup != backup) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_http_upstream_zone_addr_marked(addr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_cmp_sockaddr(peer->sockaddr, peer->socklen,
|
||||
addr->sockaddr, addr->socklen,
|
||||
host->service.len != 0)
|
||||
!= NGX_OK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (host->service.len) {
|
||||
if (addr->name.len != peer->server.len
|
||||
|| ngx_strncmp(addr->name.data, peer->server.data,
|
||||
addr->name.len))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (template->weight == 1 && addr->weight != peer->weight) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ngx_http_upstream_zone_mark_addr(addr);
|
||||
|
||||
goto next;
|
||||
}
|
||||
|
||||
*peerp = peer->next;
|
||||
ngx_http_upstream_zone_remove_peer_locked(peers, peer);
|
||||
|
||||
ngx_http_upstream_zone_set_single(uscf);
|
||||
|
||||
continue;
|
||||
|
||||
next:
|
||||
|
||||
peerp = &peer->next;
|
||||
}
|
||||
|
||||
for (i = 0; i < ctx->naddrs; i++) {
|
||||
|
||||
addr = &ctx->addrs[i];
|
||||
|
||||
addr_backup = (addr->priority != min_priority);
|
||||
if (addr_backup != backup) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_http_upstream_zone_addr_marked(addr)) {
|
||||
ngx_http_upstream_zone_unmark_addr(addr);
|
||||
continue;
|
||||
}
|
||||
|
||||
ngx_shmtx_lock(&peers->shpool->mutex);
|
||||
peer = ngx_http_upstream_zone_copy_peer(peers, NULL);
|
||||
ngx_shmtx_unlock(&peers->shpool->mutex);
|
||||
|
||||
if (peer == NULL) {
|
||||
ngx_log_error(NGX_LOG_ERR, event->log, 0,
|
||||
"cannot add new server to upstream \"%V\", "
|
||||
"memory exhausted", peers->name);
|
||||
goto done;
|
||||
}
|
||||
|
||||
ngx_memcpy(peer->sockaddr, addr->sockaddr, addr->socklen);
|
||||
|
||||
if (host->service.len == 0) {
|
||||
port = ngx_inet_get_port(template->sockaddr);
|
||||
ngx_inet_set_port(peer->sockaddr, port);
|
||||
}
|
||||
|
||||
peer->socklen = addr->socklen;
|
||||
|
||||
peer->name.len = ngx_sock_ntop(peer->sockaddr, peer->socklen,
|
||||
peer->name.data, NGX_SOCKADDR_STRLEN, 1);
|
||||
|
||||
peer->host = template->host;
|
||||
|
||||
server = host->service.len ? &addr->name : &template->server;
|
||||
|
||||
peer->server.data = ngx_slab_alloc(peers->shpool, server->len);
|
||||
if (peer->server.data == NULL) {
|
||||
ngx_http_upstream_rr_peer_free(peers, peer);
|
||||
|
||||
ngx_log_error(NGX_LOG_ERR, event->log, 0,
|
||||
"cannot add new server to upstream \"%V\", "
|
||||
"memory exhausted", peers->name);
|
||||
goto done;
|
||||
}
|
||||
|
||||
peer->server.len = server->len;
|
||||
ngx_memcpy(peer->server.data, server->data, server->len);
|
||||
|
||||
if (host->service.len == 0) {
|
||||
peer->weight = template->weight;
|
||||
|
||||
} else {
|
||||
peer->weight = (template->weight != 1 ? template->weight
|
||||
: addr->weight);
|
||||
}
|
||||
|
||||
peer->effective_weight = peer->weight;
|
||||
peer->max_conns = template->max_conns;
|
||||
peer->max_fails = template->max_fails;
|
||||
peer->fail_timeout = template->fail_timeout;
|
||||
peer->down = template->down;
|
||||
|
||||
*peerp = peer;
|
||||
peerp = &peer->next;
|
||||
|
||||
peers->number++;
|
||||
peers->tries += (peer->down == 0);
|
||||
peers->total_weight += peer->weight;
|
||||
peers->weighted = (peers->total_weight != peers->number);
|
||||
(*peers->config)++;
|
||||
|
||||
ngx_http_upstream_zone_set_single(uscf);
|
||||
}
|
||||
|
||||
if (host->service.len && peers->next) {
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
|
||||
peers = peers->next;
|
||||
backup = 1;
|
||||
|
||||
ngx_http_upstream_rr_peers_wlock(peers);
|
||||
|
||||
goto again;
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
host->valid = ctx->valid;
|
||||
|
||||
ngx_http_upstream_rr_peers_unlock(peers);
|
||||
|
||||
while (++i < ctx->naddrs) {
|
||||
ngx_http_upstream_zone_unmark_addr(&ctx->addrs[i]);
|
||||
}
|
||||
|
||||
timer = (ngx_msec_t) 1000 * (ctx->valid > now ? ctx->valid - now + 1 : 1);
|
||||
|
||||
ngx_resolve_name_done(ctx);
|
||||
|
||||
ngx_add_timer(event, timer);
|
||||
}
|
||||
@@ -1511,6 +1511,28 @@ ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* set by ngx_pcalloc():
|
||||
*
|
||||
* conf->upstream.bufs.num = 0;
|
||||
* conf->upstream.ignore_headers = 0;
|
||||
* conf->upstream.next_upstream = 0;
|
||||
* conf->upstream.cache_zone = NULL;
|
||||
* conf->upstream.cache_use_stale = 0;
|
||||
* conf->upstream.cache_methods = 0;
|
||||
* conf->upstream.temp_path = NULL;
|
||||
* conf->upstream.hide_headers_hash = { NULL, 0 };
|
||||
* conf->upstream.store_lengths = NULL;
|
||||
* conf->upstream.store_values = NULL;
|
||||
*
|
||||
* conf->uwsgi_string = { 0, NULL };
|
||||
* conf->ssl = 0;
|
||||
* conf->ssl_protocols = 0;
|
||||
* conf->ssl_ciphers = { 0, NULL };
|
||||
* conf->ssl_trusted_certificate = { 0, NULL };
|
||||
* conf->ssl_crl = { 0, NULL };
|
||||
*/
|
||||
|
||||
conf->modifier1 = NGX_CONF_UNSET_UINT;
|
||||
conf->modifier2 = NGX_CONF_UNSET_UINT;
|
||||
|
||||
@@ -1877,12 +1899,16 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
ngx_conf_merge_value(conf->upstream.ssl_session_reuse,
|
||||
prev->upstream.ssl_session_reuse, 1);
|
||||
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
#ifndef SSL_OP_NO_TLSv1_2
|
||||
|NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
|
||||
#endif
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#else
|
||||
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
|
||||
(NGX_CONF_BITMASK_SET
|
||||
|NGX_SSL_TLSv1_2|NGX_SSL_TLSv1_3));
|
||||
#endif
|
||||
|
||||
ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
|
||||
"DEFAULT");
|
||||
|
||||
Reference in New Issue
Block a user