@@ -205,6 +205,9 @@ static ngx_int_t ngx_http_upstream_init_polaris_peer(ngx_http_request_t *r,
205205 r->upstream ->peer .get = ngx_http_upstream_get_polaris_peer;
206206 r->upstream ->peer .free = ngx_http_upstream_free_polaris_peer;
207207
208+ if (dcf->max_tries != NGX_CONF_UNSET_UINT) {
209+ r->upstream ->peer .tries = dcf->max_tries ;
210+ }
208211 // control the retry times >= 2.
209212 if (r->upstream ->peer .tries < 2 ) {
210213 r->upstream ->peer .tries = 2 ;
@@ -340,6 +343,7 @@ static void *ngx_http_upstream_polaris_create_conf(ngx_conf_t *cf) {
340343 conf->polaris_metadata_route_enabled = false ;
341344 ngx_str_set (&conf->polaris_fail_status_list , " " );
342345 conf->polaris_fail_status_report_enabled = false ;
346+ conf->max_tries = NGX_CONF_UNSET_UINT;
343347
344348 return conf;
345349}
@@ -584,6 +588,20 @@ static char *ngx_http_upstream_polaris_set_handler(ngx_conf_t *cf, ngx_command_t
584588
585589 continue ;
586590 }
591+
592+ if (ngx_strncmp (value[i].data , " max_tries=" , 10 ) == 0 ) {
593+ ngx_str_t s = {value[i].len - 10 , &value[i].data [10 ]};
594+
595+ ngx_int_t max_tries = ngx_atoi (s.data , s.len );
596+ if (max_tries < 1 || max_tries > 256 ) {
597+ ngx_conf_log_error (NGX_LOG_ERR, cf, 0 ,
598+ " dcf->max_tries:%d invalid, only valid in (1-256)" ,
599+ max_tries);
600+ return const_cast <char *>(" invalid polaris max_tries" );
601+ }
602+ dcf->max_tries = max_tries;
603+ continue ;
604+ }
587605 }
588606
589607 dcf->enabled = true ;
@@ -645,10 +663,10 @@ static char *ngx_http_upstream_polaris_set_handler(ngx_conf_t *cf, ngx_command_t
645663 ngx_conf_log_error (
646664 NGX_LOG_NOTICE, cf, 0 ,
647665 " init service_namespace:%s, service_name:%s, timeout: %.2f, mode: %d, "
648- " key: %s, dr: %d, mr_mode: %d, fail_status: %s" ,
666+ " key: %s, dr: %d, mr_mode: %d, fail_status: %s, max_tries: %d " ,
649667 dcf->polaris_service_namespace .data , dcf->polaris_service_name .data , dcf->polaris_timeout ,
650668 dcf->polaris_lb_mode , dcf->polaris_lb_key .data , dcf->polaris_dynamic_route_enabled ,
651- dcf->metadata_route_failover_mode , dcf->polaris_fail_status_list .data );
669+ dcf->metadata_route_failover_mode , dcf->polaris_fail_status_list .data , dcf-> max_tries );
652670
653671 return NGX_CONF_OK;
654672}
0 commit comments