From bb31fa7b68642304317a751d9e06a3c117c024a3 Mon Sep 17 00:00:00 2001 From: Nelson Ray Date: Thu, 3 Jan 2013 10:48:05 -0800 Subject: [PATCH] update --- .../druid/master/BalancerCostAnalyzer.java | 34 +++++++++---------- .../druid/master/DruidMasterBalancer.java | 11 +++--- .../metamx/druid/master/rules/LoadRule.java | 3 ++ 3 files changed, 26 insertions(+), 22 deletions(-) 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 5bd25ed487a..9b0cd4b9c08 100644 --- a/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java +++ b/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java @@ -49,12 +49,12 @@ public class BalancerCostAnalyzer private List serverHolderList; private Random rand; - private float initialTotalCost; - private float totalCostChange; + private double initialTotalCost; + private double totalCostChange; public BalancerCostAnalyzer(){ rand = new Random(0); - totalCostChange = 0f; + totalCostChange = 0; } public void init(List serverHolderList){ @@ -62,16 +62,16 @@ public class BalancerCostAnalyzer this.serverHolderList = serverHolderList; } - public float getInitialTotalCost() { + public double getInitialTotalCost() { return initialTotalCost; } - public float getTotalCostChange() { + public double getTotalCostChange() { return totalCostChange; } - private float calculateInitialTotalCost(List serverHolderList){ - float cost = 0; + private double calculateInitialTotalCost(List serverHolderList){ + double cost = 0; for (ServerHolder server : serverHolderList) { DataSegment[] segments = server.getServer().getSegments().values().toArray(new DataSegment[]{}); for (int i = 0; i < segments.length; ++i) { @@ -83,8 +83,8 @@ public class BalancerCostAnalyzer return cost; } - public float computeJointSegmentCosts(DataSegment segment1, DataSegment segment2){ - float cost = 0f; + public double computeJointSegmentCosts(DataSegment segment1, DataSegment segment2){ + double cost = 0; Interval gap = segment1.getInterval().gap(segment2.getInterval()); // gap is null if the two segment intervals overlap or if they're adjacent @@ -106,7 +106,7 @@ public class BalancerCostAnalyzer Set movingSegments = Sets.newHashSet(); int counter = 0; - float currCost = 0f; + double currCost = 0; while (segmentHoldersToMove.size() < MAX_SEGMENTS_TO_MOVE && counter < 3 * MAX_SEGMENTS_TO_MOVE) { counter++; @@ -117,22 +117,22 @@ public class BalancerCostAnalyzer if (movingSegments.contains(proposalSegment)) continue; // Just need a regular priority queue for the min. element. - MinMaxPriorityQueue> pQueue = MinMaxPriorityQueue.orderedBy( - new Comparator>() + MinMaxPriorityQueue> pQueue = MinMaxPriorityQueue.orderedBy( + new Comparator>() { @Override public int compare( - Pair o, - Pair o1 + Pair o, + Pair o1 ) { - return Float.compare(o.lhs, o1.lhs); + return Double.compare(o.lhs, o1.lhs); } } ).create(); for (ServerHolder server : serverHolderList) { - float cost = 0f; + double cost = 0f; for (DataSegment segment : server.getServer().getSegments().values()) { cost += computeJointSegmentCosts(proposalSegment, segment); } @@ -159,7 +159,7 @@ public class BalancerCostAnalyzer pQueue.add(Pair.of(cost, server)); } - Pair minPair = pQueue.peekFirst(); + Pair minPair = pQueue.peekFirst(); if (!minPair.rhs.equals(fromServerHolder)) { movingSegments.add(proposalSegment); segmentHoldersToMove.add( diff --git a/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java b/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java index ba417f401e4..81c3b382bca 100644 --- a/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java +++ b/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java @@ -110,8 +110,8 @@ public class DruidMasterBalancer implements DruidMasterHelper continue; } - TreeSet serversByPercentUsed = Sets.newTreeSet(percentUsedComparator); - serversByPercentUsed.addAll(entry.getValue()); + //TreeSet serversByPercentUsed = Sets.newTreeSet(percentUsedComparator); + //serversByPercentUsed.addAll(entry.getValue()); List serverHolderList = new ArrayList(entry.getValue()); @@ -128,18 +128,19 @@ public class DruidMasterBalancer implements DruidMasterHelper analyzer.getTotalCostChange() ); - if (serversByPercentUsed.size() <= 1) { + if (serverHolderList.size() <= 1) { log.info( - "[%s]: No unique values found for highest and lowest percent used servers: nothing to balance", + "[%s]: One or fewer servers found. Cannot balance.", tier ); continue; } + /* ServerHolder highestPercentUsedServer = serversByPercentUsed.first(); ServerHolder lowestPercentUsedServer = serversByPercentUsed.last(); - /* + analyzer.init(highestPercentUsedServer, lowestPercentUsedServer); log.info( diff --git a/server/src/main/java/com/metamx/druid/master/rules/LoadRule.java b/server/src/main/java/com/metamx/druid/master/rules/LoadRule.java index 5bf232c9474..c0844641b5d 100644 --- a/server/src/main/java/com/metamx/druid/master/rules/LoadRule.java +++ b/server/src/main/java/com/metamx/druid/master/rules/LoadRule.java @@ -30,6 +30,7 @@ import com.metamx.druid.master.MasterStats; import com.metamx.druid.master.ServerHolder; import com.metamx.emitter.EmittingLogger; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -70,6 +71,8 @@ public abstract class LoadRule implements Rule { MasterStats stats = new MasterStats(); + List serverHolderList = new ArrayList(serverQueue); + List assignedServers = Lists.newArrayList(); while (totalReplicants < expectedReplicants) { ServerHolder holder = serverQueue.pollFirst();