Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,5 @@ upstream test_upstream {
| mr | N | Switch for metadata route| off |
| mr_mode | N | metadata route fail over mode | 0 |
| fail_report | N | Business-level fail report status code | "" |
| max_tries | N | Limits the number of tries for request to backend ip | 2 |

22 changes: 20 additions & 2 deletions nginx_polaris_module/ngx_http_upstream_polaris_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ static ngx_int_t ngx_http_upstream_init_polaris_peer(ngx_http_request_t *r,
r->upstream->peer.get = ngx_http_upstream_get_polaris_peer;
r->upstream->peer.free = ngx_http_upstream_free_polaris_peer;

if (dcf->max_tries != NGX_CONF_UNSET_UINT) {
r->upstream->peer.tries = dcf->max_tries;
}
// control the retry times >= 2.
if (r->upstream->peer.tries < 2) {
r->upstream->peer.tries = 2;
Expand Down Expand Up @@ -340,6 +343,7 @@ static void *ngx_http_upstream_polaris_create_conf(ngx_conf_t *cf) {
conf->polaris_metadata_route_enabled = false;
ngx_str_set(&conf->polaris_fail_status_list, "");
conf->polaris_fail_status_report_enabled = false;
conf->max_tries = NGX_CONF_UNSET_UINT;

return conf;
}
Expand Down Expand Up @@ -584,6 +588,20 @@ static char *ngx_http_upstream_polaris_set_handler(ngx_conf_t *cf, ngx_command_t

continue;
}

if (ngx_strncmp(value[i].data, "max_tries=", 10) == 0) {
ngx_str_t s = {value[i].len - 10, &value[i].data[10]};

ngx_int_t max_tries = ngx_atoi(s.data, s.len);
if (max_tries < 1 || max_tries > 256) {
ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
"dcf->max_tries:%d invalid, only valid in (1-256)",
max_tries);
return const_cast<char *>("invalid polaris max_tries");
}
dcf->max_tries = max_tries;
continue;
}
}

dcf->enabled = true;
Expand Down Expand Up @@ -645,10 +663,10 @@ static char *ngx_http_upstream_polaris_set_handler(ngx_conf_t *cf, ngx_command_t
ngx_conf_log_error(
NGX_LOG_NOTICE, cf, 0,
"init service_namespace:%s, service_name:%s, timeout: %.2f, mode: %d, "
"key: %s, dr: %d, mr_mode: %d, fail_status: %s",
"key: %s, dr: %d, mr_mode: %d, fail_status: %s, max_tries: %d",
dcf->polaris_service_namespace.data, dcf->polaris_service_name.data, dcf->polaris_timeout,
dcf->polaris_lb_mode, dcf->polaris_lb_key.data, dcf->polaris_dynamic_route_enabled,
dcf->metadata_route_failover_mode, dcf->polaris_fail_status_list.data);
dcf->metadata_route_failover_mode, dcf->polaris_fail_status_list.data, dcf->max_tries);

return NGX_CONF_OK;
}
2 changes: 2 additions & 0 deletions nginx_polaris_module/ngx_http_upstream_polaris_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ typedef struct {

ngx_http_upstream_init_pt original_init_upstream;
ngx_http_upstream_init_peer_pt original_init_peer;

ngx_uint_t max_tries;
} ngx_http_upstream_polaris_srv_conf_t;

/**
Expand Down