Search in sources :

Example 6 with TaskStatus

use of io.prestosql.execution.TaskStatus in project hetu-core by openlookeng.

the class TestHttpRemoteTask method createHttpRemoteTaskFactory.

private static HttpRemoteTaskFactory createHttpRemoteTaskFactory(TestingTaskResource testingTaskResource) throws Exception {
    Bootstrap app = new Bootstrap(new JsonModule(), new SmileModule(), new HandleJsonModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(JsonMapper.class);
            binder.bind(Metadata.class).toInstance(createTestMetadataManager());
            jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskStatus.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskUpdateRequest.class);
            smileCodecBinder(binder).bindSmileCodec(TaskStatus.class);
            smileCodecBinder(binder).bindSmileCodec(TaskInfo.class);
            smileCodecBinder(binder).bindSmileCodec(TaskUpdateRequest.class);
        }

        @Provides
        private HttpRemoteTaskFactory createHttpRemoteTaskFactory(JsonMapper jsonMapper, JsonCodec<TaskStatus> taskStatusJsonCodec, SmileCodec<TaskStatus> taskStatusSmileCodec, JsonCodec<TaskInfo> taskInfoJsonCodec, SmileCodec<TaskInfo> taskInfoSmileCodec, JsonCodec<TaskUpdateRequest> taskUpdateRequestJsonCodec, SmileCodec<TaskUpdateRequest> taskUpdateRequestSmileCodec) {
            JaxrsTestingHttpProcessor jaxrsTestingHttpProcessor = new JaxrsTestingHttpProcessor(URI.create("http://fake.invalid/"), testingTaskResource, jsonMapper);
            TestingHttpClient testingHttpClient = new TestingHttpClient(jaxrsTestingHttpProcessor.setTrace(TRACE_HTTP));
            testingTaskResource.setHttpClient(testingHttpClient);
            return new HttpRemoteTaskFactory(new QueryManagerConfig(), TASK_MANAGER_CONFIG, testingHttpClient, new TestSqlTaskManager.MockLocationFactory(), taskStatusJsonCodec, taskStatusSmileCodec, taskInfoJsonCodec, taskInfoSmileCodec, taskUpdateRequestJsonCodec, taskUpdateRequestSmileCodec, new RemoteTaskStats(), new InternalCommunicationConfig());
        }
    });
    Injector injector = app.strictConfig().doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("test", new TestingHandleResolver());
    return injector.getInstance(HttpRemoteTaskFactory.class);
}
Also used : TestingHandleResolver(io.prestosql.testing.TestingHandleResolver) HandleResolver(io.prestosql.metadata.HandleResolver) JsonMapper(io.airlift.jaxrs.JsonMapper) TaskInfo(io.prestosql.execution.TaskInfo) JsonBinder.jsonBinder(io.airlift.json.JsonBinder.jsonBinder) JsonCodecBinder.jsonCodecBinder(io.airlift.json.JsonCodecBinder.jsonCodecBinder) Binder(com.google.inject.Binder) SmileCodecBinder.smileCodecBinder(io.prestosql.protocol.SmileCodecBinder.smileCodecBinder) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) JaxrsTestingHttpProcessor(io.airlift.jaxrs.testing.JaxrsTestingHttpProcessor) HandleJsonModule(io.prestosql.metadata.HandleJsonModule) Injector(com.google.inject.Injector) HttpRemoteTaskFactory(io.prestosql.server.HttpRemoteTaskFactory) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Bootstrap(io.airlift.bootstrap.Bootstrap) TypeDeserializer(io.prestosql.type.TypeDeserializer) TestingHandleResolver(io.prestosql.testing.TestingHandleResolver) TaskUpdateRequest(io.prestosql.server.TaskUpdateRequest) TaskStatus(io.prestosql.execution.TaskStatus) Provides(com.google.inject.Provides) JsonModule(io.airlift.json.JsonModule) HandleJsonModule(io.prestosql.metadata.HandleJsonModule) SmileModule(io.prestosql.protocol.SmileModule) QueryManagerConfig(io.prestosql.execution.QueryManagerConfig) Module(com.google.inject.Module) SmileModule(io.prestosql.protocol.SmileModule) JsonModule(io.airlift.json.JsonModule) HandleJsonModule(io.prestosql.metadata.HandleJsonModule)

Example 7 with TaskStatus

use of io.prestosql.execution.TaskStatus in project hetu-core by openlookeng.

the class TaskInfoFetcher method sendNextRequest.

private synchronized void sendNextRequest() {
    TaskStatus taskStatus = getTaskInfo().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;
    }
    HttpUriBuilder httpUriBuilder = uriBuilderFrom(taskStatus.getSelf());
    URI uri = summarizeTaskInfo ? httpUriBuilder.addParameter("summarize").build() : httpUriBuilder.build();
    Request request = addInstanceIdHeader(setContentTypeHeaders(isBinaryEncoding, prepareGet())).setUri(uri).build();
    ResponseHandler responseHandler;
    if (isBinaryEncoding) {
        responseHandler = createFullSmileResponseHandler((io.prestosql.protocol.SmileCodec<TaskInfo>) taskInfoCodec);
    } else {
        responseHandler = createAdaptingJsonResponseHandler(unwrapJsonCodec(taskInfoCodec));
    }
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, responseHandler);
    currentRequestStartNanos.set(System.nanoTime());
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
}
Also used : FullSmileResponseHandler.createFullSmileResponseHandler(io.prestosql.protocol.FullSmileResponseHandler.createFullSmileResponseHandler) AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler(io.prestosql.protocol.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler) ResponseHandler(io.airlift.http.client.ResponseHandler) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) Request(io.airlift.http.client.Request) TaskStatus(io.prestosql.execution.TaskStatus) URI(java.net.URI)

Example 8 with TaskStatus

use of io.prestosql.execution.TaskStatus in project hetu-core by openlookeng.

the class TaskInfoFetcher method updateTaskInfo.

synchronized void updateTaskInfo(TaskInfo newValue) {
    boolean updated = taskInfo.setIf(newValue, oldValue -> {
        TaskStatus oldTaskStatus = oldValue.getTaskStatus();
        TaskStatus newTaskStatus = newValue.getTaskStatus();
        if (oldTaskStatus.getState().isDone()) {
            // never update if the task has reached a terminal state
            return false;
        }
        // don't update to an older version (same version is ok)
        return newTaskStatus.getVersion() >= oldTaskStatus.getVersion();
    });
    if (updated && newValue.getTaskStatus().getState().isDone()) {
        finalTaskInfo.compareAndSet(Optional.empty(), Optional.of(newValue));
        stop();
    }
}
Also used : TaskStatus(io.prestosql.execution.TaskStatus)

Example 9 with TaskStatus

use of io.prestosql.execution.TaskStatus in project hetu-core by openlookeng.

the class ContinuousTaskStatusFetcher method scheduleNextRequest.

private synchronized void scheduleNextRequest() {
    // stopped or done?
    TaskStatus tmpTaskStatus = getTaskStatus();
    if (!running || tmpTaskStatus.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 = addInstanceIdHeader(setContentTypeHeaders(isBinaryEncoding, prepareGet())).setUri(uriBuilderFrom(tmpTaskStatus.getSelf()).appendPath("status").build()).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).setHeader(PRESTO_CURRENT_STATE, tmpTaskStatus.getState().toString()).setHeader(PRESTO_MAX_WAIT, refreshMaxWait.toString()).build();
    ResponseHandler responseHandler;
    if (isBinaryEncoding) {
        responseHandler = createFullSmileResponseHandler((io.prestosql.protocol.SmileCodec<TaskStatus>) taskStatusCodec);
    } else {
        responseHandler = createAdaptingJsonResponseHandler(unwrapJsonCodec(taskStatusCodec));
    }
    errorTracker.startRequest();
    future = httpClient.executeAsync(request, responseHandler);
    currentRequestStartNanos.set(System.nanoTime());
    Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
}
Also used : FullSmileResponseHandler.createFullSmileResponseHandler(io.prestosql.protocol.FullSmileResponseHandler.createFullSmileResponseHandler) AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler(io.prestosql.protocol.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler) ResponseHandler(io.airlift.http.client.ResponseHandler) Request(io.airlift.http.client.Request) TaskStatus(io.prestosql.execution.TaskStatus)

Example 10 with TaskStatus

use of io.prestosql.execution.TaskStatus in project hetu-core by openlookeng.

the class HttpRemoteTask method failTask.

/**
 * Move the task directly to the failed state if there was a failure in this task
 */
private void failTask(Throwable cause) {
    TaskStatus taskStatus = getTaskStatus();
    if (!taskStatus.getState().isDone()) {
        log.debug(cause, "Remote task %s failed with %s", taskStatus.getSelf(), cause);
    }
    ExecutionFailureInfo failureInfo = toFailure(cause);
    if (SystemSessionProperties.isSnapshotEnabled(session)) {
        if (isResumableFailure(failureInfo)) {
            // Determine if the failure can be recovered by resuming query from a previous checkpoing
            taskStatus = failWith(taskStatus, RESUMABLE_FAILURE, ImmutableList.of(failureInfo));
            taskStatusFetcher.updateTaskStatus(taskStatus);
            return;
        }
        log.debug(cause, "Snapshot: remote task %s failed with unresumable error %s", taskStatus.getSelf(), cause);
    }
    abort(failWith(taskStatus, FAILED, ImmutableList.of(failureInfo)));
}
Also used : TaskStatus(io.prestosql.execution.TaskStatus) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo)

Aggregations

TaskStatus (io.prestosql.execution.TaskStatus)12 ResponseHandler (io.airlift.http.client.ResponseHandler)4 AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler (io.prestosql.protocol.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler)4 FullSmileResponseHandler.createFullSmileResponseHandler (io.prestosql.protocol.FullSmileResponseHandler.createFullSmileResponseHandler)4 SetThreadName (io.airlift.concurrent.SetThreadName)3 Request (io.airlift.http.client.Request)3 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)2 Duration (io.airlift.units.Duration)2 TaskInfo (io.prestosql.execution.TaskInfo)2 BaseResponse (io.prestosql.protocol.BaseResponse)2 SmileCodec (io.prestosql.protocol.SmileCodec)2 URI (java.net.URI)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1