use of com.facebook.presto.execution.TaskStatus in project presto by prestodb.
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);
}
TaskStatus failedTaskStatus = failWith(getTaskStatus(), FAILED, ImmutableList.of(toFailure(cause)));
// Transition task to failed state without waiting for the final task info returned by the abort request.
// The abort request is very likely not to succeed, leaving the task and the stage in the limbo state for
// the entire duration of abort retries. If the task is failed, it is not that important to actually
// record the final statistics and the final information about a failed task.
taskInfoFetcher.updateTaskInfo(getTaskInfo().withTaskStatus(failedTaskStatus));
// Initiate abort request
abort(failedTaskStatus);
}
use of com.facebook.presto.execution.TaskStatus in project presto by prestodb.
the class HttpRemoteTask method updateTaskStats.
private void updateTaskStats() {
TaskStatus taskStatus = getTaskStatus();
if (taskStatus.getState().isDone()) {
nodeStatsTracker.setPartitionedSplits(PartitionedSplitsInfo.forZeroSplits());
nodeStatsTracker.setMemoryUsage(0);
nodeStatsTracker.setCpuUsage(taskStatus.getTaskAgeInMillis(), 0);
} else {
nodeStatsTracker.setPartitionedSplits(getPartitionedSplitsInfo());
nodeStatsTracker.setMemoryUsage(taskStatus.getMemoryReservationInBytes() + taskStatus.getSystemMemoryReservationInBytes());
nodeStatsTracker.setCpuUsage(taskStatus.getTaskAgeInMillis(), taskStatus.getTotalCpuTimeInNanos());
}
}
use of com.facebook.presto.execution.TaskStatus in project presto by prestodb.
the class TaskResource method getTaskStatus.
@GET
@Path("{taskId}/status")
@Consumes({ APPLICATION_JSON, APPLICATION_JACKSON_SMILE, APPLICATION_THRIFT_BINARY, APPLICATION_THRIFT_COMPACT, APPLICATION_THRIFT_FB_COMPACT })
@Produces({ APPLICATION_JSON, APPLICATION_JACKSON_SMILE, APPLICATION_THRIFT_BINARY, APPLICATION_THRIFT_COMPACT, APPLICATION_THRIFT_FB_COMPACT })
public void getTaskStatus(@PathParam("taskId") TaskId taskId, @HeaderParam(PRESTO_CURRENT_STATE) TaskState currentState, @HeaderParam(PRESTO_MAX_WAIT) Duration maxWait, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
requireNonNull(taskId, "taskId is null");
if (currentState == null || maxWait == null) {
TaskStatus taskStatus = taskManager.getTaskStatus(taskId);
asyncResponse.resume(taskStatus);
return;
}
Duration waitTime = randomizeWaitTime(maxWait);
// TODO: With current implementation, a newly completed driver group won't trigger immediate HTTP response,
// leading to a slight delay of approx 1 second, which is not a major issue for any query that are heavy weight enough
// to justify group-by-group execution. In order to fix this, REST endpoint /v1/{task}/status will need change.
ListenableFuture<TaskStatus> futureTaskStatus = addTimeout(taskManager.getTaskStatus(taskId, currentState), () -> taskManager.getTaskStatus(taskId), waitTime, timeoutExecutor);
// For hard timeout, add an additional time to max wait for thread scheduling contention and GC
Duration timeout = new Duration(waitTime.toMillis() + ADDITIONAL_WAIT_TIME.toMillis(), MILLISECONDS);
bindAsyncResponse(asyncResponse, futureTaskStatus, responseExecutor).withTimeout(timeout);
}
use of com.facebook.presto.execution.TaskStatus in project presto by prestodb.
the class QueryExecutionResource method getTaskInfo.
@GET
@Path("/v1/query-execution/{queryId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTaskInfo(@PathParam("queryId") String queryId) {
QueryInfo query;
try {
query = manager.getQueryInfo(QueryId.valueOf(queryId));
} catch (NoSuchElementException e) {
return Response.status(Response.Status.NOT_FOUND).build();
}
List<StageInfo> stages = collectStages(query.getOutputStage());
List<Task> tasks = new ArrayList<>();
List<Flow> flows = new ArrayList<>();
for (StageInfo stage : stages) {
for (TaskInfo task : stage.getTasks()) {
int bufferedPages = 0;
TaskStatus taskStatus = task.getTaskStatus();
for (BufferInfo bufferInfo : task.getOutputBuffers().getBuffers()) {
bufferedPages += bufferInfo.getBufferedPages();
if (!bufferInfo.getBufferId().equals(OUTPUT_TASK_ID)) {
flows.add(new Flow(taskStatus.getTaskId().toString(), bufferInfo.getBufferId().toString(), bufferInfo.getPageBufferInfo().getPagesAdded(), bufferInfo.getBufferedPages(), bufferInfo.isFinished()));
}
}
long last = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
if (task.getStats().getEndTime() != null) {
last = task.getStats().getEndTime().getMillis();
}
tasks.add(new Task(taskStatus.getTaskId().toString(), taskStatus.getState().toString(), taskStatus.getSelf().getHost(), last - task.getStats().getCreateTime().getMillis(), task.getStats().getTotalCpuTime().roundTo(TimeUnit.MILLISECONDS), task.getStats().getTotalBlockedTime().roundTo(TimeUnit.MILLISECONDS), task.getStats().getRawInputDataSize().roundTo(DataSize.Unit.BYTE), task.getStats().getRawInputPositions(), task.getStats().getOutputDataSize().roundTo(DataSize.Unit.BYTE), task.getStats().getOutputPositions(), task.getStats().getMemoryReservation().roundTo(DataSize.Unit.BYTE), task.getStats().getQueuedDrivers(), task.getStats().getRunningDrivers(), task.getStats().getCompletedDrivers(), bufferedPages));
}
}
Map<String, Object> result = ImmutableMap.<String, Object>builder().put("tasks", tasks).put("flows", flows).build();
return Response.ok(result).build();
}
use of com.facebook.presto.execution.TaskStatus in project presto by prestodb.
the class TestHttpRemoteTask method testRemoteTaskMismatch.
// This timeout should never be reached because a daemon thread in test should fail the test and do proper cleanup.
@Test(timeOut = 30000)
public void testRemoteTaskMismatch() throws InterruptedException, ExecutionException {
Duration idleTimeout = new Duration(3, SECONDS);
Duration failTimeout = new Duration(20, SECONDS);
JsonCodec<TaskStatus> taskStatusCodec = JsonCodec.jsonCodec(TaskStatus.class);
JsonCodec<TaskInfo> taskInfoCodec = JsonCodec.jsonCodec(TaskInfo.class);
TaskManagerConfig taskManagerConfig = new TaskManagerConfig();
// Shorten status refresh wait and info update interval so that we can have a shorter test timeout
taskManagerConfig.setStatusRefreshMaxWait(new Duration(idleTimeout.roundTo(MILLISECONDS) / 100, MILLISECONDS));
taskManagerConfig.setInfoUpdateInterval(new Duration(idleTimeout.roundTo(MILLISECONDS) / 10, MILLISECONDS));
AtomicLong lastActivityNanos = new AtomicLong(System.nanoTime());
HttpProcessor httpProcessor = new HttpProcessor(taskStatusCodec, taskInfoCodec, lastActivityNanos);
TestingHttpClient testingHttpClient = new TestingHttpClient(httpProcessor);
HttpRemoteTaskFactory httpRemoteTaskFactory = new HttpRemoteTaskFactory(new QueryManagerConfig(), taskManagerConfig, testingHttpClient, new TestSqlTaskManager.MockLocationFactory(), taskStatusCodec, taskInfoCodec, JsonCodec.jsonCodec(TaskUpdateRequest.class), new RemoteTaskStats());
RemoteTask remoteTask = httpRemoteTaskFactory.createRemoteTask(TEST_SESSION, new TaskId("test", 1, 2), new PrestoNode("node-id", URI.create("http://192.0.1.2"), new NodeVersion("version"), false), TaskTestUtils.PLAN_FRAGMENT, ImmutableMultimap.of(), createInitialEmptyOutputBuffers(OutputBuffers.BufferType.BROADCAST), new NodeTaskMap.PartitionedSplitCountTracker(i -> {
}), true);
httpProcessor.setInitialTaskInfo(remoteTask.getTaskInfo());
remoteTask.start();
CompletableFuture<Void> testComplete = new CompletableFuture<>();
asyncRun(idleTimeout.roundTo(MILLISECONDS), failTimeout.roundTo(MILLISECONDS), lastActivityNanos, () -> testComplete.complete(null), (message, cause) -> testComplete.completeExceptionally(new AssertionError(message, cause)));
testComplete.get();
httpRemoteTaskFactory.stop();
assertTrue(remoteTask.getTaskStatus().getState().isDone(), format("TaskStatus is not in a done state: %s", remoteTask.getTaskStatus()));
assertEquals(getOnlyElement(remoteTask.getTaskStatus().getFailures()).getErrorCode(), REMOTE_TASK_MISMATCH.toErrorCode());
assertTrue(remoteTask.getTaskInfo().getTaskStatus().getState().isDone(), format("TaskInfo is not in a done state: %s", remoteTask.getTaskInfo()));
}
Aggregations