make sure after_balance
is actually otional
add inline comment to make LB algorithm change detection logic clearer also require port in addition to host
This commit is contained in:
parent
04b7356190
commit
b4e6513fc8
2 changed files with 10 additions and 5 deletions
|
@ -49,6 +49,9 @@ local function sync_backend(backend)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- every implementation is the metatable of its instances (see .new(...) functions)
|
||||||
|
-- here we check if `balancer` is the instance of `implementation`
|
||||||
|
-- if it is not then we deduce LB algorithm has changed for the backend
|
||||||
if getmetatable(balancer) ~= implementation then
|
if getmetatable(balancer) ~= implementation then
|
||||||
ngx.log(ngx.INFO,
|
ngx.log(ngx.INFO,
|
||||||
string.format("LB algorithm changed from %s to %s, resetting the instance", balancer.name, implementation.name))
|
string.format("LB algorithm changed from %s to %s, resetting the instance", balancer.name, implementation.name))
|
||||||
|
@ -113,8 +116,9 @@ function _M.balance()
|
||||||
end
|
end
|
||||||
|
|
||||||
local host, port = balancer:balance()
|
local host, port = balancer:balance()
|
||||||
if not host then
|
if not (host and port) then
|
||||||
ngx.log(ngx.WARN, "no host returned, balancer: " .. balancer.name)
|
ngx.log(ngx.WARN,
|
||||||
|
string.format("host or port is missing, balancer: %s, host: %s, port: %s", balancer.name, host, port))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -132,6 +136,10 @@ function _M.log()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not balancer.after_balance then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
balancer:after_balance()
|
balancer:after_balance()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,4 @@ function _M.sync(self, backend)
|
||||||
self.instance:reinit(nodes)
|
self.instance:reinit(nodes)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.after_balance(_)
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
Loading…
Reference in a new issue