Search in sources :

Example 1 with InjectedFailure

use of io.trino.execution.FailureInjector.InjectedFailure in project trino by trinodb.

the class TaskResource method injectFailure.

private boolean injectFailure(Optional<String> traceToken, TaskId taskId, RequestType requestType, AsyncResponse asyncResponse) {
    if (traceToken.isEmpty()) {
        return false;
    }
    Optional<InjectedFailure> injectedFailure = failureInjector.getInjectedFailure(traceToken.get(), taskId.getStageId().getId(), taskId.getPartitionId(), taskId.getAttemptId());
    if (injectedFailure.isEmpty()) {
        return false;
    }
    InjectedFailure failure = injectedFailure.get();
    Duration timeout = failureInjector.getRequestTimeout();
    switch(failure.getInjectedFailureType()) {
        case TASK_MANAGEMENT_REQUEST_FAILURE:
            if (requestType.isTaskManagement()) {
                log.info("Failing %s request for task %s", requestType, taskId);
                asyncResponse.resume(Response.serverError().build());
                return true;
            }
            break;
        case TASK_MANAGEMENT_REQUEST_TIMEOUT:
            if (requestType.isTaskManagement()) {
                log.info("Timing out %s request for task %s", requestType, taskId);
                asyncResponse.setTimeout(timeout.toMillis(), MILLISECONDS);
                return true;
            }
            break;
        case TASK_GET_RESULTS_REQUEST_FAILURE:
            if (!requestType.isTaskManagement()) {
                log.info("Failing %s request for task %s", requestType, taskId);
                asyncResponse.resume(Response.serverError().build());
                return true;
            }
            break;
        case TASK_GET_RESULTS_REQUEST_TIMEOUT:
            if (!requestType.isTaskManagement()) {
                log.info("Timing out %s request for task %s", requestType, taskId);
                asyncResponse.setTimeout(timeout.toMillis(), MILLISECONDS);
                return true;
            }
            break;
        case TASK_FAILURE:
            log.info("Injecting failure for task %s at %s", taskId, requestType);
            taskManager.failTask(taskId, injectedFailure.get().getTaskFailureException());
            break;
        default:
            throw new IllegalArgumentException("unexpected failure type: " + failure.getInjectedFailureType());
    }
    return false;
}
Also used : Duration(io.airlift.units.Duration) InjectedFailure(io.trino.execution.FailureInjector.InjectedFailure)

Aggregations

Duration (io.airlift.units.Duration)1 InjectedFailure (io.trino.execution.FailureInjector.InjectedFailure)1