Search in sources :

Example 6 with QueryableDruidServer

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

the class CachingClusteredClientTest method populateTimeline.

private List<Map<DruidServer, ServerExpectations>> populateTimeline(List<Interval> queryIntervals, List<List<Iterable<Result<Object>>>> expectedResults, int numQueryIntervals, List<Object> mocks) {
    timeline = new VersionedIntervalTimeline<>(Ordering.natural());
    final List<Map<DruidServer, ServerExpectations>> serverExpectationList = new ArrayList<>();
    for (int k = 0; k < numQueryIntervals + 1; ++k) {
        final int numChunks = expectedResults.get(k).size();
        final TreeMap<DruidServer, ServerExpectations> serverExpectations = new TreeMap<>();
        serverExpectationList.add(serverExpectations);
        for (int j = 0; j < numChunks; ++j) {
            DruidServer lastServer = servers[random.nextInt(servers.length)];
            serverExpectations.computeIfAbsent(lastServer, server -> new ServerExpectations(server, makeMock(mocks, QueryRunner.class)));
            final ShardSpec shardSpec;
            if (numChunks == 1) {
                shardSpec = new SingleDimensionShardSpec("dimAll", null, null, 0, 1);
            } else {
                String start = null;
                String end = null;
                if (j > 0) {
                    start = String.valueOf(j);
                }
                if (j + 1 < numChunks) {
                    end = String.valueOf(j + 1);
                }
                shardSpec = new SingleDimensionShardSpec("dim" + k, start, end, j, numChunks);
            }
            DataSegment mockSegment = makeMock(mocks, DataSegment.class);
            ServerExpectation<Object> expectation = new ServerExpectation<>(// interval/chunk
            SegmentId.dummy(StringUtils.format("%s_%s", k, j)), queryIntervals.get(k), mockSegment, shardSpec, expectedResults.get(k).get(j));
            serverExpectations.get(lastServer).addExpectation(expectation);
            EasyMock.expect(mockSegment.getSize()).andReturn(0L).anyTimes();
            EasyMock.replay(mockSegment);
            ServerSelector selector = new ServerSelector(expectation.getSegment(), new HighestPriorityTierSelectorStrategy(new RandomServerSelectorStrategy()));
            selector.addServerAndUpdateSegment(new QueryableDruidServer(lastServer, null), selector.getSegment());
            EasyMock.reset(mockSegment);
            EasyMock.expect(mockSegment.getShardSpec()).andReturn(shardSpec).anyTimes();
            timeline.add(queryIntervals.get(k), String.valueOf(k), shardSpec.createChunk(selector));
        }
    }
    return serverExpectationList;
}
Also used : ArrayList(java.util.ArrayList) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) TreeMap(java.util.TreeMap) DataSegment(org.apache.druid.timeline.DataSegment) HashBasedNumberedShardSpec(org.apache.druid.timeline.partition.HashBasedNumberedShardSpec) NoneShardSpec(org.apache.druid.timeline.partition.NoneShardSpec) ShardSpec(org.apache.druid.timeline.partition.ShardSpec) SingleDimensionShardSpec(org.apache.druid.timeline.partition.SingleDimensionShardSpec) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer) ServerSelector(org.apache.druid.client.selector.ServerSelector) HighestPriorityTierSelectorStrategy(org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy) Map(java.util.Map) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) SingleDimensionShardSpec(org.apache.druid.timeline.partition.SingleDimensionShardSpec) RandomServerSelectorStrategy(org.apache.druid.client.selector.RandomServerSelectorStrategy)

Example 7 with QueryableDruidServer

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

the class BrokerServerView method serverAddedSegment.

private void serverAddedSegment(final DruidServerMetadata server, final DataSegment segment) {
    SegmentId segmentId = segment.getId();
    synchronized (lock) {
        // loop...
        if (!server.getType().equals(ServerType.BROKER)) {
            log.debug("Adding segment[%s] for server[%s]", segment, server);
            ServerSelector selector = selectors.get(segmentId);
            if (selector == null) {
                selector = new ServerSelector(segment, tierSelectorStrategy);
                VersionedIntervalTimeline<String, ServerSelector> timeline = timelines.get(segment.getDataSource());
                if (timeline == null) {
                    timeline = new VersionedIntervalTimeline<>(Ordering.natural());
                    timelines.put(segment.getDataSource(), timeline);
                }
                timeline.add(segment.getInterval(), segment.getVersion(), segment.getShardSpec().createChunk(selector));
                selectors.put(segmentId, selector);
            }
            QueryableDruidServer queryableDruidServer = clients.get(server.getName());
            if (queryableDruidServer == null) {
                queryableDruidServer = addServer(baseView.getInventoryValue(server.getName()));
            }
            selector.addServerAndUpdateSegment(queryableDruidServer, segment);
        }
        // run the callbacks, even if the segment came from a broker, lets downstream watchers decide what to do with it
        runTimelineCallbacks(callback -> callback.segmentAdded(server, segment));
    }
}
Also used : ServerSelector(org.apache.druid.client.selector.ServerSelector) SegmentId(org.apache.druid.timeline.SegmentId) QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer)

Example 8 with QueryableDruidServer

use of org.apache.druid.client.selector.QueryableDruidServer 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 9 with QueryableDruidServer

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

the class BrokerServerView method addServer.

private QueryableDruidServer addServer(DruidServer server) {
    QueryableDruidServer retVal = new QueryableDruidServer<>(server, makeDirectClient(server));
    QueryableDruidServer exists = clients.put(server.getName(), retVal);
    if (exists != null) {
        log.warn("QueryRunner for server[%s] already exists!? Well it's getting replaced", server);
    }
    return retVal;
}
Also used : QueryableDruidServer(org.apache.druid.client.selector.QueryableDruidServer)

Example 10 with QueryableDruidServer

use of org.apache.druid.client.selector.QueryableDruidServer 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)

Aggregations

QueryableDruidServer (org.apache.druid.client.selector.QueryableDruidServer)14 ServerSelector (org.apache.druid.client.selector.ServerSelector)12 HighestPriorityTierSelectorStrategy (org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy)8 DataSegment (org.apache.druid.timeline.DataSegment)8 RandomServerSelectorStrategy (org.apache.druid.client.selector.RandomServerSelectorStrategy)7 Test (org.junit.Test)5 ResponseContext (org.apache.druid.query.context.ResponseContext)4 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)4 Interval (org.joda.time.Interval)4 TimeBoundaryQuery (org.apache.druid.query.timeboundary.TimeBoundaryQuery)3 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)3 SegmentId (org.apache.druid.timeline.SegmentId)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MapCache (org.apache.druid.client.cache.MapCache)2 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)2 Sequence (org.apache.druid.java.util.common.guava.Sequence)2 Iterators (com.google.common.collect.Iterators)1 Ordering (com.google.common.collect.Ordering)1