spacewander commented on a change in pull request #3217:
URL: https://github.com/apache/apisix/pull/3217#discussion_r554310844



##########
File path: apisix/balancer/roundrobin.lua
##########
@@ -16,16 +16,55 @@
 --
 
 local roundrobin  = require("resty.roundrobin")
+local core = require("apisix.core")
+local nkeys = core.table.nkeys
+
 
 local _M = {}
 
 
 function _M.new(up_nodes, upstream)
     local picker = roundrobin:new(up_nodes)
+    local nodes_count = nkeys(up_nodes)
     return {
         upstream = upstream,
-        get = function ()
-            return picker:find()
+        get = function (ctx)
+            if ctx.balancer_tried_servers and 
nkeys(ctx.balancer_tried_servers) == nodes_count then
+                return nil, "all upstream servers tried"
+            end
+
+            local server, err
+            while true do
+                server, err = picker:find()
+                if not server then
+                    return nil, err
+                end
+                if ctx.balancer_tried_servers then
+                    if not ctx.balancer_tried_servers[server] then
+                        break
+                    end
+                else
+                    break
+                end
+            end
+
+            return server
+        end,
+        after_balance = function (ctx, before_retry)

Review comment:
       There is another call in `apisix/init.lua`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to