Search in sources :

Example 11 with ServerSelector

use of org.apache.druid.client.selector.ServerSelector in project druid by druid-io.

the class BrokerServerView method serverRemovedSegment.

private void serverRemovedSegment(DruidServerMetadata server, DataSegment segment) {
    SegmentId segmentId = segment.getId();
    final ServerSelector selector;
    synchronized (lock) {
        log.debug("Removing segment[%s] from server[%s].", segmentId, server);
        // since the broker segments are not stored on the timeline, do not fire segmentRemoved event
        if (server.getType().equals(ServerType.BROKER)) {
            runTimelineCallbacks(callback -> callback.serverSegmentRemoved(server, segment));
            return;
        }
        selector = selectors.get(segmentId);
        if (selector == null) {
            log.warn("Told to remove non-existant segment[%s]", segmentId);
            return;
        }
        QueryableDruidServer queryableDruidServer = clients.get(server.getName());
        if (!selector.removeServer(queryableDruidServer)) {
            log.warn("Asked to disassociate non-existant association between server[%s] and segment[%s]", server, segmentId);
        } else {
            runTimelineCallbacks(callback -> callback.serverSegmentRemoved(server, segment));
        }
        if (selector.isEmpty()) {
            VersionedIntervalTimeline<String, ServerSelector> timeline = timelines.get(segment.getDataSource());
            selectors.remove(segmentId);
            final PartitionChunk<ServerSelector> removedPartition = timeline.remove(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(selector));
            if (removedPartition == null) {
                log.warn("Asked to remove timeline entry[interval: %s, version: %s] that doesn't exist", segment.getInterval(), segment.getVersion());
            } else {
                runTimelineCallbacks(callback -> callback.segmentRemoved(segment));
            }
        }
    }
}
Also used : ServerSelector(org.apache.druid.client.selector.ServerSelector) SegmentId(org.apache.druid.timeline.SegmentId) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer)

Example 12 with ServerSelector

use of org.apache.druid.client.selector.ServerSelector in project druid by druid-io.

the class ServerViewUtil method getTargetLocations.

public static List<LocatedSegmentDescriptor> getTargetLocations(TimelineServerView serverView, DataSource datasource, List<Interval> intervals, int numCandidates) {
    final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(datasource);
    final Optional<? extends TimelineLookup<String, ServerSelector>> maybeTimeline = serverView.getTimeline(analysis);
    if (!maybeTimeline.isPresent()) {
        return Collections.emptyList();
    }
    List<LocatedSegmentDescriptor> located = new ArrayList<>();
    for (Interval interval : intervals) {
        for (TimelineObjectHolder<String, ServerSelector> holder : maybeTimeline.get().lookup(interval)) {
            for (PartitionChunk<ServerSelector> chunk : holder.getObject()) {
                ServerSelector selector = chunk.getObject();
                final SegmentDescriptor descriptor = new SegmentDescriptor(holder.getInterval(), holder.getVersion(), chunk.getChunkNumber());
                long size = selector.getSegment().getSize();
                List<DruidServerMetadata> candidates = selector.getCandidates(numCandidates);
                located.add(new LocatedSegmentDescriptor(descriptor, size, candidates));
            }
        }
    }
    return located;
}
Also used : ArrayList(java.util.ArrayList) DataSourceAnalysis(org.apache.druid.query.planning.DataSourceAnalysis) DruidServerMetadata(org.apache.druid.server.coordination.DruidServerMetadata) ServerSelector(org.apache.druid.client.selector.ServerSelector) LocatedSegmentDescriptor(org.apache.druid.query.LocatedSegmentDescriptor) LocatedSegmentDescriptor(org.apache.druid.query.LocatedSegmentDescriptor) SegmentDescriptor(org.apache.druid.query.SegmentDescriptor) Interval(org.joda.time.Interval)

Example 13 with ServerSelector

use of org.apache.druid.client.selector.ServerSelector in project druid by druid-io.

the class CachingClusteredClientTest method makeMockSingleDimensionSelector.

private ServerSelector makeMockSingleDimensionSelector(DruidServer server, String dimension, String start, String end, int partitionNum) {
    final DataSegment segment = new DataSegment(SegmentId.dummy(DATA_SOURCE), null, null, null, new SingleDimensionShardSpec(dimension, start, end, partitionNum, SingleDimensionShardSpec.UNKNOWN_NUM_CORE_PARTITIONS), null, 9, 0L);
    ServerSelector selector = new ServerSelector(segment, new HighestPriorityTierSelectorStrategy(new RandomServerSelectorStrategy()));
    selector.addServerAndUpdateSegment(new QueryableDruidServer(server, null), segment);
    return selector;
}
Also used : ServerSelector(org.apache.druid.client.selector.ServerSelector) HighestPriorityTierSelectorStrategy(org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy) DataSegment(org.apache.druid.timeline.DataSegment) SingleDimensionShardSpec(org.apache.druid.timeline.partition.SingleDimensionShardSpec) RandomServerSelectorStrategy(org.apache.druid.client.selector.RandomServerSelectorStrategy) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer)

Example 14 with ServerSelector

use of org.apache.druid.client.selector.ServerSelector in project druid by druid-io.

the class BrokerServerViewTest method testMultipleTiers.

@Test
public void testMultipleTiers() throws Exception {
    segmentViewInitLatch = new CountDownLatch(1);
    segmentAddedLatch = new CountDownLatch(4);
    segmentRemovedLatch = new CountDownLatch(0);
    // Setup a Broker that watches only Tier 2
    final String tier1 = "tier1";
    final String tier2 = "tier2";
    setupViews(Sets.newHashSet(tier2), null, true);
    // Historical Tier 1 has segments 1 and 2, Tier 2 has segments 2 and 3
    final DruidServer server11 = setupHistoricalServer(tier1, "localhost:1", 1);
    final DruidServer server21 = setupHistoricalServer(tier2, "localhost:2", 1);
    final DataSegment segment1 = dataSegmentWithIntervalAndVersion("2020-01-01/P1D", "v1");
    announceSegmentForServer(server11, segment1, zkPathsConfig, jsonMapper);
    final DataSegment segment2 = dataSegmentWithIntervalAndVersion("2020-01-02/P1D", "v1");
    announceSegmentForServer(server11, segment2, zkPathsConfig, jsonMapper);
    announceSegmentForServer(server21, segment2, zkPathsConfig, jsonMapper);
    final DataSegment segment3 = dataSegmentWithIntervalAndVersion("2020-01-03/P1D", "v1");
    announceSegmentForServer(server21, segment3, zkPathsConfig, jsonMapper);
    // Wait for the segments to be added
    Assert.assertTrue(timing.forWaiting().awaitLatch(segmentViewInitLatch));
    Assert.assertTrue(timing.forWaiting().awaitLatch(segmentAddedLatch));
    // Get the timeline for the datasource
    TimelineLookup<String, ServerSelector> timeline = brokerServerView.getTimeline(DataSourceAnalysis.forDataSource(new TableDataSource(segment1.getDataSource()))).get();
    // Verify that the timeline has no entry for the interval of segment 1
    Assert.assertTrue(timeline.lookup(segment1.getInterval()).isEmpty());
    // Verify that there is one entry for the interval of segment 2
    List<TimelineObjectHolder<String, ServerSelector>> timelineHolders = timeline.lookup(segment2.getInterval());
    Assert.assertEquals(1, timelineHolders.size());
    TimelineObjectHolder<String, ServerSelector> timelineHolder = timelineHolders.get(0);
    Assert.assertEquals(segment2.getInterval(), timelineHolder.getInterval());
    Assert.assertEquals(segment2.getVersion(), timelineHolder.getVersion());
    PartitionHolder<ServerSelector> partitionHolder = timelineHolder.getObject();
    Assert.assertTrue(partitionHolder.isComplete());
    Assert.assertEquals(1, Iterables.size(partitionHolder));
    ServerSelector selector = (partitionHolder.iterator().next()).getObject();
    Assert.assertFalse(selector.isEmpty());
    Assert.assertEquals(segment2, selector.getSegment());
    // Verify that the ServerSelector always picks Tier 1
    for (int i = 0; i < 5; ++i) {
        Assert.assertEquals(server21, selector.pick(null).getServer());
    }
    Assert.assertEquals(Collections.singletonList(server21.getMetadata()), selector.getCandidates(2));
}
Also used : ServerSelector(org.apache.druid.client.selector.ServerSelector) TimelineObjectHolder(org.apache.druid.timeline.TimelineObjectHolder) TableDataSource(org.apache.druid.query.TableDataSource) CountDownLatch(java.util.concurrent.CountDownLatch) DataSegment(org.apache.druid.timeline.DataSegment) Test(org.junit.Test)

Example 15 with ServerSelector

use of org.apache.druid.client.selector.ServerSelector in project druid by druid-io.

the class BrokerServerViewTest method assertValues.

private void assertValues(List<Pair<Interval, Pair<String, Pair<DruidServer, DataSegment>>>> expected, List<TimelineObjectHolder> actual) {
    Assert.assertEquals(expected.size(), actual.size());
    for (int i = 0; i < expected.size(); ++i) {
        Pair<Interval, Pair<String, Pair<DruidServer, DataSegment>>> expectedPair = expected.get(i);
        TimelineObjectHolder<String, ServerSelector> actualTimelineObjectHolder = actual.get(i);
        Assert.assertEquals(expectedPair.lhs, actualTimelineObjectHolder.getInterval());
        Assert.assertEquals(expectedPair.rhs.lhs, actualTimelineObjectHolder.getVersion());
        PartitionHolder<ServerSelector> actualPartitionHolder = actualTimelineObjectHolder.getObject();
        Assert.assertTrue(actualPartitionHolder.isComplete());
        Assert.assertEquals(1, Iterables.size(actualPartitionHolder));
        ServerSelector selector = ((SingleElementPartitionChunk<ServerSelector>) actualPartitionHolder.iterator().next()).getObject();
        Assert.assertFalse(selector.isEmpty());
        Assert.assertEquals(expectedPair.rhs.rhs.lhs, selector.pick(null).getServer());
        Assert.assertEquals(expectedPair.rhs.rhs.rhs, selector.getSegment());
    }
}
Also used : ServerSelector(org.apache.druid.client.selector.ServerSelector) DataSegment(org.apache.druid.timeline.DataSegment) SingleElementPartitionChunk(org.apache.druid.timeline.partition.SingleElementPartitionChunk) Interval(org.joda.time.Interval) Pair(org.apache.druid.java.util.common.Pair)

Aggregations

ServerSelector (org.apache.druid.client.selector.ServerSelector)26 DataSegment (org.apache.druid.timeline.DataSegment)17 QueryableDruidServer (org.apache.druid.client.selector.QueryableDruidServer)16 HighestPriorityTierSelectorStrategy (org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy)11 Interval (org.joda.time.Interval)11 RandomServerSelectorStrategy (org.apache.druid.client.selector.RandomServerSelectorStrategy)10 Test (org.junit.Test)10 TableDataSource (org.apache.druid.query.TableDataSource)7 ResponseContext (org.apache.druid.query.context.ResponseContext)6 ArrayList (java.util.ArrayList)5 QueryRunner (org.apache.druid.query.QueryRunner)5 SegmentDescriptor (org.apache.druid.query.SegmentDescriptor)5 Map (java.util.Map)4 QueryPlus (org.apache.druid.query.QueryPlus)4 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 HashMap (java.util.HashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Druids (org.apache.druid.query.Druids)3 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)3