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);
}
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();
}
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());
}
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());
}
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());
}
Aggregations