Search in sources :

Example 1 with StateChangeListener

use of com.facebook.presto.execution.StateMachine.StateChangeListener in project presto by prestodb.

the class QueryStateMachine method addQueryInfoStateChangeListener.

/**
 * Add a listener for the final query info.  This notification is guaranteed to be fired only once.
 * Listener is always notified asynchronously using a dedicated notification thread pool so, care should
 * be taken to avoid leaking {@code this} when adding a listener in a constructor.
 */
public void addQueryInfoStateChangeListener(StateChangeListener<QueryInfo> stateChangeListener) {
    AtomicBoolean done = new AtomicBoolean();
    StateChangeListener<Optional<QueryInfo>> fireOnceStateChangeListener = finalQueryInfo -> {
        if (finalQueryInfo.isPresent() && done.compareAndSet(false, true)) {
            stateChangeListener.stateChanged(finalQueryInfo.get());
        }
    };
    finalQueryInfo.addStateChangeListener(fireOnceStateChangeListener);
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EMPTY_STAGE_STATS(com.facebook.presto.execution.BasicStageExecutionStats.EMPTY_STAGE_STATS) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) TransactionId(com.facebook.presto.transaction.TransactionId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) StageInfo.getAllStages(com.facebook.presto.execution.StageInfo.getAllStages) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) 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) Streams(com.google.common.collect.Streams) GuardedBy(javax.annotation.concurrent.GuardedBy) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) List(java.util.List) USER_CANCELED(com.facebook.presto.spi.StandardErrorCode.USER_CANCELED) Optional(java.util.Optional) QueryOutputInfo(com.facebook.presto.execution.QueryExecution.QueryOutputInfo) WAITING_FOR_PREREQUISITES(com.facebook.presto.execution.QueryState.WAITING_FOR_PREREQUISITES) Logger(com.facebook.airlift.log.Logger) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorCode(com.facebook.presto.spi.ErrorCode) 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) ArrayList(java.util.ArrayList) TERMINAL_QUERY_STATES(com.facebook.presto.execution.QueryState.TERMINAL_QUERY_STATES) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) Objects.requireNonNull(java.util.Objects.requireNonNull) TransactionManager(com.facebook.presto.transaction.TransactionManager) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) SelectedRole(com.facebook.presto.spi.security.SelectedRole) 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) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) QueryType(com.facebook.presto.spi.resourceGroups.QueryType) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional)

Example 2 with StateChangeListener

use of com.facebook.presto.execution.StateMachine.StateChangeListener in project presto by prestodb.

the class TaskInfoFetcher method addFinalTaskInfoListener.

/**
 * Add a listener for the final task info.  This notification is guaranteed to be fired only once.
 * Listener is always notified asynchronously using a dedicated notification thread pool so, care should
 * be taken to avoid leaking {@code this} when adding a listener in a constructor. Additionally, it is
 * possible notifications are observed out of order due to the asynchronous execution.
 */
public void addFinalTaskInfoListener(StateChangeListener<TaskInfo> stateChangeListener) {
    AtomicBoolean done = new AtomicBoolean();
    StateChangeListener<Optional<TaskInfo>> fireOnceStateChangeListener = finalTaskInfo -> {
        if (finalTaskInfo.isPresent() && done.compareAndSet(false, true)) {
            stateChangeListener.stateChanged(finalTaskInfo.get());
        }
    };
    finalTaskInfo.addStateChangeListener(fireOnceStateChangeListener);
    fireOnceStateChangeListener.stateChanged(finalTaskInfo.get());
}
Also used : JsonCodec(com.facebook.airlift.json.JsonCodec) ScheduledFuture(java.util.concurrent.ScheduledFuture) MetadataManager(com.facebook.presto.metadata.MetadataManager) TaskStatus(com.facebook.presto.execution.TaskStatus) Builder.preparePost(com.facebook.airlift.http.client.Request.Builder.preparePost) SimpleHttpResponseHandler(com.facebook.presto.server.SimpleHttpResponseHandler) RequestErrorTracker.taskRequestErrorTracker(com.facebook.presto.server.RequestErrorTracker.taskRequestErrorTracker) Duration(io.airlift.units.Duration) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Response(com.facebook.airlift.http.client.Response) FullSmileResponseHandler.createFullSmileResponseHandler(com.facebook.presto.server.smile.FullSmileResponseHandler.createFullSmileResponseHandler) URI(java.net.URI) MetadataUpdates(com.facebook.presto.metadata.MetadataUpdates) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GuardedBy(javax.annotation.concurrent.GuardedBy) Codec(com.facebook.airlift.json.Codec) ResponseHandler(com.facebook.airlift.http.client.ResponseHandler) AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler(com.facebook.presto.server.smile.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler) StateMachine(com.facebook.presto.execution.StateMachine) RequestHelpers.setContentTypeHeaders(com.facebook.presto.server.RequestHelpers.setContentTypeHeaders) Optional(java.util.Optional) PRESTO_CURRENT_STATE(com.facebook.presto.client.PrestoHeaders.PRESTO_CURRENT_STATE) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpUriBuilder(com.facebook.airlift.http.client.HttpUriBuilder) QueryManager(com.facebook.presto.execution.QueryManager) SmileCodec(com.facebook.airlift.json.smile.SmileCodec) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StaticBodyGenerator.createStaticBodyGenerator(com.facebook.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) RequestErrorTracker(com.facebook.presto.server.RequestErrorTracker) SetThreadName(com.facebook.airlift.concurrent.SetThreadName) Executor(java.util.concurrent.Executor) Session(com.facebook.presto.Session) BaseResponse(com.facebook.presto.server.smile.BaseResponse) HttpClient(com.facebook.airlift.http.client.HttpClient) PRESTO_MAX_WAIT(com.facebook.presto.client.PrestoHeaders.PRESTO_MAX_WAIT) Consumer(java.util.function.Consumer) HttpUriBuilder.uriBuilderFrom(com.facebook.airlift.http.client.HttpUriBuilder.uriBuilderFrom) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) REMOTE_TASK_ERROR(com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_ERROR) SimpleHttpResponseCallback(com.facebook.presto.server.SimpleHttpResponseCallback) Request(com.facebook.airlift.http.client.Request) ResponseHandlerUtils.propagate(com.facebook.airlift.http.client.ResponseHandlerUtils.propagate) TaskId(com.facebook.presto.execution.TaskId) Builder.prepareGet(com.facebook.airlift.http.client.Request.Builder.prepareGet) TaskInfo(com.facebook.presto.execution.TaskInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional)

Example 3 with StateChangeListener

use of com.facebook.presto.execution.StateMachine.StateChangeListener in project presto by prestodb.

the class StageExecutionStateMachine method addFinalStageInfoListener.

/**
 * Add a listener for the final stage info.  This notification is guaranteed to be fired only once.
 * Listener is always notified asynchronously using a dedicated notification thread pool so, care should
 * be taken to avoid leaking {@code this} when adding a listener in a constructor. Additionally, it is
 * possible notifications are observed out of order due to the asynchronous execution.
 */
public void addFinalStageInfoListener(StateChangeListener<StageExecutionInfo> finalStatusListener) {
    AtomicBoolean done = new AtomicBoolean();
    StateChangeListener<Optional<StageExecutionInfo>> fireOnceStateChangeListener = finalStageInfo -> {
        if (finalStageInfo.isPresent() && done.compareAndSet(false, true)) {
            finalStatusListener.stateChanged(finalStageInfo.get());
        }
    };
    finalInfo.addStateChangeListener(fireOnceStateChangeListener);
}
Also used : TaskStats(com.facebook.presto.operator.TaskStats) Logger(com.facebook.airlift.log.Logger) SCHEDULING_SPLITS(com.facebook.presto.execution.StageExecutionState.SCHEDULING_SPLITS) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) OptionalDouble(java.util.OptionalDouble) Failures(com.facebook.presto.util.Failures) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) Duration.succinctNanos(io.airlift.units.Duration.succinctNanos) SCHEDULED(com.facebook.presto.execution.StageExecutionState.SCHEDULED) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) SCHEDULING(com.facebook.presto.execution.StageExecutionState.SCHEDULING) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ABORTED(com.facebook.presto.execution.StageExecutionState.ABORTED) ImmutableList(com.google.common.collect.ImmutableList) TERMINAL_STAGE_STATES(com.facebook.presto.execution.StageExecutionState.TERMINAL_STAGE_STATES) Objects.requireNonNull(java.util.Objects.requireNonNull) ExecutorService(java.util.concurrent.ExecutorService) PLANNED(com.facebook.presto.execution.StageExecutionState.PLANNED) CANCELED(com.facebook.presto.execution.StageExecutionState.CANCELED) Distribution(com.facebook.airlift.stats.Distribution) BlockedReason(com.facebook.presto.operator.BlockedReason) SplitSchedulerStats(com.facebook.presto.execution.scheduler.SplitSchedulerStats) FINISHED_TASK_SCHEDULING(com.facebook.presto.execution.StageExecutionState.FINISHED_TASK_SCHEDULING) RUNNING(com.facebook.presto.execution.StageExecutionState.RUNNING) DateTime(org.joda.time.DateTime) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Math.min(java.lang.Math.min) Preconditions.checkState(com.google.common.base.Preconditions.checkState) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) FAILED(com.facebook.presto.execution.StageExecutionState.FAILED) Optional(java.util.Optional) Math.max(java.lang.Math.max) FINISHED(com.facebook.presto.execution.StageExecutionState.FINISHED) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional)

Aggregations

StateChangeListener (com.facebook.presto.execution.StateMachine.StateChangeListener)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 Optional (java.util.Optional)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Logger (com.facebook.airlift.log.Logger)2 Session (com.facebook.presto.Session)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableList (com.google.common.collect.ImmutableList)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 DataSize.succinctBytes (io.airlift.units.DataSize.succinctBytes)2 URI (java.net.URI)2 List (java.util.List)2 Set (java.util.Set)2 Executor (java.util.concurrent.Executor)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Consumer (java.util.function.Consumer)2 GuardedBy (javax.annotation.concurrent.GuardedBy)2