Using round robin for load balancing if hash key is empty

Maxim Dounin mdounin at mdounin.ru
Mon May 27 16:56:54 UTC 2019


Hello!

On Thu, May 23, 2019 at 04:49:32PM +0300, Roman Arutyunyan wrote:

[...]

> # HG changeset patch
> # User Niklas Keller <me at kelunik.com>
> # Date 1558614458 -10800
> #      Thu May 23 15:27:38 2019 +0300
> # Node ID 34dff919b948dd9652b24459e6a40c303058df09
> # Parent  234373adb2ce6023e69e527cbf2b60adf70b1130
> Upstream hash: fall back to round-robin if hash key is empty.
> 
> diff --git a/src/http/modules/ngx_http_upstream_hash_module.c b/src/http/modules/ngx_http_upstream_hash_module.c
> --- a/src/http/modules/ngx_http_upstream_hash_module.c
> +++ b/src/http/modules/ngx_http_upstream_hash_module.c
> @@ -178,7 +178,7 @@ ngx_http_upstream_get_hash_peer(ngx_peer
>  
>      ngx_http_upstream_rr_peers_rlock(hp->rrp.peers);
>  
> -    if (hp->tries > 20 || hp->rrp.peers->single) {
> +    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
>          ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
>          return hp->get_rr_peer(pc, &hp->rrp);
>      }
> @@ -509,7 +509,7 @@ ngx_http_upstream_get_chash_peer(ngx_pee
>  
>      ngx_http_upstream_rr_peers_wlock(hp->rrp.peers);
>  
> -    if (hp->tries > 20 || hp->rrp.peers->single) {
> +    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
>          ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
>          return hp->get_rr_peer(pc, &hp->rrp);
>      }
> diff --git a/src/stream/ngx_stream_upstream_hash_module.c b/src/stream/ngx_stream_upstream_hash_module.c
> --- a/src/stream/ngx_stream_upstream_hash_module.c
> +++ b/src/stream/ngx_stream_upstream_hash_module.c
> @@ -178,7 +178,7 @@ ngx_stream_upstream_get_hash_peer(ngx_pe
>  
>      ngx_stream_upstream_rr_peers_rlock(hp->rrp.peers);
>  
> -    if (hp->tries > 20 || hp->rrp.peers->single) {
> +    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
>          ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
>          return hp->get_rr_peer(pc, &hp->rrp);
>      }
> @@ -511,7 +511,7 @@ ngx_stream_upstream_get_chash_peer(ngx_p
>  
>      ngx_stream_upstream_rr_peers_wlock(hp->rrp.peers);
>  
> -    if (hp->tries > 20 || hp->rrp.peers->single) {
> +    if (hp->tries > 20 || hp->rrp.peers->single || hp->key.len == 0) {
>          ngx_stream_upstream_rr_peers_unlock(hp->rrp.peers);
>          return hp->get_rr_peer(pc, &hp->rrp);
>      }

For the record: looks good to me, please commit.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list