split pick segment logic into its own method

This commit is contained in:
Nelson Ray 2013-01-28 15:06:09 -08:00
parent 94b72e8878
commit 6438401a32
3 changed files with 12 additions and 21 deletions

View File

@ -141,7 +141,7 @@ public class BalancerCostAnalyzer
}
// The balancing application requires us to pick a proposal segment.
public BalancerSegmentHolder findNewSegmentHome(List<ServerHolder> serverHolders, int numSegments)
public BalancerSegmentHolder pickSegmentToMove(List<ServerHolder> 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<DataSegment> 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.

View File

@ -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;

View File

@ -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()