Search in sources :

Example 1 with StateChangeListener

use of io.prestosql.execution.StateMachine.StateChangeListener in project hetu-core by openlookeng.

the class StageStateMachine 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<StageInfo> finalStatusListener) {
    AtomicBoolean done = new AtomicBoolean();
    StateChangeListener<Optional<StageInfo>> fireOnceStateChangeListener = finalStageInfo -> {
        if (finalStageInfo.isPresent() && done.compareAndSet(false, true)) {
            finalStatusListener.stateChanged(finalStageInfo.get());
        }
    };
    finalStageInfo.addStateChangeListener(fireOnceStateChangeListener);
}
Also used : CANCELED(io.prestosql.execution.StageState.CANCELED) FAILED(io.prestosql.execution.StageState.FAILED) SCHEDULED(io.prestosql.execution.StageState.SCHEDULED) REUSE_STRATEGY_PRODUCER(io.prestosql.spi.operator.ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_PRODUCER) Duration(io.airlift.units.Duration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TERMINAL_STAGE_STATES(io.prestosql.execution.StageState.TERMINAL_STAGE_STATES) Map(java.util.Map) URI(java.net.URI) SCHEDULING(io.prestosql.execution.StageState.SCHEDULING) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) BlockedReason(io.prestosql.operator.BlockedReason) ImmutableMap(com.google.common.collect.ImmutableMap) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Math.min(java.lang.Math.min) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) SplitSchedulerStats(io.prestosql.execution.scheduler.SplitSchedulerStats) Optional(java.util.Optional) Math.max(java.lang.Math.max) OperatorStats(io.prestosql.operator.OperatorStats) PLANNED(io.prestosql.execution.StageState.PLANNED) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) RUNNING(io.prestosql.execution.StageState.RUNNING) TaskStats(io.prestosql.operator.TaskStats) StateChangeListener(io.prestosql.execution.StateMachine.StateChangeListener) Logger(io.airlift.log.Logger) RESUMABLE_FAILURE(io.prestosql.execution.StageState.RESUMABLE_FAILURE) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) OptionalDouble(java.util.OptionalDouble) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) SCHEDULING_SPLITS(io.prestosql.execution.StageState.SCHEDULING_SPLITS) ImmutableList(com.google.common.collect.ImmutableList) SystemSessionProperties.isReuseTableScanEnabled(io.prestosql.SystemSessionProperties.isReuseTableScanEnabled) Failures(io.prestosql.util.Failures) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Duration.succinctDuration(io.airlift.units.Duration.succinctDuration) Math.toIntExact(java.lang.Math.toIntExact) ExecutorService(java.util.concurrent.ExecutorService) FINISHED(io.prestosql.execution.StageState.FINISHED) PlanFragment(io.prestosql.sql.planner.PlanFragment) REUSE_STRATEGY_CONSUMER(io.prestosql.spi.operator.ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_CONSUMER) DateTime(org.joda.time.DateTime) RESCHEDULING(io.prestosql.execution.StageState.RESCHEDULING) PipelineStats(io.prestosql.operator.PipelineStats) AtomicLong(java.util.concurrent.atomic.AtomicLong) Distribution(io.airlift.stats.Distribution) ABORTED(io.prestosql.execution.StageState.ABORTED) StageGcStatistics(io.prestosql.spi.eventlistener.StageGcStatistics) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional)

Example 2 with StateChangeListener

use of io.prestosql.execution.StateMachine.StateChangeListener in project hetu-core by openlookeng.

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 : HttpClient(io.airlift.http.client.HttpClient) PRESTO_TASK_INSTANCE_ID(io.prestosql.client.PrestoHeaders.PRESTO_TASK_INSTANCE_ID) TaskId(io.prestosql.execution.TaskId) ScheduledFuture(java.util.concurrent.ScheduledFuture) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StateChangeListener(io.prestosql.execution.StateMachine.StateChangeListener) BaseResponse(io.prestosql.protocol.BaseResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Duration(io.airlift.units.Duration) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) URI(java.net.URI) RequestHelpers.setContentTypeHeaders(io.prestosql.protocol.RequestHelpers.setContentTypeHeaders) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) JsonCodecWrapper.unwrapJsonCodec(io.prestosql.protocol.JsonCodecWrapper.unwrapJsonCodec) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) TaskStatus(io.prestosql.execution.TaskStatus) Executor(java.util.concurrent.Executor) FullSmileResponseHandler.createFullSmileResponseHandler(io.prestosql.protocol.FullSmileResponseHandler.createFullSmileResponseHandler) Codec(io.prestosql.protocol.Codec) AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler(io.prestosql.protocol.AdaptingJsonResponseHandler.createAdaptingJsonResponseHandler) TaskInfo(io.prestosql.execution.TaskInfo) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ResponseHandler(io.airlift.http.client.ResponseHandler) GuardedBy(javax.annotation.concurrent.GuardedBy) StateMachine(io.prestosql.execution.StateMachine) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) Optional(java.util.Optional) SetThreadName(io.airlift.concurrent.SetThreadName) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional)

Example 3 with StateChangeListener

use of io.prestosql.execution.StateMachine.StateChangeListener in project hetu-core by openlookeng.

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 : ResourceGroupManager(io.prestosql.execution.resourcegroups.ResourceGroupManager) PLANNING(io.prestosql.execution.QueryState.PLANNING) SystemSessionProperties(io.prestosql.SystemSessionProperties) WAITING_FOR_RESOURCES(io.prestosql.execution.QueryState.WAITING_FOR_RESOURCES) Duration(io.airlift.units.Duration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) WarningCollector(io.prestosql.execution.warnings.WarningCollector) USER_CANCELED(io.prestosql.spi.StandardErrorCode.USER_CANCELED) FINISHING(io.prestosql.execution.QueryState.FINISHING) Map(java.util.Map) Type(io.prestosql.spi.type.Type) URI(java.net.URI) RESCHEDULING(io.prestosql.execution.QueryState.RESCHEDULING) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) AccessControl(io.prestosql.security.AccessControl) EMPTY_STAGE_STATS(io.prestosql.execution.BasicStageStats.EMPTY_STAGE_STATS) BlockedReason(io.prestosql.operator.BlockedReason) ImmutableMap(com.google.common.collect.ImmutableMap) FINISHED(io.prestosql.execution.QueryState.FINISHED) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TableScanNode(io.prestosql.spi.plan.TableScanNode) SelectedRole(io.prestosql.spi.security.SelectedRole) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Ticker(com.google.common.base.Ticker) GuardedBy(javax.annotation.concurrent.GuardedBy) Sets(com.google.common.collect.Sets) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) ResourceGroupId(io.prestosql.spi.resourcegroups.ResourceGroupId) List(java.util.List) StageInfo.getAllStages(io.prestosql.execution.StageInfo.getAllStages) Optional(java.util.Optional) GENERAL_POOL(io.prestosql.memory.LocalMemoryManager.GENERAL_POOL) Failures.toFailure(io.prestosql.util.Failures.toFailure) OperatorStats(io.prestosql.operator.OperatorStats) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StateChangeListener(io.prestosql.execution.StateMachine.StateChangeListener) Logger(io.airlift.log.Logger) TransactionManager(io.prestosql.transaction.TransactionManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) DISPATCHING(io.prestosql.execution.QueryState.DISPATCHING) RESUMING(io.prestosql.execution.QueryState.RESUMING) TaskLocation(io.prestosql.operator.TaskLocation) NOT_FOUND(io.prestosql.spi.StandardErrorCode.NOT_FOUND) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) STARTING(io.prestosql.execution.QueryState.STARTING) VersionedMemoryPoolId(io.prestosql.memory.VersionedMemoryPoolId) ImmutableList(com.google.common.collect.ImmutableList) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) QUEUED(io.prestosql.execution.QueryState.QUEUED) RUNNING(io.prestosql.execution.QueryState.RUNNING) QueryId(io.prestosql.spi.QueryId) ErrorCode(io.prestosql.spi.ErrorCode) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) PlanFragment(io.prestosql.sql.planner.PlanFragment) FAILED(io.prestosql.execution.QueryState.FAILED) Executor(java.util.concurrent.Executor) DateTime(org.joda.time.DateTime) FutureCallback(com.google.common.util.concurrent.FutureCallback) Consumer(java.util.function.Consumer) TransactionId(io.prestosql.transaction.TransactionId) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) TERMINAL_QUERY_STATES(io.prestosql.execution.QueryState.TERMINAL_QUERY_STATES) QueryOutputInfo(io.prestosql.execution.QueryExecution.QueryOutputInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BasicQueryStats(io.prestosql.server.BasicQueryStats) StageGcStatistics(io.prestosql.spi.eventlistener.StageGcStatistics) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional)

Aggregations

Duration (io.airlift.units.Duration)3 StateChangeListener (io.prestosql.execution.StateMachine.StateChangeListener)3 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 ImmutableMap (com.google.common.collect.ImmutableMap)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Logger (io.airlift.log.Logger)2 DataSize.succinctBytes (io.airlift.units.DataSize.succinctBytes)2 Session (io.prestosql.Session)2 URI (java.net.URI)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Optional (java.util.Optional)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Ticker (com.google.common.base.Ticker)1 ImmutableSet (com.google.common.collect.ImmutableSet)1