Welcome! Log In Create A New Profile

Advanced

[PATCH 4 of 6] Upstream: per-upstream resolver

Aleksei Bavshin
January 31, 2023 08:42PM
# HG changeset patch
# User Vladimir Homutov <vl@nginx.com>
# Date 1571405595 -10800
# Fri Oct 18 16:33:15 2019 +0300
# Node ID cfae397f1ea87a35c41febab6162fe5142aa767b
# Parent 95ea48662e8a8b7ee73b39c5791c06b5e17e3102
Upstream: per-upstream resolver.

The "resolver" and "resolver_timeout" directives can now be specified
directly in the "upstream" block.

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -169,6 +169,10 @@ static ngx_int_t ngx_http_upstream_cooki
static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+#if (NGX_HTTP_UPSTREAM_ZONE)
+static char *ngx_http_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+#endif

static ngx_int_t ngx_http_upstream_set_local(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_http_upstream_local_t *local);
@@ -339,6 +343,24 @@ static ngx_command_t ngx_http_upstream_
0,
NULL },

+#if (NGX_HTTP_UPSTREAM_ZONE)
+
+ { ngx_string("resolver"),
+ NGX_HTTP_UPS_CONF|NGX_CONF_1MORE,
+ ngx_http_upstream_resolver,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ 0,
+ NULL },
+
+ { ngx_string("resolver_timeout"),
+ NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_msec_slot,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ offsetof(ngx_http_upstream_srv_conf_t, resolver_timeout),
+ NULL },
+
+#endif
+
ngx_null_command
};

@@ -6401,6 +6423,32 @@ not_supported:
}


+#if (NGX_HTTP_UPSTREAM_ZONE)
+
+static char *
+ngx_http_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_upstream_srv_conf_t *uscf = conf;
+
+ ngx_str_t *value;
+
+ if (uscf->resolver) {
+ return "is duplicate";
+ }
+
+ value = cf->args->elts;
+
+ uscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
+ if (uscf->resolver == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ return NGX_CONF_OK;
+}
+
+#endif
+
+
ngx_http_upstream_srv_conf_t *
ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
{
@@ -6482,6 +6530,9 @@ ngx_http_upstream_add(ngx_conf_t *cf, ng
uscf->line = cf->conf_file->line;
uscf->port = u->port;
uscf->no_port = u->no_port;
+#if (NGX_HTTP_UPSTREAM_ZONE)
+ uscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
+#endif

if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {
uscf->servers = ngx_array_create(cf->pool, 1,
diff --git a/src/http/ngx_http_upstream_round_robin.c b/src/http/ngx_http_upstream_round_robin.c
--- a/src/http/ngx_http_upstream_round_robin.c
+++ b/src/http/ngx_http_upstream_round_robin.c
@@ -104,15 +104,15 @@ ngx_http_upstream_init_round_robin(ngx_c

clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);

- us->resolver = clcf->resolver;
- us->resolver_timeout = clcf->resolver_timeout;
+ if (us->resolver == NULL) {
+ us->resolver = clcf->resolver;
+ }

/*
- * Without "resolver_timeout" in http{}, the value is unset.
- * Even if we set it in ngx_http_core_merge_loc_conf(), it's
- * still dependent on the module order and unreliable.
+ * Without "resolver_timeout" in http{} the merged value is unset.
*/
- ngx_conf_init_msec_value(us->resolver_timeout, 30000);
+ ngx_conf_merge_msec_value(us->resolver_timeout,
+ clcf->resolver_timeout, 30000);

if (resolve
&& (us->resolver == NULL
diff --git a/src/stream/ngx_stream_upstream.c b/src/stream/ngx_stream_upstream.c
--- a/src/stream/ngx_stream_upstream.c
+++ b/src/stream/ngx_stream_upstream.c
@@ -22,6 +22,11 @@ static char *ngx_stream_upstream(ngx_con
void *dummy);
static char *ngx_stream_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+#if (NGX_STREAM_UPSTREAM_ZONE)
+static char *ngx_stream_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+#endif
+
static void *ngx_stream_upstream_create_main_conf(ngx_conf_t *cf);
static char *ngx_stream_upstream_init_main_conf(ngx_conf_t *cf, void *conf);

@@ -42,6 +47,24 @@ static ngx_command_t ngx_stream_upstrea
0,
NULL },

+#if (NGX_STREAM_UPSTREAM_ZONE)
+
+ { ngx_string("resolver"),
+ NGX_STREAM_UPS_CONF|NGX_CONF_1MORE,
+ ngx_stream_upstream_resolver,
+ NGX_STREAM_SRV_CONF_OFFSET,
+ 0,
+ NULL },
+
+ { ngx_string("resolver_timeout"),
+ NGX_STREAM_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_msec_slot,
+ NGX_STREAM_SRV_CONF_OFFSET,
+ offsetof(ngx_stream_upstream_srv_conf_t, resolver_timeout),
+ NULL },
+
+#endif
+
ngx_null_command
};

@@ -665,6 +688,32 @@ not_supported:
}


+#if (NGX_STREAM_UPSTREAM_ZONE)
+
+static char *
+ngx_stream_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_stream_upstream_srv_conf_t *uscf = conf;
+
+ ngx_str_t *value;
+
+ if (uscf->resolver) {
+ return "is duplicate";
+ }
+
+ value = cf->args->elts;
+
+ uscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
+ if (uscf->resolver == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ return NGX_CONF_OK;
+}
+
+#endif
+
+
ngx_stream_upstream_srv_conf_t *
ngx_stream_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
{
@@ -743,6 +792,9 @@ ngx_stream_upstream_add(ngx_conf_t *cf,
uscf->line = cf->conf_file->line;
uscf->port = u->port;
uscf->no_port = u->no_port;
+#if (NGX_STREAM_UPSTREAM_ZONE)
+ uscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
+#endif

if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {
uscf->servers = ngx_array_create(cf->pool, 1,
diff --git a/src/stream/ngx_stream_upstream_round_robin.c b/src/stream/ngx_stream_upstream_round_robin.c
--- a/src/stream/ngx_stream_upstream_round_robin.c
+++ b/src/stream/ngx_stream_upstream_round_robin.c
@@ -111,15 +111,15 @@ ngx_stream_upstream_init_round_robin(ngx
cscf = ngx_stream_conf_get_module_srv_conf(cf,
ngx_stream_core_module);

- us->resolver = cscf->resolver;
- us->resolver_timeout = cscf->resolver_timeout;
+ if (us->resolver == NULL) {
+ us->resolver = cscf->resolver;
+ }

/*
- * Without "resolver_timeout" in stream{}, the value is unset.
- * Even if we set it in ngx_stream_core_merge_srv_conf(), it's
- * still dependent on the module order and unreliable.
+ * Without "resolver_timeout" in stream{} the merged value is unset.
*/
- ngx_conf_init_msec_value(us->resolver_timeout, 30000);
+ ngx_conf_merge_msec_value(us->resolver_timeout,
+ cscf->resolver_timeout, 30000);

if (resolve
&& (us->resolver == NULL
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 0 of 6] Upstream: re-resolvable servers.

Aleksei Bavshin 542 January 31, 2023 08:40PM

[PATCH 1 of 6] Upstream: re-resolvable servers

Aleksei Bavshin 185 January 31, 2023 08:40PM

[PATCH 2 of 6] Stream: re-resolvable servers

Aleksei Bavshin 140 January 31, 2023 08:40PM

[PATCH 3 of 6] Upstream: construct upstream peers from DNS SRV records

Aleksei Bavshin 159 January 31, 2023 08:40PM

[PATCH 4 of 6] Upstream: per-upstream resolver

Aleksei Bavshin 145 January 31, 2023 08:42PM

[PATCH 5 of 6] Upstream: allow any worker to resolve upstream servers

Aleksei Bavshin 138 January 31, 2023 08:42PM

Re: [PATCH 5 of 6] Upstream: allow any worker to resolve upstream servers

J Carter 175 February 05, 2023 10:02PM

Re: [PATCH 5 of 6] Upstream: allow any worker to resolve upstream servers

Aleksei Bavshin 118 February 09, 2023 11:46AM

Re: [PATCH 5 of 6] Upstream: allow any worker to resolve upstream servers

J Carter 149 February 09, 2023 07:06PM

[PATCH 6 of 6] Upstream: reschedule in-progress resolve tasks at worker exit

Aleksei Bavshin 125 January 31, 2023 08:42PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 316
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready