diff --git a/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java b/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java index 9a22daf2c13..48b65552274 100644 --- a/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java +++ b/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java @@ -183,17 +183,7 @@ public class BalancerCostAnalyzer final Iterable serverHolders ) { - MinMaxPriorityQueue> costsAndServers = computeCosts(proposalSegment, serverHolders); - if (costsAndServers.isEmpty()) { - return null; - } - - ServerHolder toServer = costsAndServers.pollFirst().rhs; - if (!toServer.isServingSegment(proposalSegment)) { - return toServer; - } - - return null; + return computeCosts(proposalSegment, serverHolders).rhs; } /** @@ -220,11 +210,12 @@ public class BalancerCostAnalyzer return null; } - private MinMaxPriorityQueue> computeCosts( + private Pair computeCosts( final DataSegment proposalSegment, final Iterable serverHolders ) { + Pair bestServer = Pair.of(Double.POSITIVE_INFINITY,null); MinMaxPriorityQueue> costsAndServers = MinMaxPriorityQueue.orderedBy( new Comparator>() { @@ -260,10 +251,12 @@ public class BalancerCostAnalyzer cost += computeJointSegmentCosts(proposalSegment, segment); } - costsAndServers.add(Pair.of(cost, server)); + if (cost