Search in sources :

Example 6 with QueryableDruidServer

use of io.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 existed!? Well it's getting replaced", server);
    }
    return retVal;
}
Also used : QueryableDruidServer(io.druid.client.selector.QueryableDruidServer)

Example 7 with QueryableDruidServer

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

the class BrokerServerView method serverRemovedSegment.

private void serverRemovedSegment(DruidServerMetadata server, DataSegment segment) {
    String segmentId = segment.getIdentifier();
    final ServerSelector selector;
    synchronized (lock) {
        log.debug("Removing segment[%s] from server[%s].", segmentId, server);
        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);
        }
        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());
            }
        }
    }
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer)

Example 8 with QueryableDruidServer

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

the class BrokerServerView method serverAddedSegment.

private void serverAddedSegment(final DruidServerMetadata server, final DataSegment segment) {
    String segmentId = segment.getIdentifier();
    synchronized (lock) {
        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);
    }
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer)

Example 9 with QueryableDruidServer

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

the class BrokerServerView method clear.

public void clear() {
    synchronized (lock) {
        final Iterator<String> clientsIter = clients.keySet().iterator();
        while (clientsIter.hasNext()) {
            clientsIter.remove();
        }
        timelines.clear();
        final Iterator<ServerSelector> selectorsIter = selectors.values().iterator();
        while (selectorsIter.hasNext()) {
            final ServerSelector selector = selectorsIter.next();
            selectorsIter.remove();
            while (!selector.isEmpty()) {
                final QueryableDruidServer pick = selector.pick();
                selector.removeServer(pick);
            }
        }
    }
}
Also used : ServerSelector(io.druid.client.selector.ServerSelector) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer)

Example 10 with QueryableDruidServer

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

the class CachingClusteredClientTest method testCachingOverBulkLimitEnforcesLimit.

@Test
@SuppressWarnings("unchecked")
public void testCachingOverBulkLimitEnforcesLimit() throws Exception {
    final int limit = 10;
    final Interval interval = new Interval("2011-01-01/2011-01-02");
    final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource(DATA_SOURCE).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(interval))).filters(DIM_FILTER).granularity(GRANULARITY).aggregators(AGGS).postAggregators(POST_AGGS).context(CONTEXT).build();
    final Map<String, Object> context = new HashMap<>();
    final Cache cache = EasyMock.createStrictMock(Cache.class);
    final Capture<Iterable<Cache.NamedKey>> cacheKeyCapture = EasyMock.newCapture();
    EasyMock.expect(cache.getBulk(EasyMock.capture(cacheKeyCapture))).andReturn(ImmutableMap.<Cache.NamedKey, byte[]>of()).once();
    EasyMock.replay(cache);
    client = makeClient(MoreExecutors.sameThreadExecutor(), cache, limit);
    final DruidServer lastServer = servers[random.nextInt(servers.length)];
    final DataSegment dataSegment = EasyMock.createNiceMock(DataSegment.class);
    EasyMock.expect(dataSegment.getIdentifier()).andReturn(DATA_SOURCE).anyTimes();
    EasyMock.replay(dataSegment);
    final ServerSelector selector = new ServerSelector(dataSegment, new HighestPriorityTierSelectorStrategy(new RandomServerSelectorStrategy()));
    selector.addServerAndUpdateSegment(new QueryableDruidServer(lastServer, null), dataSegment);
    timeline.add(interval, "v", new SingleElementPartitionChunk<>(selector));
    client.run(query, context);
    Assert.assertTrue("Capture cache keys", cacheKeyCapture.hasCaptured());
    Assert.assertTrue("Cache key below limit", ImmutableList.copyOf(cacheKeyCapture.getValue()).size() <= limit);
    EasyMock.verify(cache);
    EasyMock.reset(cache);
    cacheKeyCapture.reset();
    EasyMock.expect(cache.getBulk(EasyMock.capture(cacheKeyCapture))).andReturn(ImmutableMap.<Cache.NamedKey, byte[]>of()).once();
    EasyMock.replay(cache);
    client = makeClient(MoreExecutors.sameThreadExecutor(), cache, 0);
    client.run(query, context);
    EasyMock.verify(cache);
    EasyMock.verify(dataSegment);
    Assert.assertTrue("Capture cache keys", cacheKeyCapture.hasCaptured());
    Assert.assertTrue("Cache Keys empty", ImmutableList.copyOf(cacheKeyCapture.getValue()).isEmpty());
}
Also used : TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) MergeIterable(io.druid.java.util.common.guava.MergeIterable) FunctionalIterable(io.druid.java.util.common.guava.FunctionalIterable) HashMap(java.util.HashMap) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) DataSegment(io.druid.timeline.DataSegment) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) ServerSelector(io.druid.client.selector.ServerSelector) HighestPriorityTierSelectorStrategy(io.druid.client.selector.HighestPriorityTierSelectorStrategy) RandomServerSelectorStrategy(io.druid.client.selector.RandomServerSelectorStrategy) Interval(org.joda.time.Interval) MapCache(io.druid.client.cache.MapCache) Cache(io.druid.client.cache.Cache) Test(org.junit.Test) GroupByQueryRunnerTest(io.druid.query.groupby.GroupByQueryRunnerTest)

Aggregations

QueryableDruidServer (io.druid.client.selector.QueryableDruidServer)12 ServerSelector (io.druid.client.selector.ServerSelector)11 HighestPriorityTierSelectorStrategy (io.druid.client.selector.HighestPriorityTierSelectorStrategy)7 DataSegment (io.druid.timeline.DataSegment)7 Interval (org.joda.time.Interval)6 Test (org.junit.Test)5 RandomServerSelectorStrategy (io.druid.client.selector.RandomServerSelectorStrategy)4 Sequence (io.druid.java.util.common.guava.Sequence)4 TimeBoundaryQuery (io.druid.query.timeboundary.TimeBoundaryQuery)4 List (java.util.List)4 HttpClient (com.metamx.http.client.HttpClient)3 Request (com.metamx.http.client.Request)3 HttpResponseHandler (com.metamx.http.client.response.HttpResponseHandler)3 ConnectionCountServerSelectorStrategy (io.druid.client.selector.ConnectionCountServerSelectorStrategy)3 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)3 ReflectionQueryToolChestWarehouse (io.druid.query.ReflectionQueryToolChestWarehouse)3 HashMap (java.util.HashMap)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Cache (io.druid.client.cache.Cache)2 QueryInterruptedException (io.druid.query.QueryInterruptedException)2