turned Iterable to ArrayList, fixed potential null pointer in reservoir sampling

This commit is contained in:
Dhruv Parthasarathy 2013-07-29 18:07:49 -07:00
parent ba4a9c28a7
commit ac0f0afdbf
6 changed files with 13 additions and 9 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ examples/rand/RealtimeNode.out
examples/twitter/RealtimeNode.out
*.log
*.DS_Store
server/src/main/resources/static/js/SlickGrid-master/

View File

@ -25,7 +25,7 @@ import java.util.List;
public interface BalancerStrategy
{
public ServerHolder findNewSegmentHome(final DataSegment proposalSegment,final Iterable<ServerHolder> serverHolders);
public ServerHolder findNewSegmentHome(final DataSegment proposalSegment,final List<ServerHolder> serverHolders);
public BalancerSegmentHolder pickSegmentToMove(final List<ServerHolder> serverHolders);
public void emitStats(String tier, MasterStats stats, List<ServerHolder> serverHolderList);
}

View File

@ -44,7 +44,7 @@ public class CostBalancerStrategy implements BalancerStrategy
@Override
public ServerHolder findNewSegmentHome(
DataSegment proposalSegment, Iterable<ServerHolder> serverHolders
DataSegment proposalSegment, List<ServerHolder> serverHolders
)
{
return computeCosts(proposalSegment, serverHolders).rhs;

View File

@ -115,7 +115,7 @@ public class DruidMasterBalancer implements DruidMasterHelper
for (int iter = 0; iter < maxSegmentsToMove; iter++) {
final BalancerSegmentHolder segmentToMove = strategy.pickSegmentToMove(serverHolderList);
if (params.getAvailableSegments().contains(segmentToMove.getSegment())) {
if (segmentToMove!=null && params.getAvailableSegments().contains(segmentToMove.getSegment())) {
final ServerHolder holder = strategy.findNewSegmentHome(segmentToMove.getSegment(), serverHolderList);
if (holder != null) {

View File

@ -19,10 +19,8 @@
package com.metamx.druid.master;
import com.google.common.collect.Lists;
import com.metamx.druid.client.DataSegment;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@ -32,11 +30,10 @@ public class RandomBalancerStrategy implements BalancerStrategy
@Override
public ServerHolder findNewSegmentHome(
DataSegment proposalSegment, Iterable<ServerHolder> serverHolders
DataSegment proposalSegment, List<ServerHolder> serverHolders
)
{
ArrayList<ServerHolder> serverHoldersList = Lists.newArrayList(serverHolders);
return serverHoldersList.get(new Random().nextInt(serverHoldersList.size()));
return serverHolders.get(new Random().nextInt(serverHolders.size()));
}
@Override

View File

@ -45,6 +45,12 @@ public class ReservoirSegmentSampler
numSoFar++;
}
}
return new BalancerSegmentHolder(fromServerHolder.getServer(), proposalSegment);
if (fromServerHolder!=null)
{
return new BalancerSegmentHolder(fromServerHolder.getServer(), proposalSegment);
}
else{
return null;
}
}
}