diff --git a/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java b/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java index ca958d7d2d3..068a317ce9b 100644 --- a/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java +++ b/server/src/main/java/com/metamx/druid/master/CostBalancerStrategy.java @@ -48,7 +48,7 @@ public class CostBalancerStrategy implements BalancerStrategy ) { ServerHolder holder= chooseBestServer(proposalSegment, serverHolders, false).rhs; - if (!holder.isServingSegment(proposalSegment)) + if (holder!=null && !holder.isServingSegment(proposalSegment)) { return holder; } diff --git a/server/src/main/java/com/metamx/druid/master/DruidMasterRuleRunner.java b/server/src/main/java/com/metamx/druid/master/DruidMasterRuleRunner.java index 2bd4870ff2c..04a3ce55da6 100644 --- a/server/src/main/java/com/metamx/druid/master/DruidMasterRuleRunner.java +++ b/server/src/main/java/com/metamx/druid/master/DruidMasterRuleRunner.java @@ -68,7 +68,6 @@ public class DruidMasterRuleRunner implements DruidMasterHelper DatabaseRuleManager databaseRuleManager = paramsWithReplicationManager.getDatabaseRuleManager(); for (DataSegment segment : paramsWithReplicationManager.getAvailableSegments()) { List rules = databaseRuleManager.getRulesWithDefault(segment.getDataSource()); - boolean foundMatchingRule = false; for (Rule rule : rules) { if (rule.appliesTo(segment, now)) { diff --git a/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTester.java b/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTester.java index 3b5865fb361..690fa991fd9 100644 --- a/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTester.java +++ b/server/src/test/java/com/metamx/druid/master/DruidMasterBalancerTester.java @@ -1,10 +1,14 @@ package com.metamx.druid.master; +import com.google.common.collect.Maps; import com.metamx.druid.client.DataSegment; import com.metamx.druid.client.DruidServer; +import java.util.Map; + public class DruidMasterBalancerTester extends DruidMasterBalancer { + private final Map serverMap = Maps.newHashMap(); public DruidMasterBalancerTester(DruidMaster master) { super(master); @@ -45,7 +49,16 @@ public class DruidMasterBalancerTester extends DruidMasterBalancer } }); - currentlyMovingSegments.get("normal").put(segmentName, segment); + if (serverMap.get(fromServerName)==null) + { + serverMap.put(fromServerName,segment.getFromServer().getSegments().size()); + } + if (serverMap.get(toServerName)==null) + { + serverMap.put(toServerName,0); + } + serverMap.put(fromServerName,serverMap.get(fromServerName)-1); + serverMap.put(toServerName, serverMap.get(toServerName)+1); } catch (Exception e) { log.info(e, String.format("[%s] : Moving exception", segmentName)); @@ -54,4 +67,25 @@ public class DruidMasterBalancerTester extends DruidMasterBalancer currentlyMovingSegments.get("normal").remove(segment); } } + + public Map getServerMap() + { + return this.serverMap; + } + + public boolean isBalanced(int min, int numServers) + { + if (serverMap.size()==numServers) + { + for (int numSegments: serverMap.values()) + { + if (numSegmentsanyObject(), EasyMock.anyObject() ); + EasyMock.expectLastCall().anyTimes(); EasyMock.replay(master); @@ -86,7 +86,7 @@ public class DruidMasterBalancerProfiler ); } - for (int i=0;i