Search in sources :

Example 1 with ConnectTimeoutException

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(org.apache.commons.httpclient.URI) ExecutionException(java.util.concurrent.ExecutionException) ConnectTimeoutException(org.apache.commons.httpclient.ConnectTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionPoolTimeoutException(org.apache.commons.httpclient.ConnectionPoolTimeoutException) MultiGetRequest(com.linkedin.pinot.common.http.MultiGetRequest) ConnectionPoolTimeoutException(org.apache.commons.httpclient.ConnectionPoolTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) ArrayList(java.util.ArrayList) List(java.util.List) TableSizeInfo(com.linkedin.pinot.common.restlet.resources.TableSizeInfo) ExecutionException(java.util.concurrent.ExecutionException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ConnectTimeoutException(org.apache.commons.httpclient.ConnectTimeoutException)

Aggregations

MultiGetRequest (com.linkedin.pinot.common.http.MultiGetRequest)1 TableSizeInfo (com.linkedin.pinot.common.restlet.resources.TableSizeInfo)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConnectTimeoutException (org.apache.commons.httpclient.ConnectTimeoutException)1 ConnectionPoolTimeoutException (org.apache.commons.httpclient.ConnectionPoolTimeoutException)1 URI (org.apache.commons.httpclient.URI)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1