Search in sources :

Example 11 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class StatementClient method close.

@Override
public void close() {
    if (!closed.getAndSet(true)) {
        URI uri = currentResults.get().getNextUri();
        if (uri != null) {
            Request request = prepareRequest(prepareDelete(), uri).build();
            httpClient.executeAsync(request, createStatusResponseHandler());
        }
    }
}
Also used : Request(io.airlift.http.client.Request) URI(java.net.URI)

Example 12 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class StatementClient method cancelLeafStage.

public boolean cancelLeafStage(Duration timeout) {
    checkState(!isClosed(), "client is closed");
    URI uri = current().getPartialCancelUri();
    if (uri == null) {
        return false;
    }
    Request request = prepareRequest(prepareDelete(), uri).build();
    HttpResponseFuture<StatusResponse> response = httpClient.executeAsync(request, createStatusResponseHandler());
    try {
        StatusResponse status = response.get(timeout.toMillis(), MILLISECONDS);
        return familyForStatusCode(status.getStatusCode()) == Family.SUCCESSFUL;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw Throwables.propagate(e);
    } catch (ExecutionException e) {
        throw Throwables.propagate(e.getCause());
    } catch (TimeoutException e) {
        return false;
    }
}
Also used : Request(io.airlift.http.client.Request) StatusResponse(io.airlift.http.client.StatusResponseHandler.StatusResponse) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) TimeoutException(java.util.concurrent.TimeoutException)

Example 13 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class ContinuousTaskStatusFetcher method scheduleNextRequest.

private synchronized void scheduleNextRequest() {
    // stopped or done?
    TaskStatus taskStatus = getTaskStatus();
    if (!running || taskStatus.getState().isDone()) {
        return;
    }
    // outstanding request?
    if (future != null && !future.isDone()) {
        // this should never happen
        log.error("Can not reschedule update because an update is already running");
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<?> errorRateLimit = errorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::scheduleNextRequest, executor);
        return;
    }
    Request request = prepareGet().setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("status").build()).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString()).setHeader(PRESTO_MAX_WAIT, refreshMaxWait.toString()).build();
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskStatusCodec));
    currentRequestStartNanos.set(System.nanoTime());
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
}
Also used : Request(io.airlift.http.client.Request) TaskStatus(com.facebook.presto.execution.TaskStatus)

Example 14 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class HttpRemoteTask method abort.

private synchronized void abort(TaskStatus status) {
    checkState(status.getState().isDone(), "cannot abort task with an incomplete status");
    try (SetThreadName ignored = new SetThreadName("HttpRemoteTask-%s", taskId)) {
        taskStatusFetcher.updateTaskStatus(status);
        // send abort to task
        HttpUriBuilder uriBuilder = getHttpUriBuilder(getTaskStatus());
        Request request = prepareDelete().setUri(uriBuilder.build()).build();
        scheduleAsyncCleanupRequest(new Backoff(MAX_CLEANUP_RETRY_TIME, MAX_CLEANUP_RETRY_TIME), request, "abort");
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) Request(io.airlift.http.client.Request) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest)

Example 15 with Request

use of io.airlift.http.client.Request in project presto by prestodb.

the class HttpRemoteTask method cleanUpTask.

private synchronized void cleanUpTask() {
    checkState(getTaskStatus().getState().isDone(), "attempt to clean up a task that is not done yet");
    // clear pending splits to free memory
    pendingSplits.clear();
    pendingSourceSplitCount = 0;
    partitionedSplitCountTracker.setPartitionedSplitCount(getPartitionedSplitCount());
    splitQueueHasSpace = true;
    whenSplitQueueHasSpace.complete(null, executor);
    // cancel pending request
    if (currentRequest != null) {
        currentRequest.cancel(true);
        currentRequest = null;
        currentRequestStartNanos = 0;
    }
    taskStatusFetcher.stop();
    // The remote task is likely to get a delete from the PageBufferClient first.
    // We send an additional delete anyway to get the final TaskInfo
    HttpUriBuilder uriBuilder = getHttpUriBuilder(getTaskStatus());
    Request request = prepareDelete().setUri(uriBuilder.build()).build();
    scheduleAsyncCleanupRequest(new Backoff(MAX_CLEANUP_RETRY_TIME, MAX_CLEANUP_RETRY_TIME), request, "cleanup");
}
Also used : HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) Request(io.airlift.http.client.Request) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest)

Aggregations

Request (io.airlift.http.client.Request)20 URI (java.net.URI)8 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)5 Test (org.testng.annotations.Test)5 QueryResults (com.facebook.presto.client.QueryResults)4 TaskStatus (com.facebook.presto.execution.TaskStatus)4 TaskUpdateRequest (com.facebook.presto.server.TaskUpdateRequest)4 ImmutableList (com.google.common.collect.ImmutableList)3 JsonResponse (io.airlift.http.client.FullJsonResponseHandler.JsonResponse)3 Duration (io.airlift.units.Duration)3 List (java.util.List)3 SetThreadName (io.airlift.concurrent.SetThreadName)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 PRESTO_PAGES (com.facebook.presto.PrestoMediaTypes.PRESTO_PAGES)1 TaskSource (com.facebook.presto.TaskSource)1 QueryError (com.facebook.presto.client.QueryError)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 PagesSerde (com.facebook.presto.execution.buffer.PagesSerde)1 SerializedPage (com.facebook.presto.execution.buffer.SerializedPage)1