Search in sources :

Example 6 with BalancerStrategy

use of io.druid.server.coordinator.BalancerStrategy in project druid by druid-io.

the class LoadRule method run.

@Override
public CoordinatorStats run(DruidCoordinator coordinator, DruidCoordinatorRuntimeParams params, DataSegment segment) {
    final CoordinatorStats stats = new CoordinatorStats();
    final Set<DataSegment> availableSegments = params.getAvailableSegments();
    final Map<String, Integer> loadStatus = Maps.newHashMap();
    int totalReplicantsInCluster = params.getSegmentReplicantLookup().getTotalReplicants(segment.getIdentifier());
    for (Map.Entry<String, Integer> entry : getTieredReplicants().entrySet()) {
        final String tier = entry.getKey();
        final int expectedReplicantsInTier = entry.getValue();
        final int totalReplicantsInTier = params.getSegmentReplicantLookup().getTotalReplicants(segment.getIdentifier(), tier);
        final int loadedReplicantsInTier = params.getSegmentReplicantLookup().getLoadedReplicants(segment.getIdentifier(), tier);
        final MinMaxPriorityQueue<ServerHolder> serverQueue = params.getDruidCluster().getServersByTier(tier);
        if (serverQueue == null) {
            log.makeAlert("Tier[%s] has no servers! Check your cluster configuration!", tier).emit();
            continue;
        }
        final List<ServerHolder> serverHolderList = Lists.newArrayList(serverQueue);
        final BalancerStrategy strategy = params.getBalancerStrategy();
        if (availableSegments.contains(segment)) {
            CoordinatorStats assignStats = assign(params.getReplicationManager(), tier, totalReplicantsInCluster, expectedReplicantsInTier, totalReplicantsInTier, strategy, serverHolderList, segment);
            stats.accumulate(assignStats);
            totalReplicantsInCluster += assignStats.getPerTierStats().get(assignedCount).get(tier).get();
        }
        loadStatus.put(tier, expectedReplicantsInTier - loadedReplicantsInTier);
    }
    // Remove over-replication
    stats.accumulate(drop(loadStatus, segment, params));
    return stats;
}
Also used : CoordinatorStats(io.druid.server.coordinator.CoordinatorStats) DataSegment(io.druid.timeline.DataSegment) BalancerStrategy(io.druid.server.coordinator.BalancerStrategy) ServerHolder(io.druid.server.coordinator.ServerHolder) Map(java.util.Map)

Aggregations

BalancerStrategy (io.druid.server.coordinator.BalancerStrategy)6 CoordinatorStats (io.druid.server.coordinator.CoordinatorStats)6 ServerHolder (io.druid.server.coordinator.ServerHolder)6 Map (java.util.Map)6 DataSegment (io.druid.timeline.DataSegment)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)4 DruidServer (io.druid.client.DruidServer)4 CostBalancerStrategyFactory (io.druid.server.coordinator.CostBalancerStrategyFactory)4 DruidCluster (io.druid.server.coordinator.DruidCluster)4 DateTime (org.joda.time.DateTime)4 Interval (org.joda.time.Interval)4 Test (org.junit.Test)4 MinMaxPriorityQueue (com.google.common.collect.MinMaxPriorityQueue)1 BalancerSegmentHolder (io.druid.server.coordinator.BalancerSegmentHolder)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1