Search in sources :

Example 1 with Server

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

the class RendezvousHashAvaticaConnectionBalancer method pickServer.

@Override
public Server pickServer(Collection<Server> servers, String connectionId) {
    if (servers.isEmpty()) {
        return null;
    }
    Map<String, Server> serverMap = new HashMap<>();
    for (Server server : servers) {
        serverMap.put(server.getHost(), server);
    }
    String chosenServerId = hasher.chooseNode(serverMap.keySet(), StringUtils.toUtf8(connectionId));
    return serverMap.get(chosenServerId);
}
Also used : Server(org.apache.druid.client.selector.Server) HashMap(java.util.HashMap)

Example 2 with Server

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

the class AsyncQueryForwardingServlet method broadcastQueryCancelRequest.

/**
 * Issues async query cancellation requests to all Brokers (except the given
 * targetServer). Query cancellation on the targetServer is handled by the
 * proxy servlet.
 */
private void broadcastQueryCancelRequest(HttpServletRequest request, Server targetServer) {
    for (final Server server : hostFinder.getAllServers()) {
        if (server.getHost().equals(targetServer.getHost())) {
            continue;
        }
        // issue async requests
        Response.CompleteListener completeListener = result -> {
            if (result.isFailed()) {
                LOG.warn(result.getFailure(), "Failed to forward cancellation request to [%s]", server.getHost());
            }
        };
        Request broadcastReq = broadcastClient.newRequest(rewriteURI(request, server.getScheme(), server.getHost())).method(HttpMethod.DELETE).timeout(CANCELLATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        copyRequestHeaders(request, broadcastReq);
        broadcastReq.send(completeListener);
    }
    interruptedQueryCount.incrementAndGet();
}
Also used : Response(org.eclipse.jetty.client.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ProtobufTranslationImpl(org.apache.calcite.avatica.remote.ProtobufTranslationImpl) ServletException(javax.servlet.ServletException) Inject(com.google.inject.Inject) Smile(org.apache.druid.guice.annotations.Smile) GenericQueryMetricsFactory(org.apache.druid.query.GenericQueryMetricsFactory) ProtobufTranslation(org.apache.calcite.avatica.remote.ProtobufTranslation) Request(org.eclipse.jetty.client.api.Request) HttpClient(org.eclipse.jetty.client.HttpClient) Authenticator(org.apache.druid.server.security.Authenticator) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) QueryToolChestWarehouse(org.apache.druid.query.QueryToolChestWarehouse) AuthConfig(org.apache.druid.server.security.AuthConfig) IAE(org.apache.druid.java.util.common.IAE) Response(org.eclipse.jetty.client.api.Response) SmileMediaTypes(com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes) DateTimes(org.apache.druid.java.util.common.DateTimes) JacksonUtils(org.apache.druid.java.util.common.jackson.JacksonUtils) ImmutableMap(com.google.common.collect.ImmutableMap) RequestLogger(org.apache.druid.server.log.RequestLogger) UUID(java.util.UUID) Json(org.apache.druid.guice.annotations.Json) IOUtils(org.apache.commons.io.IOUtils) DruidHttpClientConfig(org.apache.druid.guice.http.DruidHttpClientConfig) QueryCountStatsProvider(org.apache.druid.server.metrics.QueryCountStatsProvider) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Server(org.apache.druid.client.selector.Server) QueryHostFinder(org.apache.druid.server.router.QueryHostFinder) DruidMetrics(org.apache.druid.query.DruidMetrics) Result(org.eclipse.jetty.client.api.Result) QueryMetrics(org.apache.druid.query.QueryMetrics) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpServletRequest(javax.servlet.http.HttpServletRequest) Query(org.apache.druid.query.Query) AsyncProxyServlet(org.eclipse.jetty.proxy.AsyncProxyServlet) Status(javax.ws.rs.core.Response.Status) SqlQuery(org.apache.druid.sql.http.SqlQuery) Properties(java.util.Properties) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) AuthenticatorMapper(org.apache.druid.server.security.AuthenticatorMapper) ServerConfig(org.apache.druid.server.initialization.ServerConfig) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Service(org.apache.calcite.avatica.remote.Service) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Provider(com.google.inject.Provider) HttpMethod(org.eclipse.jetty.http.HttpMethod) Router(org.apache.druid.server.router.Router) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Server(org.apache.druid.client.selector.Server) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest)

Example 3 with Server

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

the class QueryHostFinderTest method testFindServer.

@Test
public void testFindServer() {
    QueryHostFinder queryRunner = new QueryHostFinder(brokerSelector, new RendezvousHashAvaticaConnectionBalancer());
    Server server = queryRunner.findServer(new TimeBoundaryQuery(new TableDataSource("test"), new MultipleIntervalSegmentSpec(Collections.singletonList(Intervals.of("2011-08-31/2011-09-01"))), null, null, null));
    Assert.assertEquals("foo", server.getHost());
}
Also used : Server(org.apache.druid.client.selector.Server) TableDataSource(org.apache.druid.query.TableDataSource) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) TimeBoundaryQuery(org.apache.druid.query.timeboundary.TimeBoundaryQuery) Test(org.junit.Test)

Example 4 with Server

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

the class TieredBrokerHostSelectorTest method testBasicSelect2.

@Test
public void testBasicSelect2() {
    Pair<String, Server> p = brokerSelector.select(Druids.newTimeseriesQueryBuilder().dataSource("test").granularity("all").aggregators(Collections.singletonList(new CountAggregatorFactory("rows"))).intervals(Collections.singletonList(Intervals.of("2013-08-31/2013-09-01"))).build());
    Assert.assertEquals("hotBroker", p.lhs);
    Assert.assertEquals("hotHost:8080", p.rhs.getHost());
}
Also used : DruidServer(org.apache.druid.client.DruidServer) Server(org.apache.druid.client.selector.Server) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) Test(org.junit.Test)

Example 5 with Server

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

the class TieredBrokerHostSelectorTest method testBasicSelect.

@Test
public void testBasicSelect() {
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("test").granularity("all").aggregators(Collections.singletonList(new CountAggregatorFactory("rows"))).intervals(Collections.singletonList(Intervals.of("2011-08-31/2011-09-01"))).build();
    Pair<String, Server> p = brokerSelector.select(query);
    Assert.assertEquals("coldBroker", p.lhs);
    Assert.assertEquals("coldHost1:8080", p.rhs.getHost());
    p = brokerSelector.select(query);
    Assert.assertEquals("coldBroker", p.lhs);
    Assert.assertEquals("coldHost2:8080", p.rhs.getHost());
    p = brokerSelector.select(query);
    Assert.assertEquals("coldBroker", p.lhs);
    Assert.assertEquals("coldHost1:8080", p.rhs.getHost());
}
Also used : TimeseriesQuery(org.apache.druid.query.timeseries.TimeseriesQuery) CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) DruidServer(org.apache.druid.client.DruidServer) Server(org.apache.druid.client.selector.Server) Test(org.junit.Test)

Aggregations

Server (org.apache.druid.client.selector.Server)20 Test (org.junit.Test)10 URI (java.net.URI)5 IOException (java.io.IOException)3 Query (org.apache.druid.query.Query)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 Service (org.apache.calcite.avatica.remote.Service)2 DruidServer (org.apache.druid.client.DruidServer)2 QueryInterruptedException (org.apache.druid.query.QueryInterruptedException)2 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)2 SqlQuery (org.apache.druid.sql.http.SqlQuery)2 SmileMediaTypes (com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1