mirror of https://github.com/apache/druid.git
turned Iterable to ArrayList, fixed potential null pointer in reservoir sampling
This commit is contained in:
parent
ba4a9c28a7
commit
ac0f0afdbf
|
@ -14,3 +14,4 @@ examples/rand/RealtimeNode.out
|
|||
examples/twitter/RealtimeNode.out
|
||||
*.log
|
||||
*.DS_Store
|
||||
server/src/main/resources/static/js/SlickGrid-master/
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue