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:
Elvin Efendi 2018-05-28 16:08:53 -04:00
parent 04b7356190
commit b4e6513fc8
2 changed files with 10 additions and 5 deletions

View file

@ -49,6 +49,9 @@ local function sync_backend(backend)
return
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
ngx.log(ngx.INFO,
string.format("LB algorithm changed from %s to %s, resetting the instance", balancer.name, implementation.name))
@ -113,8 +116,9 @@ function _M.balance()
end
local host, port = balancer:balance()
if not host then
ngx.log(ngx.WARN, "no host returned, balancer: " .. balancer.name)
if not (host and port) then
ngx.log(ngx.WARN,
string.format("host or port is missing, balancer: %s, host: %s, port: %s", balancer.name, host, port))
return
end
@ -132,6 +136,10 @@ function _M.log()
return
end
if not balancer.after_balance then
return
end
balancer:after_balance()
end

View file

@ -19,7 +19,4 @@ function _M.sync(self, backend)
self.instance:reinit(nodes)
end
function _M.after_balance(_)
end
return _M