Search in sources :

Example 1 with BalancerSegmentHolder

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

the class DruidCoordinatorBalancer method run.

@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
    final CoordinatorStats stats = new CoordinatorStats();
    final BalancerStrategy strategy = params.getBalancerStrategy();
    final int maxSegmentsToMove = params.getCoordinatorDynamicConfig().getMaxSegmentsToMove();
    for (Map.Entry<String, MinMaxPriorityQueue<ServerHolder>> entry : params.getDruidCluster().getCluster().entrySet()) {
        String tier = entry.getKey();
        if (currentlyMovingSegments.get(tier) == null) {
            currentlyMovingSegments.put(tier, new ConcurrentHashMap<String, BalancerSegmentHolder>());
        }
        if (!currentlyMovingSegments.get(tier).isEmpty()) {
            reduceLifetimes(tier);
            log.info("[%s]: Still waiting on %,d segments to be moved", tier, currentlyMovingSegments.size());
            continue;
        }
        final List<ServerHolder> serverHolderList = Lists.newArrayList(entry.getValue());
        if (serverHolderList.size() <= 1) {
            log.info("[%s]: One or fewer servers found.  Cannot balance.", tier);
            continue;
        }
        int numSegments = 0;
        for (ServerHolder server : serverHolderList) {
            numSegments += server.getServer().getSegments().size();
        }
        if (numSegments == 0) {
            log.info("No segments found.  Cannot balance.");
            continue;
        }
        long unmoved = 0L;
        for (int iter = 0; iter < maxSegmentsToMove; iter++) {
            final BalancerSegmentHolder segmentToMove = strategy.pickSegmentToMove(serverHolderList);
            if (segmentToMove != null && params.getAvailableSegments().contains(segmentToMove.getSegment())) {
                final ServerHolder holder = strategy.findNewSegmentHomeBalancer(segmentToMove.getSegment(), serverHolderList);
                if (holder != null) {
                    moveSegment(segmentToMove, holder.getServer(), params);
                } else {
                    ++unmoved;
                }
            }
        }
        if (unmoved == maxSegmentsToMove) {
            // Cluster should be alive and constantly adjusting
            log.info("No good moves found in tier [%s]", tier);
        }
        stats.addToTieredStat("unmovedCount", tier, unmoved);
        stats.addToTieredStat("movedCount", tier, currentlyMovingSegments.get(tier).size());
        if (params.getCoordinatorDynamicConfig().emitBalancingStats()) {
            strategy.emitStats(tier, stats, serverHolderList);
        }
        log.info("[%s]: Segments Moved: [%d] Segments Let Alone: [%d]", tier, currentlyMovingSegments.get(tier).size(), unmoved);
    }
    return params.buildFromExisting().withCoordinatorStats(stats).build();
}
Also used : CoordinatorStats(io.druid.server.coordinator.CoordinatorStats) BalancerStrategy(io.druid.server.coordinator.BalancerStrategy) ServerHolder(io.druid.server.coordinator.ServerHolder) MinMaxPriorityQueue(com.google.common.collect.MinMaxPriorityQueue) BalancerSegmentHolder(io.druid.server.coordinator.BalancerSegmentHolder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Aggregations

MinMaxPriorityQueue (com.google.common.collect.MinMaxPriorityQueue)1 BalancerSegmentHolder (io.druid.server.coordinator.BalancerSegmentHolder)1 BalancerStrategy (io.druid.server.coordinator.BalancerStrategy)1 CoordinatorStats (io.druid.server.coordinator.CoordinatorStats)1 ServerHolder (io.druid.server.coordinator.ServerHolder)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1