Search in sources :

Example 1 with LoadRule

use of io.druid.server.coordinator.rules.LoadRule in project druid by druid-io.

the class DruidCoordinator method getReplicationStatus.

public Map<String, CountingMap<String>> getReplicationStatus() {
    final Map<String, CountingMap<String>> retVal = Maps.newHashMap();
    if (segmentReplicantLookup == null) {
        return retVal;
    }
    final DateTime now = new DateTime();
    for (DataSegment segment : getAvailableDataSegments()) {
        List<Rule> rules = metadataRuleManager.getRulesWithDefault(segment.getDataSource());
        for (Rule rule : rules) {
            if (rule instanceof LoadRule && rule.appliesTo(segment, now)) {
                for (Map.Entry<String, Integer> entry : ((LoadRule) rule).getTieredReplicants().entrySet()) {
                    CountingMap<String> dataSourceMap = retVal.get(entry.getKey());
                    if (dataSourceMap == null) {
                        dataSourceMap = new CountingMap<>();
                        retVal.put(entry.getKey(), dataSourceMap);
                    }
                    int diff = Math.max(entry.getValue() - segmentReplicantLookup.getTotalReplicants(segment.getIdentifier(), entry.getKey()), 0);
                    dataSourceMap.add(segment.getDataSource(), diff);
                }
                break;
            }
        }
    }
    return retVal;
}
Also used : DataSegment(io.druid.timeline.DataSegment) DateTime(org.joda.time.DateTime) CountingMap(io.druid.collections.CountingMap) LoadRule(io.druid.server.coordinator.rules.LoadRule) LoadRule(io.druid.server.coordinator.rules.LoadRule) Rule(io.druid.server.coordinator.rules.Rule) Map(java.util.Map) CountingMap(io.druid.collections.CountingMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 2 with LoadRule

use of io.druid.server.coordinator.rules.LoadRule in project druid by druid-io.

the class TieredBrokerHostSelector method select.

public Pair<String, ServerDiscoverySelector> select(final Query<T> query) {
    synchronized (lock) {
        if (!ruleManager.isStarted() || !started) {
            return getDefaultLookup();
        }
    }
    String brokerServiceName = null;
    for (TieredBrokerSelectorStrategy strategy : strategies) {
        final Optional<String> optionalName = strategy.getBrokerServiceName(tierConfig, query);
        if (optionalName.isPresent()) {
            brokerServiceName = optionalName.get();
            break;
        }
    }
    if (brokerServiceName == null) {
        // For Union Queries tier will be selected on the rules for first dataSource.
        List<Rule> rules = ruleManager.getRulesWithDefault(Iterables.getFirst(query.getDataSource().getNames(), null));
        // find the rule that can apply to the entire set of intervals
        DateTime now = new DateTime();
        int lastRulePosition = -1;
        LoadRule baseRule = null;
        for (Interval interval : query.getIntervals()) {
            int currRulePosition = 0;
            for (Rule rule : rules) {
                if (rule instanceof LoadRule && currRulePosition > lastRulePosition && rule.appliesTo(interval, now)) {
                    lastRulePosition = currRulePosition;
                    baseRule = (LoadRule) rule;
                    break;
                }
                currRulePosition++;
            }
        }
        if (baseRule == null) {
            return getDefaultLookup();
        }
        // in the baseRule, find the broker of highest priority
        for (Map.Entry<String, String> entry : tierConfig.getTierToBrokerMap().entrySet()) {
            if (baseRule.getTieredReplicants().containsKey(entry.getKey())) {
                brokerServiceName = entry.getValue();
                break;
            }
        }
    }
    if (brokerServiceName == null) {
        log.error("WTF?! No brokerServiceName found for datasource[%s], intervals[%s]. Using default[%s].", query.getDataSource(), query.getIntervals(), tierConfig.getDefaultBrokerServiceName());
        brokerServiceName = tierConfig.getDefaultBrokerServiceName();
    }
    ServerDiscoverySelector retVal = selectorMap.get(brokerServiceName);
    if (retVal == null) {
        log.error("WTF?! No selector found for brokerServiceName[%s]. Using default selector for[%s]", brokerServiceName, tierConfig.getDefaultBrokerServiceName());
        retVal = selectorMap.get(tierConfig.getDefaultBrokerServiceName());
    }
    return new Pair<>(brokerServiceName, retVal);
}
Also used : DateTime(org.joda.time.DateTime) ServerDiscoverySelector(io.druid.curator.discovery.ServerDiscoverySelector) LoadRule(io.druid.server.coordinator.rules.LoadRule) LoadRule(io.druid.server.coordinator.rules.LoadRule) Rule(io.druid.server.coordinator.rules.Rule) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) Interval(org.joda.time.Interval) Pair(io.druid.java.util.common.Pair)

Aggregations

LoadRule (io.druid.server.coordinator.rules.LoadRule)2 Rule (io.druid.server.coordinator.rules.Rule)2 Map (java.util.Map)2 DateTime (org.joda.time.DateTime)2 CountingMap (io.druid.collections.CountingMap)1 ServerDiscoverySelector (io.druid.curator.discovery.ServerDiscoverySelector)1 Pair (io.druid.java.util.common.Pair)1 DataSegment (io.druid.timeline.DataSegment)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Interval (org.joda.time.Interval)1