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 56563cb1521..50c53e6fde2 100644 --- a/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java +++ b/server/src/main/java/com/metamx/druid/master/BalancerCostAnalyzer.java @@ -141,7 +141,7 @@ public class BalancerCostAnalyzer } // The balancing application requires us to pick a proposal segment. - public BalancerSegmentHolder findNewSegmentHome(List serverHolders, int numSegments) + public BalancerSegmentHolder pickSegmentToMove(List serverHolders, int numSegments) { // We want to sample from each server w.p. numSegmentsOnServer / totalSegments ServerHolder fromServerHolder = sampleServer(serverHolders, numSegments); @@ -151,9 +151,7 @@ public class BalancerCostAnalyzer List segments = Lists.newArrayList(fromServerHolder.getServer().getSegments().values()); DataSegment proposalSegment = segments.get(rand.nextInt(segments.size())); - ServerHolder toServer = findNewSegmentHome(proposalSegment, serverHolders); - - return new BalancerSegmentHolder(fromServerHolder.getServer(), toServer.getServer(), proposalSegment); + return new BalancerSegmentHolder(fromServerHolder.getServer(), proposalSegment); } // The assignment application requires us to supply a proposal segment. diff --git a/server/src/main/java/com/metamx/druid/master/BalancerSegmentHolder.java b/server/src/main/java/com/metamx/druid/master/BalancerSegmentHolder.java index 5e7a9369fe4..7d62968e4b9 100644 --- a/server/src/main/java/com/metamx/druid/master/BalancerSegmentHolder.java +++ b/server/src/main/java/com/metamx/druid/master/BalancerSegmentHolder.java @@ -27,19 +27,16 @@ import com.metamx.druid.client.DruidServer; public class BalancerSegmentHolder { private final DruidServer fromServer; - private final DruidServer toServer; private final DataSegment segment; private volatile int lifetime = 15; public BalancerSegmentHolder( DruidServer fromServer, - DruidServer toServer, DataSegment segment ) { this.fromServer = fromServer; - this.toServer = toServer; this.segment = segment; } @@ -48,11 +45,6 @@ public class BalancerSegmentHolder return fromServer; } - public DruidServer getToServer() - { - return toServer; - } - public DataSegment getSegment() { return segment; 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 19cfd89274f..450da27165e 100644 --- a/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java +++ b/server/src/main/java/com/metamx/druid/master/DruidMasterBalancer.java @@ -120,10 +120,11 @@ public class DruidMasterBalancer implements DruidMasterHelper int iter = 0; while (iter < maxSegmentsToMove) { - BalancerSegmentHolder holder = analyzer.findNewSegmentHome(serverHolderList, numSegments); - if (!segmentsBeingMoved.contains(holder.getSegment())) { - moveSegment(holder, params); - segmentsBeingMoved.add(holder.getSegment()); + BalancerSegmentHolder segmentToMove = analyzer.pickSegmentToMove(serverHolderList, numSegments); + DruidServer toServer = analyzer.findNewSegmentHome(segmentToMove.getSegment(), serverHolderList).getServer(); + if (!segmentsBeingMoved.contains(segmentToMove.getSegment())) { + moveSegment(segmentToMove, toServer, params); + segmentsBeingMoved.add(segmentToMove.getSegment()); } iter++; } @@ -160,14 +161,14 @@ public class DruidMasterBalancer implements DruidMasterHelper private void moveSegment( final BalancerSegmentHolder segment, + final DruidServer toServer, final DruidMasterRuntimeParams params ) { - final DruidServer toServer = segment.getToServer(); - final String toServerName = segment.getToServer().getName(); + final String toServerName = toServer.getName(); final LoadQueuePeon toPeon = params.getLoadManagementPeons().get(toServerName); - final String fromServer = segment.getFromServer().getName(); + final String fromServerName = segment.getFromServer().getName(); final DataSegment segmentToMove = segment.getSegment(); final String segmentName = segmentToMove.getIdentifier(); @@ -177,12 +178,12 @@ public class DruidMasterBalancer implements DruidMasterHelper log.info( "Moving [%s] from [%s] to [%s]", segmentName, - fromServer, + fromServerName, toServerName ); try { master.moveSegment( - fromServer, + fromServerName, toServerName, segmentToMove.getIdentifier(), new LoadPeonCallback()