Search in sources :

Example 1 with OperatorContext

use of io.prestosql.operator.OperatorContext in project hetu-core by openlookeng.

the class LocalQueryRunner method executeInternal.

private MaterializedResultWithPlan executeInternal(Session session, @Language("SQL") String sql) {
    lock.readLock().lock();
    try (Closer closer = Closer.create()) {
        AtomicReference<MaterializedResult.Builder> builder = new AtomicReference<>();
        PageConsumerOutputFactory outputFactory = new PageConsumerOutputFactory(types -> {
            builder.compareAndSet(null, MaterializedResult.resultBuilder(session, types));
            return builder.get()::page;
        });
        TaskContext taskContext = TestingTaskContext.builder(notificationExecutor, yieldExecutor, session).setMaxSpillSize(nodeSpillConfig.getMaxSpillPerNode()).setQueryMaxSpillSize(nodeSpillConfig.getQueryMaxSpillPerNode()).build();
        Plan plan = createPlan(session, sql, WarningCollector.NOOP);
        List<Driver> drivers = createDrivers(session, plan, outputFactory, taskContext);
        drivers.forEach(closer::register);
        boolean done = false;
        while (!done) {
            boolean processed = false;
            for (Driver driver : drivers) {
                if (alwaysRevokeMemory) {
                    driver.getDriverContext().getOperatorContexts().stream().filter(operatorContext -> operatorContext.getOperatorStats().getRevocableMemoryReservation().getValue() > 0).forEach(OperatorContext::requestMemoryRevoking);
                }
                if (!driver.isFinished()) {
                    driver.process();
                    processed = true;
                }
            }
            done = !processed;
        }
        verify(builder.get() != null, "Output operator was not created");
        return new MaterializedResultWithPlan(builder.get().build(), plan);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : Closer(com.google.common.io.Closer) CostCalculatorWithEstimatedExchanges(io.prestosql.cost.CostCalculatorWithEstimatedExchanges) RollbackTask(io.prestosql.execution.RollbackTask) FilterStatsCalculator(io.prestosql.cost.FilterStatsCalculator) Plan(io.prestosql.sql.planner.Plan) ConnectorManager(io.prestosql.connector.ConnectorManager) HttpServerConfig(io.airlift.http.server.HttpServerConfig) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) Prepare(io.prestosql.sql.tree.Prepare) Statement(io.prestosql.sql.tree.Statement) WarningCollector(io.prestosql.execution.warnings.WarningCollector) SnapshotConfig(io.prestosql.snapshot.SnapshotConfig) SchemaPropertiesSystemTable(io.prestosql.connector.system.SchemaPropertiesSystemTable) NoOpResourceGroupManager(io.prestosql.execution.resourcegroups.NoOpResourceGroupManager) PlanSanityChecker(io.prestosql.sql.planner.sanity.PlanSanityChecker) Map(java.util.Map) TestingSession.createBogusTestingCatalog(io.prestosql.testing.TestingSession.createBogusTestingCatalog) TransactionBuilder.transaction(io.prestosql.transaction.TransactionBuilder.transaction) GlobalSystemConnector(io.prestosql.connector.system.GlobalSystemConnector) RenameColumn(io.prestosql.sql.tree.RenameColumn) HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TransactionManagerConfig(io.prestosql.transaction.TransactionManagerConfig) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) SetSessionTask(io.prestosql.execution.SetSessionTask) CostCalculatorUsingExchanges(io.prestosql.cost.CostCalculatorUsingExchanges) PageConsumerOutputFactory(io.prestosql.testing.PageConsumerOperator.PageConsumerOutputFactory) CommentTask(io.prestosql.execution.CommentTask) PlanNode(io.prestosql.spi.plan.PlanNode) NodeSchedulerConfig(io.prestosql.execution.scheduler.NodeSchedulerConfig) RowExpressionDomainTranslator(io.prestosql.sql.relational.RowExpressionDomainTranslator) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) DropView(io.prestosql.sql.tree.DropView) PageSinkManager(io.prestosql.split.PageSinkManager) QueryPreparer(io.prestosql.execution.QueryPreparer) TaskManagerConfig(io.prestosql.execution.TaskManagerConfig) Plugin(io.prestosql.spi.Plugin) LocalExecutionPlanner(io.prestosql.sql.planner.LocalExecutionPlanner) EmbedVersion(io.prestosql.version.EmbedVersion) DropTable(io.prestosql.sql.tree.DropTable) TransactionManager(io.prestosql.transaction.TransactionManager) StageExecutionDescriptor(io.prestosql.operator.StageExecutionDescriptor) TaskContext(io.prestosql.operator.TaskContext) PlanPrinter(io.prestosql.sql.planner.planprinter.PlanPrinter) IndexJoinLookupStats(io.prestosql.operator.index.IndexJoinLookupStats) CommitTask(io.prestosql.execution.CommitTask) GenericSpillerFactory(io.prestosql.spiller.GenericSpillerFactory) ResetSession(io.prestosql.sql.tree.ResetSession) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Deallocate(io.prestosql.sql.tree.Deallocate) ResetSessionTask(io.prestosql.execution.ResetSessionTask) MetadataUtil(io.prestosql.metadata.MetadataUtil) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ParsingUtil.createParsingOptions(io.prestosql.sql.ParsingUtil.createParsingOptions) NodeTaskMap(io.prestosql.execution.NodeTaskMap) SplitSource(io.prestosql.split.SplitSource) Comment(io.prestosql.sql.tree.Comment) SpillerFactory(io.prestosql.spiller.SpillerFactory) RenameTable(io.prestosql.sql.tree.RenameTable) DriverContext(io.prestosql.operator.DriverContext) TaskCountEstimator(io.prestosql.cost.TaskCountEstimator) Lifespan(io.prestosql.execution.Lifespan) StatsCalculatorModule.createNewStatsCalculator(io.prestosql.cost.StatsCalculatorModule.createNewStatsCalculator) CreateViewTask(io.prestosql.execution.CreateViewTask) IOException(java.io.IOException) GlobalSystemConnectorFactory(io.prestosql.connector.system.GlobalSystemConnectorFactory) DeallocateTask(io.prestosql.execution.DeallocateTask) CatalogManager(io.prestosql.metadata.CatalogManager) PlanOptimizer(io.prestosql.sql.planner.optimizations.PlanOptimizer) QueryExplainer(io.prestosql.sql.analyzer.QueryExplainer) SystemSessionProperties(io.prestosql.SystemSessionProperties) SqlParser(io.prestosql.sql.parser.SqlParser) QueryManagerConfig(io.prestosql.execution.QueryManagerConfig) Duration(io.airlift.units.Duration) TaskSource(io.prestosql.execution.TaskSource) HetuConfig(io.prestosql.utils.HetuConfig) ConnectorPlanOptimizerManager(io.prestosql.sql.planner.ConnectorPlanOptimizerManager) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SetPathTask(io.prestosql.execution.SetPathTask) StartTransaction(io.prestosql.sql.tree.StartTransaction) Type(io.prestosql.spi.type.Type) StatsCalculator(io.prestosql.cost.StatsCalculator) PartitioningSpillerFactory(io.prestosql.spiller.PartitioningSpillerFactory) ImmutableSet(com.google.common.collect.ImmutableSet) CatalogName(io.prestosql.spi.connector.CatalogName) GenericPartitioningSpillerFactory(io.prestosql.spiller.GenericPartitioningSpillerFactory) Rollback(io.prestosql.sql.tree.Rollback) RenameColumnTask(io.prestosql.execution.RenameColumnTask) NodePartitioningManager(io.prestosql.sql.planner.NodePartitioningManager) NOT_PARTITIONED(io.prestosql.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED) Split(io.prestosql.metadata.Split) TableHandle(io.prestosql.spi.metadata.TableHandle) Function(java.util.function.Function) DynamicFilterCacheManager(io.prestosql.dynamicfilter.DynamicFilterCacheManager) LookupJoinOperators(io.prestosql.operator.LookupJoinOperators) PlanOptimizers(io.prestosql.sql.planner.PlanOptimizers) ImmutableList(com.google.common.collect.ImmutableList) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) PagesIndexPageSorter(io.prestosql.PagesIndexPageSorter) ExecutorService(java.util.concurrent.ExecutorService) IndexManager(io.prestosql.index.IndexManager) RenameIndex(io.prestosql.sql.tree.RenameIndex) PlanNodeSearcher.searchFrom(io.prestosql.sql.planner.optimizations.PlanNodeSearcher.searchFrom) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) JoinCompiler(io.prestosql.sql.gen.JoinCompiler) SpillerStats(io.prestosql.spiller.SpillerStats) GROUPED_SCHEDULING(io.prestosql.spi.connector.ConnectorSplitManager.SplitSchedulingStrategy.GROUPED_SCHEDULING) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) CostCalculator(io.prestosql.cost.CostCalculator) SubPlan(io.prestosql.sql.planner.SubPlan) NodeInfo(io.airlift.node.NodeInfo) RenameIndexTask(io.prestosql.execution.RenameIndexTask) NodeSystemTable(io.prestosql.connector.system.NodeSystemTable) StateStoreListenerManager(io.prestosql.statestore.listener.StateStoreListenerManager) CreateTable(io.prestosql.sql.tree.CreateTable) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) EventListenerManager(io.prestosql.eventlistener.EventListenerManager) PageIndexerFactory(io.prestosql.spi.PageIndexerFactory) OrderingCompiler(io.prestosql.sql.gen.OrderingCompiler) UNGROUPED_SCHEDULING(io.prestosql.spi.connector.ConnectorSplitManager.SplitSchedulingStrategy.UNGROUPED_SCHEDULING) SchemaPropertyManager(io.prestosql.metadata.SchemaPropertyManager) FileSingleStreamSpillerFactory(io.prestosql.spiller.FileSingleStreamSpillerFactory) TableScanNode(io.prestosql.spi.plan.TableScanNode) TablePropertiesSystemTable(io.prestosql.connector.system.TablePropertiesSystemTable) Metadata(io.prestosql.metadata.Metadata) MetadataManager(io.prestosql.metadata.MetadataManager) LogicalPlanner(io.prestosql.sql.planner.LogicalPlanner) SetSession(io.prestosql.sql.tree.SetSession) UncheckedIOException(java.io.UncheckedIOException) HttpServerInfo(io.airlift.http.server.HttpServerInfo) CreateView(io.prestosql.sql.tree.CreateView) CatalogSystemTable(io.prestosql.connector.system.CatalogSystemTable) Driver(io.prestosql.operator.Driver) PluginManager(io.prestosql.server.PluginManager) PreparedQuery(io.prestosql.execution.QueryPreparer.PreparedQuery) StartTransactionTask(io.prestosql.execution.StartTransactionTask) ExpressionCompiler(io.prestosql.sql.gen.ExpressionCompiler) SetPath(io.prestosql.sql.tree.SetPath) TESTING_CATALOG(io.prestosql.testing.TestingSession.TESTING_CATALOG) DropTableTask(io.prestosql.execution.DropTableTask) DataDefinitionTask(io.prestosql.execution.DataDefinitionTask) NodeScheduler(io.prestosql.execution.scheduler.NodeScheduler) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) InMemoryTransactionManager(io.prestosql.transaction.InMemoryTransactionManager) ArrayList(java.util.ArrayList) CatalogConnectorStore(io.prestosql.connector.CatalogConnectorStore) GroupByHashPageIndexerFactory(io.prestosql.GroupByHashPageIndexerFactory) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) Closer(com.google.common.io.Closer) InMemoryNodeManager(io.prestosql.metadata.InMemoryNodeManager) EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) Session(io.prestosql.Session) PageSourceManager(io.prestosql.split.PageSourceManager) ScheduledSplit(io.prestosql.execution.ScheduledSplit) SessionPropertyDefaults(io.prestosql.server.SessionPropertyDefaults) TransactionsSystemTable(io.prestosql.connector.system.TransactionsSystemTable) Language(org.intellij.lang.annotations.Language) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) CostComparator(io.prestosql.cost.CostComparator) FinalizerService(io.prestosql.util.FinalizerService) CubeManager(io.prestosql.cube.CubeManager) Lock(java.util.concurrent.locks.Lock) JoinFilterFunctionCompiler(io.prestosql.sql.gen.JoinFilterFunctionCompiler) TreeAssertions.assertFormattedSql(io.prestosql.sql.testing.TreeAssertions.assertFormattedSql) HandleResolver(io.prestosql.metadata.HandleResolver) ConnectorFactory(io.prestosql.spi.connector.ConnectorFactory) SplitManager(io.prestosql.split.SplitManager) QualifiedTablePrefix(io.prestosql.metadata.QualifiedTablePrefix) TablePropertyManager(io.prestosql.metadata.TablePropertyManager) TestingMBeanServer(org.weakref.jmx.testing.TestingMBeanServer) StatsNormalizer(io.prestosql.cost.StatsNormalizer) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) Kryo(com.esotericsoftware.kryo.Kryo) AnalyzePropertiesSystemTable(io.prestosql.connector.system.AnalyzePropertiesSystemTable) ServerConfig(io.prestosql.server.ServerConfig) ColumnPropertyManager(io.prestosql.metadata.ColumnPropertyManager) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) Commit(io.prestosql.sql.tree.Commit) ImmutableMap(com.google.common.collect.ImmutableMap) OutputFactory(io.prestosql.operator.OutputFactory) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PluginManagerConfig(io.prestosql.server.PluginManagerConfig) List(java.util.List) ColumnPropertiesSystemTable(io.prestosql.connector.system.ColumnPropertiesSystemTable) TableCommentSystemTable(io.prestosql.connector.system.TableCommentSystemTable) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) Optional(java.util.Optional) Analysis(io.prestosql.sql.analyzer.Analysis) NodeSpillConfig(io.prestosql.spiller.NodeSpillConfig) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) MemoryManagerConfig(io.prestosql.memory.MemoryManagerConfig) LegacyNetworkTopology(io.prestosql.execution.scheduler.LegacyNetworkTopology) CreateTableTask(io.prestosql.execution.CreateTableTask) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) PlanFragmenter(io.prestosql.sql.planner.PlanFragmenter) DropViewTask(io.prestosql.execution.DropViewTask) PrepareTask(io.prestosql.execution.PrepareTask) Verify.verify(com.google.common.base.Verify.verify) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Objects.requireNonNull(java.util.Objects.requireNonNull) PasswordAuthenticatorManager(io.prestosql.server.security.PasswordAuthenticatorManager) PagesIndex(io.prestosql.operator.PagesIndex) ScalarStatsCalculator(io.prestosql.cost.ScalarStatsCalculator) OperatorContext(io.prestosql.operator.OperatorContext) DriverFactory(io.prestosql.operator.DriverFactory) AnalyzePropertyManager(io.prestosql.metadata.AnalyzePropertyManager) GroupProviderManager(io.prestosql.security.GroupProviderManager) PageSorter(io.prestosql.spi.PageSorter) LocalExecutionPlan(io.prestosql.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) Analyzer(io.prestosql.sql.analyzer.Analyzer) TimeUnit(java.util.concurrent.TimeUnit) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) HetuMetaStoreManager(io.prestosql.metastore.HetuMetaStoreManager) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) RenameTableTask(io.prestosql.execution.RenameTableTask) MBeanExporter(org.weakref.jmx.MBeanExporter) Collections(java.util.Collections) TaskContext(io.prestosql.operator.TaskContext) PageConsumerOutputFactory(io.prestosql.testing.PageConsumerOperator.PageConsumerOutputFactory) Driver(io.prestosql.operator.Driver) AtomicReference(java.util.concurrent.atomic.AtomicReference) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Plan(io.prestosql.sql.planner.Plan) SubPlan(io.prestosql.sql.planner.SubPlan) LocalExecutionPlan(io.prestosql.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) OperatorContext(io.prestosql.operator.OperatorContext)

Example 2 with OperatorContext

use of io.prestosql.operator.OperatorContext in project hetu-core by openlookeng.

the class TestSingleInputSnapshotState method testStaticConstructor.

@Test
public void testStaticConstructor() {
    ScheduledExecutorService scheduler = newScheduledThreadPool(4);
    DriverContext driverContext = createTaskContext(scheduler, scheduler, TEST_SNAPSHOT_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    OperatorContext operatorContext = driverContext.addOperatorContext(1, new PlanNodeId("planNodeId"), "test");
    SingleInputSnapshotState singleInputSnapshotState = SingleInputSnapshotState.forOperator(mock(Operator.class), operatorContext);
    singleInputSnapshotState.processPage(regularPage);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Operator(io.prestosql.operator.Operator) DriverContext(io.prestosql.operator.DriverContext) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OperatorContext(io.prestosql.operator.OperatorContext) Test(org.testng.annotations.Test)

Example 3 with OperatorContext

use of io.prestosql.operator.OperatorContext in project hetu-core by openlookeng.

the class TestMemoryRevokingScheduler method testScheduleMemoryRevoking.

@Test
public void testScheduleMemoryRevoking() throws Exception {
    SqlTask sqlTask1 = newSqlTask();
    SqlTask sqlTask2 = newSqlTask();
    TaskContext taskContext1 = sqlTask1.getQueryContext().addTaskContext(new TaskStateMachine(new TaskId("q1", 1, 1), executor), session, false, false, OptionalInt.empty(), Optional.empty(), TESTING_SERDE_FACTORY);
    PipelineContext pipelineContext11 = taskContext1.addPipelineContext(0, false, false, false);
    DriverContext driverContext111 = pipelineContext11.addDriverContext();
    OperatorContext operatorContext1 = driverContext111.addOperatorContext(1, new PlanNodeId("na"), "na");
    OperatorContext operatorContext2 = driverContext111.addOperatorContext(2, new PlanNodeId("na"), "na");
    DriverContext driverContext112 = pipelineContext11.addDriverContext();
    OperatorContext operatorContext3 = driverContext112.addOperatorContext(3, new PlanNodeId("na"), "na");
    TaskContext taskContext2 = sqlTask2.getQueryContext().addTaskContext(new TaskStateMachine(new TaskId("q2", 1, 1), executor), session, false, false, OptionalInt.empty(), Optional.empty(), TESTING_SERDE_FACTORY);
    PipelineContext pipelineContext21 = taskContext2.addPipelineContext(1, false, false, false);
    DriverContext driverContext211 = pipelineContext21.addDriverContext();
    OperatorContext operatorContext4 = driverContext211.addOperatorContext(4, new PlanNodeId("na"), "na");
    OperatorContext operatorContext5 = driverContext211.addOperatorContext(5, new PlanNodeId("na"), "na");
    Collection<SqlTask> tasks = ImmutableList.of(sqlTask1, sqlTask2);
    MemoryRevokingScheduler scheduler = new MemoryRevokingScheduler(singletonList(memoryPool), () -> tasks, executor, 1.0, 1.0, false, new DataSize(512, MEGABYTE).toBytes());
    allOperatorContexts = ImmutableSet.of(operatorContext1, operatorContext2, operatorContext3, operatorContext4, operatorContext5);
    assertMemoryRevokingNotRequested();
    requestMemoryRevoking(scheduler);
    assertEquals(10, memoryPool.getFreeBytes());
    assertMemoryRevokingNotRequested();
    LocalMemoryContext revocableMemory1 = operatorContext1.localRevocableMemoryContext();
    LocalMemoryContext revocableMemory3 = operatorContext3.localRevocableMemoryContext();
    LocalMemoryContext revocableMemory4 = operatorContext4.localRevocableMemoryContext();
    LocalMemoryContext revocableMemory5 = operatorContext5.localRevocableMemoryContext();
    revocableMemory1.setBytes(3);
    revocableMemory3.setBytes(6);
    assertEquals(1, memoryPool.getFreeBytes());
    requestMemoryRevoking(scheduler);
    // we are still good - no revoking needed
    assertMemoryRevokingNotRequested();
    revocableMemory4.setBytes(7);
    assertEquals(-6, memoryPool.getFreeBytes());
    requestMemoryRevoking(scheduler);
    // we need to revoke 3 and 6
    assertMemoryRevokingRequestedFor(operatorContext1, operatorContext3);
    // yet another revoking request should not change anything
    requestMemoryRevoking(scheduler);
    assertMemoryRevokingRequestedFor(operatorContext1, operatorContext3);
    // lets revoke some bytes
    revocableMemory1.setBytes(0);
    operatorContext1.resetMemoryRevokingRequested();
    requestMemoryRevoking(scheduler);
    assertMemoryRevokingRequestedFor(operatorContext3);
    assertEquals(-3, memoryPool.getFreeBytes());
    // and allocate some more
    revocableMemory5.setBytes(3);
    assertEquals(-6, memoryPool.getFreeBytes());
    requestMemoryRevoking(scheduler);
    // we are still good with just OC3 in process of revoking
    assertMemoryRevokingRequestedFor(operatorContext3);
    // and allocate some more
    revocableMemory5.setBytes(4);
    assertEquals(-7, memoryPool.getFreeBytes());
    requestMemoryRevoking(scheduler);
    // no we have to trigger revoking for OC4
    assertMemoryRevokingRequestedFor(operatorContext3, operatorContext4);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) SqlTask.createSqlTask(io.prestosql.execution.SqlTask.createSqlTask) DriverContext(io.prestosql.operator.DriverContext) LocalMemoryContext(io.prestosql.memory.context.LocalMemoryContext) TaskContext(io.prestosql.operator.TaskContext) PipelineContext(io.prestosql.operator.PipelineContext) OperatorContext(io.prestosql.operator.OperatorContext) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 4 with OperatorContext

use of io.prestosql.operator.OperatorContext in project hetu-core by openlookeng.

the class TestMemoryRevokingScheduler method testImmediateMemoryRevoking.

/**
 * Test that when a {@link MemoryPool} is over-allocated, revocable memory is revoked without delay (although asynchronously).
 */
@Test
public void testImmediateMemoryRevoking() throws Exception {
    // Given
    SqlTask sqlTask = newSqlTask();
    OperatorContext operatorContext = createContexts(sqlTask);
    allOperatorContexts = ImmutableSet.of(operatorContext);
    List<SqlTask> tasks = ImmutableList.of(sqlTask);
    MemoryRevokingScheduler scheduler = new MemoryRevokingScheduler(singletonList(memoryPool), () -> tasks, executor, 1.0, 1.0, false, new DataSize(512, MEGABYTE).toBytes());
    // no periodic check initiated
    scheduler.registerPoolListeners();
    // When
    operatorContext.localRevocableMemoryContext().setBytes(12);
    awaitAsynchronousCallbacksRun();
    // Then
    assertMemoryRevokingRequestedFor(operatorContext);
}
Also used : SqlTask.createSqlTask(io.prestosql.execution.SqlTask.createSqlTask) OperatorContext(io.prestosql.operator.OperatorContext) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 5 with OperatorContext

use of io.prestosql.operator.OperatorContext in project hetu-core by openlookeng.

the class TestMemoryRevokingScheduler method createContexts.

private OperatorContext createContexts(SqlTask sqlTask) {
    TaskContext taskContext = sqlTask.getQueryContext().addTaskContext(new TaskStateMachine(new TaskId("q", 1, 1), executor), session, false, false, OptionalInt.empty(), Optional.empty(), TESTING_SERDE_FACTORY);
    PipelineContext pipelineContext = taskContext.addPipelineContext(0, false, false, false);
    DriverContext driverContext = pipelineContext.addDriverContext();
    OperatorContext operatorContext = driverContext.addOperatorContext(1, new PlanNodeId("na"), "na");
    return operatorContext;
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) DriverContext(io.prestosql.operator.DriverContext) TaskContext(io.prestosql.operator.TaskContext) PipelineContext(io.prestosql.operator.PipelineContext) OperatorContext(io.prestosql.operator.OperatorContext)

Aggregations

OperatorContext (io.prestosql.operator.OperatorContext)13 DriverContext (io.prestosql.operator.DriverContext)9 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)8 TaskContext (io.prestosql.operator.TaskContext)7 Test (org.testng.annotations.Test)7 DataSize (io.airlift.units.DataSize)6 ImmutableList (com.google.common.collect.ImmutableList)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 ArrayList (java.util.ArrayList)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Session (io.prestosql.Session)3 List (java.util.List)3 Map (java.util.Map)3 Kryo (com.esotericsoftware.kryo.Kryo)2 Verify.verify (com.google.common.base.Verify.verify)2 MEGABYTE (io.airlift.units.DataSize.Unit.MEGABYTE)2 SqlTask.createSqlTask (io.prestosql.execution.SqlTask.createSqlTask)2 MemoryPool (io.prestosql.memory.MemoryPool)2