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 6e7ca4d20a4..799bccca581 100644 --- a/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java +++ b/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java @@ -188,19 +188,26 @@ public class BalancerCostAnalyzer * A DataSegment that we are proposing to move. * @param serverHolders * An iterable of ServerHolders for a particular tier. + * @param assign + * A boolean that is true if used in assignment else false in balancing. * @return A ServerHolder with the new home for a segment. */ - public ServerHolder findNewSegmentHome(final DataSegment proposalSegment, final Iterable serverHolders) + public ServerHolder findNewSegmentHome( + final DataSegment proposalSegment, + final Iterable serverHolders, + final boolean assign + ) { final long proposalSegmentSize = proposalSegment.getSize(); double minCost = Double.MAX_VALUE; ServerHolder toServer = null; for (ServerHolder server : serverHolders) { - /** Don't calculate cost if the server doesn't have enough space or is serving/loading the segment. */ + /** Don't calculate cost if the server doesn't have enough space or is loading the segment */ if (proposalSegmentSize > server.getAvailableSize() - || server.isServingSegment(proposalSegment) - || server.isLoadingSegment(proposalSegment)) { + || server.isLoadingSegment(proposalSegment) + /** or if the ask is assignment and the server is serving the segment. */ + || (assign && server.isServingSegment(proposalSegment)) ) { continue; } 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 809c1106a3c..3d66a21f9d7 100644 --- a/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java +++ b/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java @@ -111,7 +111,7 @@ public class DruidMasterBalancer implements DruidMasterHelper while (iter < maxSegmentsToMove) { iter++; final BalancerSegmentHolder segmentToMove = analyzer.pickSegmentToMove(serverHolderList, numSegments); - final ServerHolder holder = analyzer.findNewSegmentHome(segmentToMove.getSegment(), serverHolderList); + final ServerHolder holder = analyzer.findNewSegmentHome(segmentToMove.getSegment(), serverHolderList, false); if (holder == null) { continue; } @@ -128,11 +128,13 @@ public class DruidMasterBalancer implements DruidMasterHelper stats.addToTieredStat("initialCost", tier, (long) initialTotalCost); stats.addToTieredStat("normalization", tier, (long) normalization); + stats.addToTieredStat("normalizedInitialCostTimesOneThousand", tier, (long) (normalizedInitialCost * 1000)); stats.addToTieredStat("movedCount", tier, currentlyMovingSegments.get(tier).size()); log.info( - "Initial Total Cost: [%f], Initial Normalized Cost: [%f], Segments Moved: [%d]", + "Initial Total Cost: [%f], Normalization: [%f], Initial Normalized Cost: [%f], Segments Moved: [%d]", initialTotalCost, + normalization, normalizedInitialCost, currentlyMovingSegments.get(tier).size() ); 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 4cd6acae640..a59d9c795b5 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 @@ -91,7 +91,7 @@ public abstract class LoadRule implements Rule final MasterStats stats = new MasterStats(); while (totalReplicants < expectedReplicants) { - final ServerHolder holder = analyzer.findNewSegmentHome(segment, serverHolderList); + final ServerHolder holder = analyzer.findNewSegmentHome(segment, serverHolderList, true); if (holder == null) { log.warn(