Skip to content

Commit

Permalink
fix: make set_more_retries() work when upstream_type is chash (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
kai08-cn authored Jan 7, 2021
1 parent 2996416 commit 500e42d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions apisix/balancer/chash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions t/admin/balancer.t
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions t/node/healthcheck.t
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 500e42d

Please # to comment.