use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class SqlTaskManager method close.
@Override
@PreDestroy
public void close() {
boolean taskCanceled = false;
for (SqlTask task : tasks.asMap().values()) {
if (task.getTaskInfo().getTaskStatus().getState().isDone()) {
continue;
}
task.failed(new PrestoException(SERVER_SHUTTING_DOWN, format("Server is shutting down. Task %s has been canceled", task.getTaskId())));
taskCanceled = true;
}
if (taskCanceled) {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
taskNotificationExecutor.shutdownNow();
taskManagementExecutor.shutdownNow();
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class StartTransactionTask method execute.
@Override
public ListenableFuture<?> execute(StartTransaction statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
if (!session.isClientTransactionSupport()) {
throw new PrestoException(StandardErrorCode.INCOMPATIBLE_CLIENT, "Client does not support transactions");
}
if (session.getTransactionId().isPresent()) {
throw new PrestoException(StandardErrorCode.NOT_SUPPORTED, "Nested transactions not supported");
}
Optional<IsolationLevel> isolationLevel = extractIsolationLevel(statement);
Optional<Boolean> readOnly = extractReadOnly(statement);
TransactionId transactionId = transactionManager.beginTransaction(isolationLevel.orElse(TransactionManager.DEFAULT_ISOLATION), readOnly.orElse(TransactionManager.DEFAULT_READ_ONLY), false);
stateMachine.setStartedTransactionId(transactionId);
// Since the current session does not contain this new transaction ID, we need to manually mark it as inactive
// when this statement completes.
transactionManager.trySetInactive(transactionId);
return immediateFuture(null);
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class SqlQueryManager method failAbandonedQueries.
public void failAbandonedQueries() {
for (QueryExecution queryExecution : queries.values()) {
QueryInfo queryInfo = queryExecution.getQueryInfo();
if (queryInfo.getState().isDone()) {
continue;
}
if (isAbandoned(queryInfo)) {
log.info("Failing abandoned query %s", queryExecution.getQueryId());
queryExecution.fail(new PrestoException(ABANDONED_QUERY, format("Query %s has not been accessed since %s: currentTime %s", queryInfo.getQueryId(), queryInfo.getQueryStats().getLastHeartbeat(), DateTime.now())));
}
}
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class SqlQueryQueueManager method submit.
@Override
public void submit(Statement statement, QueryExecution queryExecution, Executor executor) {
List<QueryQueue> queues;
try {
queues = selectQueues(queryExecution.getSession(), executor);
} catch (PrestoException e) {
queryExecution.fail(e);
return;
}
for (QueryQueue queue : queues) {
if (!queue.reserve(queryExecution)) {
// Reject query if we couldn't acquire a permit to enter the queue.
// The permits will be released when this query fails.
queryExecution.fail(new PrestoException(QUERY_QUEUE_FULL, "Too many queued queries"));
return;
}
}
queues.get(0).enqueue(createQueuedExecution(queryExecution, queues.subList(1, queues.size()), executor));
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class RollbackTask method execute.
@Override
public ListenableFuture<?> execute(Rollback statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
if (!session.getTransactionId().isPresent()) {
throw new PrestoException(NOT_IN_TRANSACTION, "No transaction in progress");
}
TransactionId transactionId = session.getTransactionId().get();
stateMachine.clearTransactionId();
transactionManager.asyncAbort(transactionId);
return immediateFuture(null);
}
Aggregations