public boolean transitionToFinishing() { queryStateTimer.beginFinishing(); if (!queryState.setIf(FINISHING, currentState -> currentState != FINISHING && !currentState.isDone())) { return false; } Optional<TransactionId> transactionId = session.getTransactionId(); if (transactionId.isPresent() && transactionManager.transactionExists(transactionId.get()) && transactionManager.isAutoCommit(transactionId.get())) { ListenableFuture<?> commitFuture = transactionManager.asyncCommit(transactionId.get()); Futures.addCallback(commitFuture, new FutureCallback<Object>() { @Override public void onSuccess(@Nullable Object result) { transitionToFinished(); } @Override public void onFailure(Throwable throwable) { transitionToFailed(throwable); } }, directExecutor()); } else { transitionToFinished(); } return true; }
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; }
@Override public ListenableFuture<?> execute(Call call, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) if (!transactionManager.isAutoCommit(stateMachine.getSession().getRequiredTransactionId())) { throw new PrestoException(NOT_SUPPORTED, "Procedures cannot be called within a transaction (use autocommit mode)");