Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: ignored upstream nodes with a weight of 0. #536

Merged
merged 4 commits into from
Sep 18, 2019
Merged
Changes from 1 commit
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
17 changes: 13 additions & 4 deletions lua/apisix/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,27 @@ end


local function fetch_health_nodes(upstream, checker)
local up_nodes = core.table.new(0, #upstream.nodes)

if not checker then
for addr, weight in pairs(upstream.nodes) do
if weight > 0 then
up_nodes[addr] = weight
end
end
return upstream.nodes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here should return up_nodes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old implementation is enough, it support weight equal 0 case already. we do not need to patch here, I reverted those new code.

end

local host = upstream.checks and upstream.checks.host
local up_nodes = core.table.new(0, #upstream.nodes)
Copy link
Contributor

@chnliyong chnliyong Sep 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement likely duplicate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


for addr, weight in pairs(upstream.nodes) do
local ip, port = parse_addr(addr)
local ok = checker:get_target_status(ip, port, host)
if ok then
up_nodes[addr] = weight
if weight > 0 then
local ip, port = parse_addr(addr)
local ok = checker:get_target_status(ip, port, host)
if ok then
up_nodes[addr] = weight
end
end
end

Expand Down