Search in sources :

Example 1 with ServiceUnavailableException

use of org.apache.druid.server.initialization.jetty.ServiceUnavailableException in project druid by druid-io.

the class DruidCoordinator method computeUnderReplicationCountsPerDataSourcePerTierForSegmentsInternal.

private Map<String, Object2LongMap<String>> computeUnderReplicationCountsPerDataSourcePerTierForSegmentsInternal(Iterable<DataSegment> dataSegments, boolean computeUsingClusterView) {
    final Map<String, Object2LongMap<String>> underReplicationCountsPerDataSourcePerTier = new HashMap<>();
    if (segmentReplicantLookup == null) {
        return underReplicationCountsPerDataSourcePerTier;
    }
    if (computeUsingClusterView && cluster == null) {
        throw new ServiceUnavailableException("coordinator hasn't populated information about cluster yet, try again later");
    }
    final DateTime now = DateTimes.nowUtc();
    for (final DataSegment segment : dataSegments) {
        final List<Rule> rules = metadataRuleManager.getRulesWithDefault(segment.getDataSource());
        for (final Rule rule : rules) {
            if (!rule.appliesTo(segment, now)) {
                // Rule did not match. Continue to the next Rule.
                continue;
            }
            if (!rule.canLoadSegments()) {
                // Hence, there is no need to update underReplicationCountsPerDataSourcePerTier map
                break;
            }
            if (computeUsingClusterView) {
                rule.updateUnderReplicatedWithClusterView(underReplicationCountsPerDataSourcePerTier, segmentReplicantLookup, cluster, segment);
            } else {
                rule.updateUnderReplicated(underReplicationCountsPerDataSourcePerTier, segmentReplicantLookup, segment);
            }
            // and match each segment with the first rule that applies. Each segment may only match a single rule.
            break;
        }
    }
    return underReplicationCountsPerDataSourcePerTier;
}
Also used : Object2LongMap(it.unimi.dsi.fastutil.objects.Object2LongMap) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ServiceUnavailableException(org.apache.druid.server.initialization.jetty.ServiceUnavailableException) Rule(org.apache.druid.server.coordinator.rules.Rule) LoadRule(org.apache.druid.server.coordinator.rules.LoadRule) DataSegment(org.apache.druid.timeline.DataSegment) DateTime(org.joda.time.DateTime)

Aggregations

Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LoadRule (org.apache.druid.server.coordinator.rules.LoadRule)1 Rule (org.apache.druid.server.coordinator.rules.Rule)1 ServiceUnavailableException (org.apache.druid.server.initialization.jetty.ServiceUnavailableException)1 DataSegment (org.apache.druid.timeline.DataSegment)1 DateTime (org.joda.time.DateTime)1