diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-17 09:51:41 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-06-17 09:51:41 +0000 |
commit | baa81340f6cfbbd70480b3981a14fd3d087e13fe (patch) | |
tree | efa85925730f8d1f5c4e5ddc7a0753c26329aeea /documentapi/src | |
parent | 544ba2e3d8cc1e4f1766ead5651712401d98a86f (diff) |
Randomness is also needed when having only 2 nodes. If not it will always select [0] when pending is equal.
Diffstat (limited to 'documentapi/src')
-rw-r--r-- | documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/AdaptiveLoadBalancer.java | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/AdaptiveLoadBalancer.java b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/AdaptiveLoadBalancer.java index 6a68a6e122b..621064c178e 100644 --- a/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/AdaptiveLoadBalancer.java +++ b/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/AdaptiveLoadBalancer.java @@ -30,14 +30,10 @@ class AdaptiveLoadBalancer extends LoadBalancer { entry = choices.get(0); metrics = getNodeMetrics(entry); } else { - int candA = 0; - int candB = 1; - if (choices.size() > 2) { - candA = random.nextInt(choices.size()); + int candA = random.nextInt(choices.size()); + int candB = random.nextInt(choices.size()); + while (candB == candA) { candB = random.nextInt(choices.size()); - while (candB == candA) { - candB = random.nextInt(choices.size()); - } } entry = choices.get(candA); Mirror.Entry entryB = choices.get(candB); |