Search in sources :

Example 1 with FINISHING

use of com.facebook.presto.execution.QueryState.FINISHING in project presto by prestodb.

the class QueryStateMachine method transitionToFinishing.

public boolean transitionToFinishing() {
    Duration durationSinceCreation = nanosSince(createNanos).convertToMostSuccinctTimeUnit();
    queuedTime.compareAndSet(null, durationSinceCreation);
    totalPlanningStartNanos.compareAndSet(null, tickerNanos());
    totalPlanningTime.compareAndSet(null, nanosSince(totalPlanningStartNanos.get()));
    DateTime now = DateTime.now();
    executionStartTime.compareAndSet(null, now);
    finishingStartNanos.compareAndSet(null, tickerNanos());
    if (!queryState.setIf(FINISHING, currentState -> currentState != FINISHING && !currentState.isDone())) {
        return false;
    }
    if (autoCommit) {
        ListenableFuture<?> commitFuture = transactionManager.asyncCommit(session.getTransactionId().get());
        Futures.addCallback(commitFuture, new FutureCallback<Object>() {

            @Override
            public void onSuccess(@Nullable Object result) {
                transitionToFinished();
            }

            @Override
            public void onFailure(Throwable throwable) {
                transitionToFailed(throwable);
            }
        });
    } else {
        transitionToFinished();
    }
    return true;
}
Also used : NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) Duration.succinctNanos(io.airlift.units.Duration.succinctNanos) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) Duration(io.airlift.units.Duration) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) OperatorStats(com.facebook.presto.operator.OperatorStats) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) Map(java.util.Map) FAILED(com.facebook.presto.execution.QueryState.FAILED) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) TransactionId(com.facebook.presto.transaction.TransactionId) URI(java.net.URI) StageInfo.getAllStages(com.facebook.presto.execution.StageInfo.getAllStages) ImmutableSet(com.google.common.collect.ImmutableSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Failures.toFailure(com.facebook.presto.util.Failures.toFailure) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Ticker(com.google.common.base.Ticker) Sets(com.google.common.collect.Sets) List(java.util.List) USER_CANCELED(com.facebook.presto.spi.StandardErrorCode.USER_CANCELED) Optional(java.util.Optional) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) ErrorCode(com.facebook.presto.spi.ErrorCode) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) PrestoException(com.facebook.presto.spi.PrestoException) VersionedMemoryPoolId(com.facebook.presto.memory.VersionedMemoryPoolId) AtomicReference(java.util.concurrent.atomic.AtomicReference) TERMINAL_QUERY_STATES(com.facebook.presto.execution.QueryState.TERMINAL_QUERY_STATES) HashSet(java.util.HashSet) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) ImmutableList(com.google.common.collect.ImmutableList) FailureInfo(com.facebook.presto.client.FailureInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) TransactionManager(com.facebook.presto.transaction.TransactionManager) Nullable(javax.annotation.Nullable) BlockedReason(com.facebook.presto.operator.BlockedReason) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) Executor(java.util.concurrent.Executor) Session(com.facebook.presto.Session) DateTime(org.joda.time.DateTime) FutureCallback(com.google.common.util.concurrent.FutureCallback) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) QueryId(com.facebook.presto.spi.QueryId) STARTING(com.facebook.presto.execution.QueryState.STARTING) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) Duration(io.airlift.units.Duration) DateTime(org.joda.time.DateTime)

Aggregations

Session (com.facebook.presto.Session)1 FailureInfo (com.facebook.presto.client.FailureInfo)1 FAILED (com.facebook.presto.execution.QueryState.FAILED)1 FINISHED (com.facebook.presto.execution.QueryState.FINISHED)1 FINISHING (com.facebook.presto.execution.QueryState.FINISHING)1 PLANNING (com.facebook.presto.execution.QueryState.PLANNING)1 QUEUED (com.facebook.presto.execution.QueryState.QUEUED)1 RUNNING (com.facebook.presto.execution.QueryState.RUNNING)1 STARTING (com.facebook.presto.execution.QueryState.STARTING)1 TERMINAL_QUERY_STATES (com.facebook.presto.execution.QueryState.TERMINAL_QUERY_STATES)1 StageInfo.getAllStages (com.facebook.presto.execution.StageInfo.getAllStages)1 StateChangeListener (com.facebook.presto.execution.StateMachine.StateChangeListener)1 GENERAL_POOL (com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL)1 VersionedMemoryPoolId (com.facebook.presto.memory.VersionedMemoryPoolId)1 Metadata (com.facebook.presto.metadata.Metadata)1 BlockedReason (com.facebook.presto.operator.BlockedReason)1 OperatorStats (com.facebook.presto.operator.OperatorStats)1 AccessControl (com.facebook.presto.security.AccessControl)1 ErrorCode (com.facebook.presto.spi.ErrorCode)1 PrestoException (com.facebook.presto.spi.PrestoException)1