Search in sources :

Example 1 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class MarkAsUnusedOvershadowedSegments method run.

@Override
public DruidCoordinatorRuntimeParams run(DruidCoordinatorRuntimeParams params) {
    // Mark as unused overshadowed segments only if we've had enough time to make sure we aren't flapping with old data.
    if (!params.coordinatorIsLeadingEnoughTimeToMarkAsUnusedOvershadowedSegements()) {
        return params;
    }
    CoordinatorStats stats = new CoordinatorStats();
    DruidCluster cluster = params.getDruidCluster();
    Map<String, VersionedIntervalTimeline<String, DataSegment>> timelines = new HashMap<>();
    for (SortedSet<ServerHolder> serverHolders : cluster.getSortedHistoricalsByTier()) {
        for (ServerHolder serverHolder : serverHolders) {
            addSegmentsFromServer(serverHolder, timelines);
        }
    }
    for (ServerHolder serverHolder : cluster.getBrokers()) {
        addSegmentsFromServer(serverHolder, timelines);
    }
    // Mark all segments as unused in db that are overshadowed by served segments
    for (DataSegment dataSegment : params.getUsedSegments()) {
        VersionedIntervalTimeline<String, DataSegment> timeline = timelines.get(dataSegment.getDataSource());
        if (timeline != null && timeline.isOvershadowed(dataSegment.getInterval(), dataSegment.getVersion(), dataSegment)) {
            coordinator.markSegmentAsUnused(dataSegment);
            stats.addToGlobalStat("overShadowedCount", 1);
        }
    }
    return params.buildFromExisting().withCoordinatorStats(stats).build();
}
Also used : CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) HashMap(java.util.HashMap) VersionedIntervalTimeline(org.apache.druid.timeline.VersionedIntervalTimeline) DruidCluster(org.apache.druid.server.coordinator.DruidCluster) DataSegment(org.apache.druid.timeline.DataSegment)

Example 2 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class BroadcastDistributionRule method assign.

private CoordinatorStats assign(final Set<ServerHolder> serverHolders, final DataSegment segment) {
    final CoordinatorStats stats = new CoordinatorStats();
    stats.addToGlobalStat(LoadRule.ASSIGNED_COUNT, 0);
    for (ServerHolder holder : serverHolders) {
        if (segment.getSize() > holder.getAvailableSize()) {
            log.makeAlert("Failed to broadcast segment for [%s]", segment.getDataSource()).addData("segmentId", segment.getId()).addData("segmentSize", segment.getSize()).addData("hostName", holder.getServer().getHost()).addData("availableSize", holder.getAvailableSize()).emit();
        } else {
            if (!holder.isLoadingSegment(segment)) {
                holder.getPeon().loadSegment(segment, null);
                stats.addToGlobalStat(LoadRule.ASSIGNED_COUNT, 1);
            }
        }
    }
    return stats;
}
Also used : CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder)

Example 3 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class BroadcastDistributionRule method drop.

private CoordinatorStats drop(final Set<ServerHolder> serverHolders, final DataSegment segment) {
    CoordinatorStats stats = new CoordinatorStats();
    for (ServerHolder holder : serverHolders) {
        holder.getPeon().dropSegment(segment, null);
        stats.addToGlobalStat(LoadRule.DROPPED_COUNT, 1);
    }
    return stats;
}
Also used : CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder)

Example 4 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class BroadcastDistributionRule method run.

@Override
public CoordinatorStats run(DruidCoordinator coordinator, DruidCoordinatorRuntimeParams params, DataSegment segment) {
    final Set<ServerHolder> dropServerHolders = new HashSet<>();
    // Find servers where we need to load the broadcast segments
    final Set<ServerHolder> loadServerHolders = params.getDruidCluster().getAllServers().stream().filter((serverHolder) -> {
        ServerType serverType = serverHolder.getServer().getType();
        if (!serverType.isSegmentBroadcastTarget()) {
            return false;
        }
        final boolean isServingSegment = serverHolder.isServingSegment(segment);
        if (serverHolder.isDecommissioning()) {
            if (isServingSegment && !serverHolder.isDroppingSegment(segment)) {
                dropServerHolders.add(serverHolder);
            }
            return false;
        }
        return !isServingSegment && !serverHolder.isLoadingSegment(segment);
    }).collect(Collectors.toSet());
    final CoordinatorStats stats = new CoordinatorStats();
    return stats.accumulate(assign(loadServerHolders, segment)).accumulate(drop(dropServerHolders, segment));
}
Also used : EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) DruidCoordinatorRuntimeParams(org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams) Set(java.util.Set) DruidCoordinator(org.apache.druid.server.coordinator.DruidCoordinator) CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) SegmentReplicantLookup(org.apache.druid.server.coordinator.SegmentReplicantLookup) Object2LongMap(it.unimi.dsi.fastutil.objects.Object2LongMap) Map(java.util.Map) ServerType(org.apache.druid.server.coordination.ServerType) DataSegment(org.apache.druid.timeline.DataSegment) DruidCluster(org.apache.druid.server.coordinator.DruidCluster) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) Object2LongOpenHashMap(it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap) ServerType(org.apache.druid.server.coordination.ServerType) CoordinatorStats(org.apache.druid.server.coordinator.CoordinatorStats) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) HashSet(java.util.HashSet)

Example 5 with ServerHolder

use of org.apache.druid.server.coordinator.ServerHolder in project druid by druid-io.

the class LoadRule method dropSegmentFromServers.

private static int dropSegmentFromServers(BalancerStrategy balancerStrategy, DataSegment segment, NavigableSet<ServerHolder> holders, int numToDrop) {
    final Iterator<ServerHolder> iterator = balancerStrategy.pickServersToDrop(segment, holders);
    while (numToDrop > 0) {
        if (!iterator.hasNext()) {
            break;
        }
        final ServerHolder holder = iterator.next();
        if (holder.isServingSegment(segment)) {
            log.info("Dropping segment [%s] on server [%s] in tier [%s]", segment.getId(), holder.getServer().getName(), holder.getServer().getTier());
            holder.getPeon().dropSegment(segment, null);
            numToDrop--;
        } else {
            log.warn("Server [%s] is no longer serving segment [%s], skipping drop.", holder.getServer().getName(), segment.getId());
        }
    }
    return numToDrop;
}
Also used : ServerHolder(org.apache.druid.server.coordinator.ServerHolder)

Aggregations

ServerHolder (org.apache.druid.server.coordinator.ServerHolder)32 CoordinatorStats (org.apache.druid.server.coordinator.CoordinatorStats)22 DataSegment (org.apache.druid.timeline.DataSegment)22 DruidCluster (org.apache.druid.server.coordinator.DruidCluster)18 Test (org.junit.Test)16 DruidServer (org.apache.druid.client.DruidServer)15 ImmutableDruidServer (org.apache.druid.client.ImmutableDruidServer)15 LoadQueuePeon (org.apache.druid.server.coordinator.LoadQueuePeon)15 DruidCoordinatorRuntimeParams (org.apache.druid.server.coordinator.DruidCoordinatorRuntimeParams)7 LoadQueuePeonTester (org.apache.druid.server.coordinator.LoadQueuePeonTester)5 HashMap (java.util.HashMap)4 Object2IntMap (it.unimi.dsi.fastutil.objects.Object2IntMap)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ServerType (org.apache.druid.server.coordination.ServerType)3 DruidCoordinator (org.apache.druid.server.coordinator.DruidCoordinator)3 SegmentId (org.apache.druid.timeline.SegmentId)3 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2