Search in sources :

Example 6 with HttpUriBuilder

use of com.facebook.airlift.http.client.HttpUriBuilder in project presto by prestodb.

the class TaskInfoFetcher method sendNextRequest.

private synchronized void sendNextRequest() {
    TaskInfo taskInfo = getTaskInfo();
    TaskStatus taskStatus = taskInfo.getTaskStatus();
    if (!running) {
        return;
    }
    // we already have the final task info
    if (isDone(getTaskInfo())) {
        stop();
        return;
    }
    // if we have an outstanding request
    if (future != null && !future.isDone()) {
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<?> errorRateLimit = errorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::sendNextRequest, executor);
        return;
    }
    MetadataUpdates metadataUpdateRequests = taskInfo.getMetadataUpdates();
    if (!metadataUpdateRequests.getMetadataUpdates().isEmpty()) {
        scheduleMetadataUpdates(metadataUpdateRequests);
    }
    HttpUriBuilder httpUriBuilder = uriBuilderFrom(taskStatus.getSelf());
    URI uri = summarizeTaskInfo ? httpUriBuilder.addParameter("summarize").build() : httpUriBuilder.build();
    Request.Builder uriBuilder = setContentTypeHeaders(isBinaryTransportEnabled, prepareGet());
    if (taskInfoRefreshMaxWait.toMillis() != 0L) {
        uriBuilder.setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString()).setHeader(PRESTO_MAX_WAIT, taskInfoRefreshMaxWait.toString());
    }
    Request request = uriBuilder.setUri(uri).build();
    ResponseHandler responseHandler;
    if (isBinaryTransportEnabled) {
        responseHandler = createFullSmileResponseHandler((SmileCodec<TaskInfo>) taskInfoCodec);
    } else {
        responseHandler = createAdaptingJsonResponseHandler((JsonCodec<TaskInfo>) taskInfoCodec);
    }
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, responseHandler);
    currentRequestStartNanos.set(System.nanoTime());
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats.getHttpResponseStats(), REMOTE_TASK_ERROR), executor);
}
Also used : TaskInfo(com.facebook.presto.execution.TaskInfo) MetadataUpdates(com.facebook.presto.metadata.MetadataUpdates) SmileCodec(com.facebook.airlift.json.smile.SmileCodec) JsonCodec(com.facebook.airlift.json.JsonCodec) SimpleHttpResponseHandler(com.facebook.presto.server.SimpleHttpResponseHandler) FullSmileResponseHandler.createFullSmileResponseHandler(com.facebook.presto.server.smile.FullSmileResponseHandler.createFullSmileResponseHandler) ResponseHandler(com.facebook.airlift.http.client.ResponseHandler) AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler(com.facebook.presto.server.smile.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler) HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) Request(com.facebook.airlift.http.client.Request) TaskStatus(com.facebook.presto.execution.TaskStatus) URI(java.net.URI)

Aggregations

HttpUriBuilder (com.facebook.airlift.http.client.HttpUriBuilder)6 Request (com.facebook.airlift.http.client.Request)5 TaskUpdateRequest (com.facebook.presto.server.TaskUpdateRequest)4 TaskStatus (com.facebook.presto.execution.TaskStatus)3 SetThreadName (com.facebook.airlift.concurrent.SetThreadName)2 ResponseHandler (com.facebook.airlift.http.client.ResponseHandler)2 JsonCodec (com.facebook.airlift.json.JsonCodec)2 SmileCodec (com.facebook.airlift.json.smile.SmileCodec)2 SimpleHttpResponseHandler (com.facebook.presto.server.SimpleHttpResponseHandler)2 AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler (com.facebook.presto.server.smile.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler)2 FullSmileResponseHandler.createFullSmileResponseHandler (com.facebook.presto.server.smile.FullSmileResponseHandler.createFullSmileResponseHandler)2 StatusResponseHandler.createStatusResponseHandler (com.facebook.airlift.http.client.StatusResponseHandler.createStatusResponseHandler)1 TaskInfo (com.facebook.presto.execution.TaskInfo)1 TaskSource (com.facebook.presto.execution.TaskSource)1 TableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo)1 MetadataUpdates (com.facebook.presto.metadata.MetadataUpdates)1 BaseResponse (com.facebook.presto.server.smile.BaseResponse)1 PrestoException (com.facebook.presto.spi.PrestoException)1 URI (java.net.URI)1 OptionalInt (java.util.OptionalInt)1