use of org.apache.commons.httpclient.ConnectTimeoutException in project pinot by linkedin.
the class ServerTableSizeReader method getSizeDetailsFromServers.
public Map<String, List<SegmentSizeInfo>> getSizeDetailsFromServers(BiMap<String, String> serverEndPoints, String table, int timeoutMsec) {
List<String> serverUrls = new ArrayList<>(serverEndPoints.size());
BiMap<String, String> endpointsToServers = serverEndPoints.inverse();
for (String endpoint : endpointsToServers.keySet()) {
String tableSizeUri = "http://" + endpoint + "/table/" + table + "/size";
serverUrls.add(tableSizeUri);
}
MultiGetRequest mget = new MultiGetRequest(executor, connectionManager);
LOGGER.info("Reading segment sizes from servers for table: {}, timeoutMsec: {}", table, timeoutMsec);
CompletionService<GetMethod> completionService = mget.execute(serverUrls, timeoutMsec);
Map<String, List<SegmentSizeInfo>> serverSegmentSizes = new HashMap<>(serverEndPoints.size());
for (int i = 0; i < serverUrls.size(); i++) {
GetMethod getMethod = null;
try {
getMethod = completionService.take().get();
URI uri = getMethod.getURI();
String instance = endpointsToServers.get(uri.getHost() + ":" + uri.getPort());
if (getMethod.getStatusCode() >= 300) {
LOGGER.error("Server: {} returned error: {}", instance, getMethod.getStatusCode());
continue;
}
TableSizeInfo tableSizeInfo = new ObjectMapper().readValue(getMethod.getResponseBodyAsString(), TableSizeInfo.class);
serverSegmentSizes.put(instance, tableSizeInfo.segments);
} catch (InterruptedException e) {
LOGGER.warn("Interrupted exception while reading segment size for table: {}", table, e);
} catch (ExecutionException e) {
if (Throwables.getRootCause(e) instanceof SocketTimeoutException) {
LOGGER.warn("Server request to read table size was timed out for table: {}", table, e);
} else if (Throwables.getRootCause(e) instanceof ConnectTimeoutException) {
LOGGER.warn("Server request to read table size timed out waiting for connection. table: {}", table, e);
} else if (Throwables.getRootCause(e) instanceof ConnectionPoolTimeoutException) {
LOGGER.warn("Server request to read table size timed out on getting a connection from pool, table: {}", table, e);
} else {
LOGGER.warn("Execution exception while reading segment sizes for table: {}", table, e);
}
} catch (Exception e) {
LOGGER.warn("Error while reading segment sizes for table: {}", table);
} finally {
if (getMethod != null) {
getMethod.releaseConnection();
}
}
}
LOGGER.info("Finished reading segment sizes for table: {}", table);
return serverSegmentSizes;
}
Aggregations