Search in sources :

Example 1 with TableWriteInfo

use of com.facebook.presto.execution.scheduler.TableWriteInfo in project presto by prestodb.

the class TestLocalExecutionPlanner method getLocalExecutionPlan.

private LocalExecutionPlan getLocalExecutionPlan(Session session) {
    SubPlan subPlan = runner.inTransaction(session, transactionSession -> {
        Plan plan = runner.createPlan(transactionSession, "SELECT avg(totalprice) FROM orders", OPTIMIZED_AND_VALIDATED, false, WarningCollector.NOOP);
        return runner.createSubPlans(transactionSession, plan, false);
    });
    // Expect only one child sub plan doing partial aggregation.
    assertEquals(subPlan.getChildren().size(), 1);
    PlanFragment leafFragment = subPlan.getChildren().get(0).getFragment();
    return createTestingPlanner().plan(createTaskContext(EXECUTOR, SCHEDULED_EXECUTOR, session), leafFragment.getRoot(), leafFragment.getPartitioningScheme(), leafFragment.getStageExecutionDescriptor(), leafFragment.getTableScanSchedulingOrder(), new TestingOutputBuffer(), new TestingRemoteSourceFactory(), new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) LocalExecutionPlan(com.facebook.presto.sql.planner.LocalExecutionPlanner.LocalExecutionPlan)

Example 2 with TableWriteInfo

use of com.facebook.presto.execution.scheduler.TableWriteInfo in project presto by prestodb.

the class SqlStageExecution method scheduleTask.

private synchronized RemoteTask scheduleTask(InternalNode node, TaskId taskId, Multimap<PlanNodeId, Split> sourceSplits) {
    checkArgument(!allTasks.contains(taskId), "A task with id %s already exists", taskId);
    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    initialSplits.putAll(sourceSplits);
    sourceTasks.forEach((planNodeId, task) -> {
        TaskStatus status = task.getTaskStatus();
        if (status.getState() != TaskState.FINISHED) {
            initialSplits.put(planNodeId, createRemoteSplitFor(taskId, task.getRemoteTaskLocation(), task.getTaskId()));
        }
    });
    OutputBuffers outputBuffers = this.outputBuffers.get();
    checkState(outputBuffers != null, "Initial output buffers must be set before a task can be scheduled");
    RemoteTask task = remoteTaskFactory.createRemoteTask(session, taskId, node, planFragment, initialSplits.build(), outputBuffers, nodeTaskMap.createTaskStatsTracker(node, taskId), summarizeTaskInfo, tableWriteInfo);
    completeSources.forEach(task::noMoreSplits);
    allTasks.add(taskId);
    tasks.computeIfAbsent(node, key -> newConcurrentHashSet()).add(task);
    nodeTaskMap.addTask(node, task);
    task.addStateChangeListener(new StageTaskListener(taskId));
    task.addFinalTaskInfoListener(this::updateFinalTaskInfo);
    if (!stateMachine.getState().isDone()) {
        task.start();
    } else {
        // stage finished while we were scheduling this task
        task.abort();
    }
    return task;
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) GENERIC_INTERNAL_ERROR(com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) Duration(io.airlift.units.Duration) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) HashMultimap(com.google.common.collect.HashMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) URI(java.net.URI) ImmutableSet(com.google.common.collect.ImmutableSet) REMOTE_TASK_MISMATCH(com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_MISMATCH) SplitSchedulerStats(com.facebook.presto.execution.scheduler.SplitSchedulerStats) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) PAGE_TRANSPORT_TIMEOUT(com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_TIMEOUT) GuardedBy(javax.annotation.concurrent.GuardedBy) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DataSize(io.airlift.units.DataSize) List(java.util.List) TOO_MANY_REQUESTS_FAILED(com.facebook.presto.spi.StandardErrorCode.TOO_MANY_REQUESTS_FAILED) Entry(java.util.Map.Entry) Optional(java.util.Optional) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) OutputBuffers(com.facebook.presto.execution.buffer.OutputBuffers) ErrorCode(com.facebook.presto.spi.ErrorCode) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SystemSessionProperties.getMaxFailedTaskPercentage(com.facebook.presto.SystemSessionProperties.getMaxFailedTaskPercentage) PrestoException(com.facebook.presto.spi.PrestoException) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) REMOTE_HOST_GONE(com.facebook.presto.spi.StandardErrorCode.REMOTE_HOST_GONE) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Objects.requireNonNull(java.util.Objects.requireNonNull) RemoteSplit(com.facebook.presto.split.RemoteSplit) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) GENERIC_RECOVERY_ERROR(com.facebook.presto.spi.StandardErrorCode.GENERIC_RECOVERY_ERROR) RemoteTransactionHandle(com.facebook.presto.metadata.RemoteTransactionHandle) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ExecutorService(java.util.concurrent.ExecutorService) PAGE_TRANSPORT_ERROR(com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_ERROR) Executor(java.util.concurrent.Executor) Session(com.facebook.presto.Session) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) InternalNode(com.facebook.presto.metadata.InternalNode) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) REMOTE_TASK_ERROR(com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_ERROR) FailureDetector(com.facebook.presto.failureDetector.FailureDetector) REMOTE_CONNECTOR_ID(com.facebook.presto.operator.ExchangeOperator.REMOTE_CONNECTOR_ID) Split(com.facebook.presto.metadata.Split) GONE(com.facebook.presto.failureDetector.FailureDetector.State.GONE) BYTE(io.airlift.units.DataSize.Unit.BYTE) OutputBuffers(com.facebook.presto.execution.buffer.OutputBuffers) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RemoteSplit(com.facebook.presto.split.RemoteSplit) Split(com.facebook.presto.metadata.Split)

Example 3 with TableWriteInfo

use of com.facebook.presto.execution.scheduler.TableWriteInfo 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 4 with TableWriteInfo

use of com.facebook.presto.execution.scheduler.TableWriteInfo in project presto by prestodb.

the class TestSqlTask method testEmptyQuery.

@Test
public void testEmptyQuery() {
    SqlTask sqlTask = createInitialTask();
    TaskInfo taskInfo = sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(), createInitialEmptyOutputBuffers(PARTITIONED).withNoMoreBufferIds(), Optional.of(new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty())));
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    taskInfo = sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(new TaskSource(TABLE_SCAN_NODE_ID, ImmutableSet.of(), true)), createInitialEmptyOutputBuffers(PARTITIONED).withNoMoreBufferIds(), Optional.of(new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty())));
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.FINISHED);
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.FINISHED);
}
Also used : SqlTask.createSqlTask(com.facebook.presto.execution.SqlTask.createSqlTask) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) Test(org.testng.annotations.Test)

Example 5 with TableWriteInfo

use of com.facebook.presto.execution.scheduler.TableWriteInfo in project presto by prestodb.

the class TestSqlTask method testCancel.

@Test
public void testCancel() {
    SqlTask sqlTask = createInitialTask();
    TaskInfo taskInfo = sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(), createInitialEmptyOutputBuffers(PARTITIONED).withBuffer(OUT, 0).withNoMoreBufferIds(), Optional.of(new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty())));
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    assertNull(taskInfo.getStats().getEndTime());
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    assertNull(taskInfo.getStats().getEndTime());
    taskInfo = sqlTask.cancel();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.CANCELED);
    assertNotNull(taskInfo.getStats().getEndTime());
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.CANCELED);
    assertNotNull(taskInfo.getStats().getEndTime());
}
Also used : SqlTask.createSqlTask(com.facebook.presto.execution.SqlTask.createSqlTask) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) Test(org.testng.annotations.Test)

Aggregations

TableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo)12 SqlTask.createSqlTask (com.facebook.presto.execution.SqlTask.createSqlTask)4 Test (org.testng.annotations.Test)4 PrestoException (com.facebook.presto.spi.PrestoException)3 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)3 Session (com.facebook.presto.Session)2 SplitSchedulerStats (com.facebook.presto.execution.scheduler.SplitSchedulerStats)2 StreamingSubPlan (com.facebook.presto.execution.scheduler.StreamingSubPlan)2 TableWriteInfo.createTableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo.createTableWriteInfo)2 InternalNode (com.facebook.presto.metadata.InternalNode)2 Split (com.facebook.presto.metadata.Split)2 QueryId (com.facebook.presto.spi.QueryId)2 HttpUriBuilder (com.facebook.airlift.http.client.HttpUriBuilder)1 Request (com.facebook.airlift.http.client.Request)1 ResponseHandler (com.facebook.airlift.http.client.ResponseHandler)1 StatusResponseHandler.createStatusResponseHandler (com.facebook.airlift.http.client.StatusResponseHandler.createStatusResponseHandler)1 JsonCodec (com.facebook.airlift.json.JsonCodec)1 SmileCodec (com.facebook.airlift.json.smile.SmileCodec)1 SystemSessionProperties.getMaxFailedTaskPercentage (com.facebook.presto.SystemSessionProperties.getMaxFailedTaskPercentage)1 DDLDefinitionTask (com.facebook.presto.execution.DDLDefinitionTask)1