From 67597cf1f3e9e35de829e97104e668acf618920a Mon Sep 17 00:00:00 2001 From: zhangxiang05 Date: Wed, 5 Dec 2018 11:22:07 +0800 Subject: [PATCH] RandomRule policy modification --- .../src/main/java/com/netflix/loadbalancer/RandomRule.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java index debe21b6..d2235511 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java @@ -48,17 +48,18 @@ public Server choose(ILoadBalancer lb, Object key) { List upList = lb.getReachableServers(); List allList = lb.getAllServers(); + int upCount = upList.size(); int serverCount = allList.size(); - if (serverCount == 0) { + if (serverCount == 0 || upCount == 0) { /* - * No servers. End regardless of pass, because subsequent passes + * No servers or No servers available. End regardless of pass, because subsequent passes * only get more restrictive. */ return null; } int index = chooseRandomInt(serverCount); - server = upList.get(index); + server = allList.get(index); if (server == null) { /*