public static ExecutionFailureInfo toFailure(Throwable failure) { return toFailure(failure, newIdentityHashSet()); }
public static ExecutionFailureInfo toFailure(Throwable failure) { if (failure == null) { return null; } // todo prevent looping with suppressed cause loops and such String type; if (failure instanceof Failure) { type = ((Failure) failure).getType(); } else { type = failure.getClass().getCanonicalName(); } return new ExecutionFailureInfo(type, failure.getMessage(), toFailure(failure.getCause()), toFailures(asList(failure.getSuppressed())), Lists.transform(asList(failure.getStackTrace()), toStringFunction()), getErrorLocation(failure), toErrorCode(failure)); }
@Nullable @JsonProperty public FailureInfo getLastFailureInfo() { Exception lastFailureException = getLastFailureException(); if (lastFailureException == null) { return null; } return Failures.toFailure(lastFailureException).toFailureInfo(); }
public boolean transitionToFailed(Throwable throwable) { requireNonNull(throwable, "throwable is null"); failureCause.compareAndSet(null, Failures.toFailure(throwable)); boolean failed = stageState.setIf(FAILED, currentState -> !currentState.isDone()); if (failed) { log.error(throwable, "Stage %s failed", stageId); } else { log.debug(throwable, "Failure after stage %s finished", stageId); } return failed; }
public static QueryInfo immediateFailureQueryInfo(Session session, String query, URI self, Optional<ResourceGroupId> resourceGroupId, Throwable throwable) ExecutionFailureInfo failureCause = toFailure(throwable); QueryInfo queryInfo = new QueryInfo( session.getQueryId(),
ExecutionFailureInfo cause = toFailure(throwable.getCause(), seenFailures); ErrorCode errorCode = toErrorCode(throwable); if (errorCode == null) { cause, Arrays.stream(throwable.getSuppressed()) .map(failure -> toFailure(failure, seenFailures)) .collect(toImmutableList()), Lists.transform(asList(throwable.getStackTrace()), toStringFunction()),
private static Expression createFailureFunction(RuntimeException exception, Type type) { requireNonNull(exception, "Exception is null"); String failureInfo = JsonCodec.jsonCodec(FailureInfo.class).toJson(Failures.toFailure(exception).toFailureInfo()); FunctionCall jsonParse = new FunctionCall(QualifiedName.of("json_parse"), ImmutableList.of(new StringLiteral(failureInfo))); FunctionCall failureFunction = new FunctionCall(QualifiedName.of("fail"), ImmutableList.of(jsonParse)); return new Cast(failureFunction, type.getTypeSignature().toString()); }
/** * 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)))); }
public boolean transitionToCanceled() { cleanupQueryQuietly(); queryStateTimer.endQuery(); // NOTE: The failure cause must be set before triggering the state change, so // listeners can observe the exception. This is safe because the failure cause // can only be observed if the transition to FAILED is successful. failureCause.compareAndSet(null, toFailure(new PrestoException(USER_CANCELED, "Query was canceled"))); boolean canceled = queryState.setIf(FAILED, currentState -> !currentState.isDone()); if (canceled) { session.getTransactionId().ifPresent(transactionId -> { if (transactionManager.isAutoCommit(transactionId)) { transactionManager.asyncAbort(transactionId); } else { transactionManager.fail(transactionId); } }); } return canceled; }
public boolean transitionToFailed(Throwable throwable) { cleanupQueryQuietly(); queryStateTimer.endQuery(); // NOTE: The failure cause must be set before triggering the state change, so // listeners can observe the exception. This is safe because the failure cause // can only be observed if the transition to FAILED is successful. requireNonNull(throwable, "throwable is null"); failureCause.compareAndSet(null, toFailure(throwable)); boolean failed = queryState.setIf(FAILED, currentState -> !currentState.isDone()); if (failed) { QUERY_STATE_LOG.debug(throwable, "Query %s failed", queryId); session.getTransactionId().ifPresent(transactionId -> { if (transactionManager.isAutoCommit(transactionId)) { transactionManager.asyncAbort(transactionId); } else { transactionManager.fail(transactionId); } }); } else { QUERY_STATE_LOG.debug(throwable, "Failure after query %s finished", queryId); } return failed; }
ExecutionFailureInfo failure = toFailure(exception1); assertEquals(failure.getMessage(), "fake exception 1"); assertNull(failure.getCause()); failure = toFailure(exception2); assertEquals(failure.getMessage(), "fake exception 2"); assertNotNull(failure.getCause()); exception1.addSuppressed(exception2); exception2.addSuppressed(exception1); failure = toFailure(exception1); assertEquals(failure.getMessage(), "fake exception 1"); assertNull(failure.getCause()); exception2 = new RuntimeException("fake exception 2", exception1); exception1.initCause(exception2); failure = toFailure(exception2); assertEquals(failure.getMessage(), "fake exception 2"); assertNotNull(failure.getCause());
failure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state))).toFailureInfo();
queryMonitor.queryImmediateFailureEvent(queryInfo, toFailure(e)); stats.queryQueued(); stats.queryStarted();
public boolean transitionToFailed(Throwable throwable) { requireNonNull(throwable, "throwable is null"); failureCause.compareAndSet(null, Failures.toFailure(throwable)); boolean failed = stageState.setIf(FAILED, currentState -> !currentState.isDone()); if (failed) { log.error(throwable, "Stage %s failed", stageId); } else { log.debug(throwable, "Failure after stage %s finished", stageId); } return failed; }
public boolean transitionToFailed(Throwable throwable) { requireNonNull(throwable, "throwable is null"); Duration durationSinceCreation = nanosSince(createNanos).convertToMostSuccinctTimeUnit(); queuedTime.compareAndSet(null, durationSinceCreation); totalPlanningTime.compareAndSet(null, durationSinceCreation); DateTime now = DateTime.now(); executionStartTime.compareAndSet(null, now); finishingStartNanos.compareAndSet(null, System.nanoTime()); finishingTime.compareAndSet(null, nanosSince(finishingStartNanos.get())); endTime.compareAndSet(null, now); endNanos.compareAndSet(0, System.nanoTime()); failureCause.compareAndSet(null, toFailure(throwable)); boolean failed = queryState.setIf(FAILED, currentState -> !currentState.isDone()); if (failed) { log.error(throwable, "Query %s failed", queryId); } else { log.debug(throwable, "Failure after query %s finished", queryId); } session.getTransactionId().ifPresent(autoCommit ? transactionManager::asyncAbort : transactionManager::fail); return failed; }
@VisibleForTesting public static Expression createFailureFunction(RuntimeException exception, Type type) { requireNonNull(exception, "Exception is null"); String failureInfo = JsonCodec.jsonCodec(FailureInfo.class).toJson(Failures.toFailure(exception).toFailureInfo()); FunctionCall jsonParse = new FunctionCall(QualifiedName.of("json_parse"), ImmutableList.of(new StringLiteral(failureInfo))); FunctionCall failureFunction = new FunctionCall(QualifiedName.of("fail"), ImmutableList.of(jsonParse)); return new Cast(failureFunction, type.getTypeSignature().toString()); }
/** * Move the task directly to the failed state */ private void failTask(Throwable cause) { TaskInfo taskInfo = getTaskInfo(); if (!taskInfo.getState().isDone()) { log.debug(cause, "Remote task failed: %s", taskInfo.getSelf()); } updateTaskInfo(new TaskInfo(taskInfo.getTaskId(), taskInfo.getTaskInstanceId(), TaskInfo.MAX_VERSION, TaskState.FAILED, taskInfo.getSelf(), taskInfo.getLastHeartbeat(), taskInfo.getOutputBuffers(), taskInfo.getNoMoreSplits(), taskInfo.getStats(), ImmutableList.of(toFailure(cause)), taskInfo.isNeedsPlan())); }
private static QueryError toQueryError(QueryInfo queryInfo) { FailureInfo failure = queryInfo.getFailureInfo(); if (failure == null) { QueryState state = queryInfo.getState(); if ((!state.isDone()) || (state == QueryState.FINISHED)) { return null; } log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state); failure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state))).toFailureInfo(); } ErrorCode errorCode; if (queryInfo.getErrorCode() != null) { errorCode = queryInfo.getErrorCode(); } else { errorCode = INTERNAL_ERROR.toErrorCode(); log.warn("Failed query %s has no error code", queryInfo.getQueryId()); } return new QueryError( failure.getMessage(), null, errorCode.getCode(), errorCode.getName(), toErrorType(errorCode.getCode()).toString(), failure.getErrorLocation(), failure); }