Search in sources :

Example 56 with PrestoException

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();
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) PreDestroy(javax.annotation.PreDestroy)

Example 57 with PrestoException

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);
}
Also used : IsolationLevel(com.facebook.presto.spi.transaction.IsolationLevel) PrestoException(com.facebook.presto.spi.PrestoException) Session(com.facebook.presto.Session) TransactionId(com.facebook.presto.transaction.TransactionId)

Example 58 with PrestoException

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())));
        }
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException)

Example 59 with PrestoException

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));
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException)

Example 60 with PrestoException

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);
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) Session(com.facebook.presto.Session) TransactionId(com.facebook.presto.transaction.TransactionId)

Aggregations

PrestoException (com.facebook.presto.spi.PrestoException)273 IOException (java.io.IOException)58 Type (com.facebook.presto.spi.type.Type)48 ImmutableList (com.google.common.collect.ImmutableList)40 SchemaTableName (com.facebook.presto.spi.SchemaTableName)32 ArrayList (java.util.ArrayList)32 List (java.util.List)28 Path (org.apache.hadoop.fs.Path)28 Map (java.util.Map)24 Slice (io.airlift.slice.Slice)23 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)22 SqlType (com.facebook.presto.spi.function.SqlType)22 ImmutableMap (com.google.common.collect.ImmutableMap)22 Optional (java.util.Optional)20 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)19 Block (com.facebook.presto.spi.block.Block)19 Test (org.testng.annotations.Test)19 ConnectorSession (com.facebook.presto.spi.ConnectorSession)17 Table (com.facebook.presto.hive.metastore.Table)15 Session (com.facebook.presto.Session)14