Search in sources :

Example 1 with HttpUriBuilder

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

the class HttpRemoteTask method sendUpdate.

private synchronized void sendUpdate() {
    TaskStatus taskStatus = getTaskStatus();
    // don't update if the task hasn't been started yet or if it is already finished
    if (!started.get() || !needsUpdate.get() || taskStatus.getState().isDone()) {
        return;
    }
    // if there is a request already running, wait for it to complete
    if (this.currentRequest != null && !this.currentRequest.isDone()) {
        return;
    }
    // if throttled due to error, asynchronously wait for timeout and try again
    ListenableFuture<?> errorRateLimit = updateErrorTracker.acquireRequestPermit();
    if (!errorRateLimit.isDone()) {
        errorRateLimit.addListener(this::sendUpdate, executor);
        return;
    }
    List<TaskSource> sources = getSources();
    Optional<byte[]> fragment = sendPlan.get() ? Optional.of(planFragment.toBytes(planFragmentCodec)) : Optional.empty();
    Optional<TableWriteInfo> writeInfo = sendPlan.get() ? Optional.of(tableWriteInfo) : Optional.empty();
    TaskUpdateRequest updateRequest = new TaskUpdateRequest(session.toSessionRepresentation(), session.getIdentity().getExtraCredentials(), fragment, sources, outputBuffers.get(), writeInfo);
    byte[] taskUpdateRequestJson = taskUpdateRequestCodec.toBytes(updateRequest);
    taskUpdateRequestSize.add(taskUpdateRequestJson.length);
    if (taskUpdateRequestJson.length > maxTaskUpdateSizeInBytes) {
        failTask(new PrestoException(EXCEEDED_TASK_UPDATE_SIZE_LIMIT, format("TaskUpdate size of %d Bytes has exceeded the limit of %d Bytes", taskUpdateRequestJson.length, maxTaskUpdateSizeInBytes)));
    }
    if (fragment.isPresent()) {
        stats.updateWithPlanSize(taskUpdateRequestJson.length);
    } else {
        if (ThreadLocalRandom.current().nextDouble() < UPDATE_WITHOUT_PLAN_STATS_SAMPLE_RATE) {
            // This is to keep track of the task update size even when the plan fragment is NOT present
            stats.updateWithoutPlanSize(taskUpdateRequestJson.length);
        }
    }
    HttpUriBuilder uriBuilder = getHttpUriBuilder(taskStatus);
    Request request = setContentTypeHeaders(binaryTransportEnabled, preparePost()).setUri(uriBuilder.build()).setBodyGenerator(createStaticBodyGenerator(taskUpdateRequestJson)).build();
    ResponseHandler responseHandler;
    if (binaryTransportEnabled) {
        responseHandler = createFullSmileResponseHandler((SmileCodec<TaskInfo>) taskInfoCodec);
    } else {
        responseHandler = createAdaptingJsonResponseHandler((JsonCodec<TaskInfo>) taskInfoCodec);
    }
    updateErrorTracker.startRequest();
    ListenableFuture<BaseResponse<TaskInfo>> future = httpClient.executeAsync(request, responseHandler);
    currentRequest = future;
    currentRequestStartNanos = System.nanoTime();
    // The needsUpdate flag needs to be set to false BEFORE adding the Future callback since callback might change the flag value
    // and does so without grabbing the instance lock.
    needsUpdate.set(false);
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(new UpdateResponseHandler(sources), request.getUri(), stats.getHttpResponseStats(), REMOTE_TASK_ERROR), executor);
}
Also used : SmileCodec(com.facebook.airlift.json.smile.SmileCodec) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) SimpleHttpResponseHandler(com.facebook.presto.server.SimpleHttpResponseHandler) StatusResponseHandler.createStatusResponseHandler(com.facebook.airlift.http.client.StatusResponseHandler.createStatusResponseHandler) 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) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) Request(com.facebook.airlift.http.client.Request) PrestoException(com.facebook.presto.spi.PrestoException) TaskStatus(com.facebook.presto.execution.TaskStatus) BaseResponse(com.facebook.presto.server.smile.BaseResponse) JsonCodec(com.facebook.airlift.json.JsonCodec) HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) TaskSource(com.facebook.presto.execution.TaskSource)

Example 2 with HttpUriBuilder

use of com.facebook.airlift.http.client.HttpUriBuilder 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 = setContentTypeHeaders(binaryTransportEnabled, prepareDelete()).setUri(uriBuilder.build()).build();
        scheduleAsyncCleanupRequest(createCleanupBackoff(), request, "abort");
    }
}
Also used : SetThreadName(com.facebook.airlift.concurrent.SetThreadName) HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) Request(com.facebook.airlift.http.client.Request)

Example 3 with HttpUriBuilder

use of com.facebook.airlift.http.client.HttpUriBuilder 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;
    pendingSourceSplitsWeight = 0;
    updateTaskStats();
    splitQueueHasSpace = true;
    whenSplitQueueHasSpace.complete(null, executor);
    // cancel pending request
    if (currentRequest != null) {
        // do not terminate if the request is already running to avoid closing pooled connections
        currentRequest.cancel(false);
        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 = setContentTypeHeaders(binaryTransportEnabled, prepareDelete()).setUri(uriBuilder.build()).build();
    scheduleAsyncCleanupRequest(createCleanupBackoff(), request, "cleanup");
}
Also used : HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) Request(com.facebook.airlift.http.client.Request)

Example 4 with HttpUriBuilder

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

the class HttpRemoteTask method cancel.

@Override
public synchronized void cancel() {
    try (SetThreadName ignored = new SetThreadName("HttpRemoteTask-%s", taskId)) {
        TaskStatus taskStatus = getTaskStatus();
        if (taskStatus.getState().isDone()) {
            return;
        }
        // send cancel to task and ignore response
        HttpUriBuilder uriBuilder = getHttpUriBuilder(taskStatus).addParameter("abort", "false");
        Request request = setContentTypeHeaders(binaryTransportEnabled, prepareDelete()).setUri(uriBuilder.build()).build();
        scheduleAsyncCleanupRequest(createCleanupBackoff(), request, "cancel");
    }
}
Also used : SetThreadName(com.facebook.airlift.concurrent.SetThreadName) HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) TaskUpdateRequest(com.facebook.presto.server.TaskUpdateRequest) Request(com.facebook.airlift.http.client.Request) TaskStatus(com.facebook.presto.execution.TaskStatus)

Example 5 with HttpUriBuilder

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

the class HttpLocationFactory method createTaskLocation.

@Override
public URI createTaskLocation(InternalNode node, TaskId taskId) {
    requireNonNull(node, "node is null");
    requireNonNull(taskId, "taskId is null");
    if (taskCommunicationProtocol.equals(CommunicationProtocol.HTTP)) {
        return createLegacyTaskLocation(node, taskId);
    }
    OptionalInt thriftPort = node.getThriftPort();
    HttpUriBuilder builder = uriBuilderFrom(node.getInternalUri());
    if (taskCommunicationProtocol.equals(CommunicationProtocol.THRIFT) && thriftPort.isPresent()) {
        builder.scheme("thrift");
        builder.port(thriftPort.getAsInt());
    } else {
    // fall back to http case
    }
    return builder.appendPath("/v1/task").appendPath(taskId.toString()).build();
}
Also used : HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) OptionalInt(java.util.OptionalInt)

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