This is an automated email from the ASF dual-hosted git repository.
tokers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 500e42d fix: make set_more_retries() work when upstream_type is chash
(#2676)
500e42d is described below
commit 500e42d4ecfd8c1f1ea2d0a84b6773dae55cb5d3
Author: 阿姆斯壮 <[email protected]>
AuthorDate: Thu Jan 7 19:19:52 2021 +0800
fix: make set_more_retries() work when upstream_type is chash (#2676)
---
apisix/balancer/chash.lua | 9 +++++++--
t/admin/balancer.t | 1 +
t/node/healthcheck.t | 4 ++--
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/apisix/balancer/chash.lua b/apisix/balancer/chash.lua
index c8215a5..7c95526 100644
--- a/apisix/balancer/chash.lua
+++ b/apisix/balancer/chash.lua
@@ -68,8 +68,13 @@ function _M.new(up_nodes, upstream)
return {
upstream = upstream,
get = function (ctx)
- local chash_key = fetch_chash_hash_key(ctx, upstream)
- local id = picker:find(chash_key)
+ local id
+ if ctx.balancer_try_count > 1 and ctx.chash_last_server_index then
+ id, ctx.chash_last_server_index =
picker:next(ctx.chash_last_server_index)
+ else
+ local chash_key = fetch_chash_hash_key(ctx, upstream)
+ id, ctx.chash_last_server_index = picker:find(chash_key)
+ end
-- core.log.warn("chash id: ", id, " val: ", servers[id])
return servers[id]
end
diff --git a/t/admin/balancer.t b/t/admin/balancer.t
index 1afceda..b9a76c5 100644
--- a/t/admin/balancer.t
+++ b/t/admin/balancer.t
@@ -33,6 +33,7 @@ add_block_preprocessor(sub {
local balancer = require("apisix.balancer")
local res = {}
for i = 1, count or 12 do
+ ctx.balancer_try_count = 0
local server, err = balancer.pick_server(route, ctx)
if err then
ngx.say("failed: ", err)
diff --git a/t/node/healthcheck.t b/t/node/healthcheck.t
index 30e01ef..1056a53 100644
--- a/t/node/healthcheck.t
+++ b/t/node/healthcheck.t
@@ -485,10 +485,10 @@ res: 502 err: nil
qr{\[error\].*while connecting to upstream.*}
--- grep_error_log_out eval
qr{.*http://127.0.0.1:1960/server_port.*
-.*http://127.0.0.1:1960/server_port.*
.*http://127.0.0.1:1961/server_port.*
.*http://127.0.0.1:1961/server_port.*
-.*http://127.0.0.1:1961/server_port.*}
+.*http://127.0.0.1:1961/server_port.*
+.*http://127.0.0.1:1960/server_port.*}
--- timeout: 10