private HttpUriBuilder getHttpUriBuilder(TaskStatus taskStatus) { HttpUriBuilder uriBuilder = uriBuilderFrom(taskStatus.getSelf()); if (summarizeTaskInfo) { uriBuilder.addParameter("summarize"); } return uriBuilder; }
private static Set<String> globalUniqueNodes(StageInfo stageInfo) { if (stageInfo == null) { return ImmutableSet.of(); } ImmutableSet.Builder<String> nodes = ImmutableSet.builder(); for (TaskInfo task : stageInfo.getTasks()) { // todo add nodeId to TaskInfo URI uri = task.getTaskStatus().getSelf(); nodes.add(uri.getHost() + ":" + uri.getPort()); } for (StageInfo subStage : stageInfo.getSubStages()) { nodes.addAll(globalUniqueNodes(subStage)); } return nodes.build(); }
public ContinuousTaskStatusFetcher( Consumer<Throwable> onFail, TaskStatus initialTaskStatus, Duration refreshMaxWait, JsonCodec<TaskStatus> taskStatusCodec, Executor executor, HttpClient httpClient, Duration maxErrorDuration, ScheduledExecutorService errorScheduledExecutor, RemoteTaskStats stats) { requireNonNull(initialTaskStatus, "initialTaskStatus is null"); this.taskId = initialTaskStatus.getTaskId(); this.onFail = requireNonNull(onFail, "onFail is null"); this.taskStatus = new StateMachine<>("task-" + taskId, executor, initialTaskStatus); this.refreshMaxWait = requireNonNull(refreshMaxWait, "refreshMaxWait is null"); this.taskStatusCodec = requireNonNull(taskStatusCodec, "taskStatusCodec is null"); this.executor = requireNonNull(executor, "executor is null"); this.httpClient = requireNonNull(httpClient, "httpClient is null"); this.errorTracker = new RequestErrorTracker(taskId, initialTaskStatus.getSelf(), maxErrorDuration, errorScheduledExecutor, "getting task status"); this.stats = requireNonNull(stats, "stats is null"); }
private Optional<QueryFailureInfo> createQueryFailureInfo(ExecutionFailureInfo failureInfo, Optional<StageInfo> outputStage) { if (failureInfo == null) { return Optional.empty(); } Optional<TaskInfo> failedTask = outputStage.flatMap(QueryMonitor::findFailedTask); return Optional.of(new QueryFailureInfo( failureInfo.getErrorCode(), Optional.ofNullable(failureInfo.getType()), Optional.ofNullable(failureInfo.getMessage()), failedTask.map(task -> task.getTaskStatus().getTaskId().toString()), failedTask.map(task -> task.getTaskStatus().getSelf().getHost()), executionFailureInfoCodec.toJson(failureInfo))); }
public TaskInfoFetcher( Consumer<Throwable> onFail, TaskInfo initialTask, HttpClient httpClient, Duration updateInterval, JsonCodec<TaskInfo> taskInfoCodec, Duration maxErrorDuration, boolean summarizeTaskInfo, Executor executor, ScheduledExecutorService updateScheduledExecutor, ScheduledExecutorService errorScheduledExecutor, RemoteTaskStats stats) { requireNonNull(initialTask, "initialTask is null"); requireNonNull(errorScheduledExecutor, "errorScheduledExecutor is null"); this.taskId = initialTask.getTaskStatus().getTaskId(); this.onFail = requireNonNull(onFail, "onFail is null"); this.taskInfo = new StateMachine<>("task " + taskId, executor, initialTask); this.finalTaskInfo = new StateMachine<>("task-" + taskId, executor, Optional.empty()); this.taskInfoCodec = requireNonNull(taskInfoCodec, "taskInfoCodec is null"); this.updateIntervalMillis = requireNonNull(updateInterval, "updateInterval is null").toMillis(); this.updateScheduledExecutor = requireNonNull(updateScheduledExecutor, "updateScheduledExecutor is null"); this.errorTracker = new RequestErrorTracker(taskId, initialTask.getTaskStatus().getSelf(), maxErrorDuration, errorScheduledExecutor, "getting info for task"); this.summarizeTaskInfo = summarizeTaskInfo; this.executor = requireNonNull(executor, "executor is null"); this.httpClient = requireNonNull(httpClient, "httpClient is null"); this.stats = requireNonNull(stats, "stats is null"); }
private static void updateQueryOutputLocations(QueryStateMachine queryStateMachine, OutputBufferId rootBufferId, Set<RemoteTask> tasks, boolean noMoreExchangeLocations) { Set<URI> bufferLocations = tasks.stream() .map(task -> task.getTaskStatus().getSelf()) .map(location -> uriBuilderFrom(location).appendPath("results").appendPath(rootBufferId.toString()).build()) .collect(toImmutableSet()); queryStateMachine.updateOutputLocations(bufferLocations, noMoreExchangeLocations); }
public synchronized void addExchangeLocations(PlanFragmentId fragmentId, Set<RemoteTask> sourceTasks, boolean noMoreExchangeLocations) { requireNonNull(fragmentId, "fragmentId is null"); requireNonNull(sourceTasks, "sourceTasks is null"); RemoteSourceNode remoteSource = exchangeSources.get(fragmentId); checkArgument(remoteSource != null, "Unknown remote source %s. Known sources are %s", fragmentId, exchangeSources.keySet()); this.sourceTasks.putAll(remoteSource.getId(), sourceTasks); for (RemoteTask task : getAllTasks()) { ImmutableMultimap.Builder<PlanNodeId, Split> newSplits = ImmutableMultimap.builder(); for (RemoteTask sourceTask : sourceTasks) { URI exchangeLocation = sourceTask.getTaskStatus().getSelf(); newSplits.put(remoteSource.getId(), createRemoteSplitFor(task.getTaskId(), exchangeLocation)); } task.addSplits(newSplits.build()); } if (noMoreExchangeLocations) { completeSourceFragments.add(fragmentId); // is the source now complete? if (completeSourceFragments.containsAll(remoteSource.getSourceFragmentIds())) { completeSources.add(remoteSource.getId()); for (RemoteTask task : getAllTasks()) { task.noMoreSplits(remoteSource.getId()); } } } }
void updateTaskStatus(TaskStatus newValue) { // change to new value if old value is not changed and new value has a newer version AtomicBoolean taskMismatch = new AtomicBoolean(); taskStatus.setIf(newValue, oldValue -> { // did the task instance id change if (!isNullOrEmpty(oldValue.getTaskInstanceId()) && !oldValue.getTaskInstanceId().equals(newValue.getTaskInstanceId())) { taskMismatch.set(true); return false; } if (oldValue.getState().isDone()) { // never update if the task has reached a terminal state return false; } if (newValue.getVersion() < oldValue.getVersion()) { // don't update to an older version (same version is ok) return false; } return true; }); if (taskMismatch.get()) { // This will also set the task status to FAILED state directly. // Additionally, this will issue a DELETE for the task to the worker. // While sending the DELETE is not required, it is preferred because a task was created by the previous request. onFail.accept(new PrestoException(REMOTE_TASK_MISMATCH, format("%s (%s)", REMOTE_TASK_MISMATCH_ERROR, HostAddress.fromUri(getTaskStatus().getSelf())))); } }
/** * 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); } abort(failWith(getTaskStatus(), FAILED, ImmutableList.of(toFailure(cause)))); }
TaskStatus status = task.getTaskStatus(); if (status.getState() != TaskState.FINISHED) { initialSplits.put(planNodeId, createRemoteSplitFor(taskId, status.getSelf()));
for (TaskInfo task : stageInfo.getTasks()) { URI uri = task.getTaskStatus().getSelf(); uniqueNodes.add(uri.getHost() + ":" + uri.getPort());
HttpUriBuilder httpUriBuilder = uriBuilderFrom(taskStatus.getSelf()); URI uri = summarizeTaskInfo ? httpUriBuilder.addParameter("summarize").build() : httpUriBuilder.build(); Request request = prepareGet()
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); }
public static TaskStatus failWith(TaskStatus taskStatus, TaskState state, List<ExecutionFailureInfo> exceptions) { return new TaskStatus( taskStatus.getTaskId(), taskStatus.getTaskInstanceId(), MAX_VERSION, state, taskStatus.getSelf(), taskStatus.getNodeId(), taskStatus.getCompletedDriverGroups(), exceptions, taskStatus.getQueuedPartitionedDrivers(), taskStatus.getRunningPartitionedDrivers(), taskStatus.isOutputBufferOverutilized(), taskStatus.getPhysicalWrittenDataSize(), taskStatus.getMemoryReservation(), taskStatus.getSystemMemoryReservation(), taskStatus.getFullGcCount(), taskStatus.getFullGcTime()); } }
++version, taskState, initialTaskStatus.getSelf(), "fake", ImmutableSet.of(),