Search in sources :

Example 1 with OperatorContext

use of io.trino.operator.OperatorContext in project trino by trinodb.

the class MemoryRevokingScheduler method requestRevoking.

private void requestRevoking(List<SqlTask> sqlTasks, long remainingBytesToRevoke) {
    VoidTraversingQueryContextVisitor<AtomicLong> visitor = new VoidTraversingQueryContextVisitor<>() {

        @Override
        public Void visitPipelineContext(PipelineContext pipelineContext, AtomicLong remainingBytesToRevoke) {
            if (remainingBytesToRevoke.get() <= 0) {
                // exit immediately if no work needs to be done
                return null;
            }
            return super.visitPipelineContext(pipelineContext, remainingBytesToRevoke);
        }

        @Override
        public Void visitOperatorContext(OperatorContext operatorContext, AtomicLong remainingBytesToRevoke) {
            if (remainingBytesToRevoke.get() > 0) {
                long revokedBytes = operatorContext.requestMemoryRevoking();
                if (revokedBytes > 0) {
                    remainingBytesToRevoke.addAndGet(-revokedBytes);
                    log.debug("requested revoking %s; remaining %s", revokedBytes, remainingBytesToRevoke.get());
                }
            }
            return null;
        }
    };
    AtomicLong remainingBytesToRevokeAtomic = new AtomicLong(remainingBytesToRevoke);
    for (SqlTask task : sqlTasks) {
        Optional<TaskContext> taskContext = task.getTaskContext();
        if (taskContext.isPresent()) {
            taskContext.get().accept(visitor, remainingBytesToRevokeAtomic);
            if (remainingBytesToRevokeAtomic.get() <= 0) {
                // No further revoking required
                return;
            }
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TaskContext(io.trino.operator.TaskContext) VoidTraversingQueryContextVisitor(io.trino.memory.VoidTraversingQueryContextVisitor) PipelineContext(io.trino.operator.PipelineContext) OperatorContext(io.trino.operator.OperatorContext)

Example 2 with OperatorContext

use of io.trino.operator.OperatorContext in project trino by trinodb.

the class LocalQueryRunner method executeInternal.

private MaterializedResultWithPlan executeInternal(Session session, @Language("SQL") String sql) {
    lock.readLock().lock();
    try (Closer closer = Closer.create()) {
        accessControl.checkCanExecuteQuery(session.getIdentity());
        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.getNestedOperatorStats().stream().mapToLong(stats -> stats.getRevocableMemoryReservation().toBytes()).sum() > 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) ConnectorManager(io.trino.connector.ConnectorManager) PagesIndexPageSorter(io.trino.operator.PagesIndexPageSorter) TransactionManager(io.trino.transaction.TransactionManager) TransactionManagerConfig(io.trino.transaction.TransactionManagerConfig) FilterStatsCalculator(io.trino.cost.FilterStatsCalculator) FinalizerService(io.trino.util.FinalizerService) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) MaterializedViewPropertiesSystemTable(io.trino.connector.system.MaterializedViewPropertiesSystemTable) HandleResolver(io.trino.metadata.HandleResolver) Map(java.util.Map) MetadataManager(io.trino.metadata.MetadataManager) CostCalculatorUsingExchanges(io.trino.cost.CostCalculatorUsingExchanges) TableScanNode(io.trino.sql.planner.plan.TableScanNode) InMemoryTransactionManager(io.trino.transaction.InMemoryTransactionManager) InjectedFailureType(io.trino.execution.FailureInjector.InjectedFailureType) SplitSource(io.trino.split.SplitSource) SystemSessionPropertiesProvider(io.trino.SystemSessionPropertiesProvider) PreparedQuery(io.trino.execution.QueryPreparer.PreparedQuery) PlanSanityChecker(io.trino.sql.planner.sanity.PlanSanityChecker) Plugin(io.trino.spi.Plugin) NOT_PARTITIONED(io.trino.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED) InternalBlockEncodingSerde(io.trino.metadata.InternalBlockEncodingSerde) SubPlan(io.trino.sql.planner.SubPlan) ShowStatsRewrite(io.trino.sql.rewrite.ShowStatsRewrite) Split(io.trino.metadata.Split) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Session(io.trino.Session) Analyzer(io.trino.sql.analyzer.Analyzer) MaterializedViewSystemTable(io.trino.connector.system.MaterializedViewSystemTable) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) PluginManager(io.trino.server.PluginManager) RuleStatsRecorder(io.trino.sql.planner.RuleStatsRecorder) ColumnPropertiesSystemTable(io.trino.connector.system.ColumnPropertiesSystemTable) ComposableStatsCalculator(io.trino.cost.ComposableStatsCalculator) PageIndexerFactory(io.trino.spi.PageIndexerFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Lifespan(io.trino.execution.Lifespan) StageExecutionDescriptor(io.trino.operator.StageExecutionDescriptor) LocalExecutionPlan(io.trino.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) SpillerStats(io.trino.spiller.SpillerStats) IOException(java.io.IOException) LocalExecutionPlanner(io.trino.sql.planner.LocalExecutionPlanner) FunctionBundle(io.trino.metadata.FunctionBundle) SessionPropertyDefaults(io.trino.server.SessionPropertyDefaults) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) EventListenerManager(io.trino.eventlistener.EventListenerManager) InternalFunctionBundle(io.trino.metadata.InternalFunctionBundle) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) TablePropertyManager(io.trino.metadata.TablePropertyManager) TransactionId(io.trino.transaction.TransactionId) Driver(io.trino.operator.Driver) AllowAllSystemAccessControl(io.trino.plugin.base.security.AllowAllSystemAccessControl) OptimizerConfig(io.trino.sql.planner.OptimizerConfig) AnalyzePropertiesSystemTable(io.trino.connector.system.AnalyzePropertiesSystemTable) ParsingUtil.createParsingOptions(io.trino.sql.ParsingUtil.createParsingOptions) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) TransactionBuilder.transaction(io.trino.transaction.TransactionBuilder.transaction) NodeTaskMap(io.trino.execution.NodeTaskMap) JoinFilterFunctionCompiler(io.trino.sql.gen.JoinFilterFunctionCompiler) InternalTypeManager(io.trino.type.InternalTypeManager) NodeSpillConfig(io.trino.spiller.NodeSpillConfig) Duration(io.airlift.units.Duration) StatsCalculator(io.trino.cost.StatsCalculator) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) DisabledSystemSecurityMetadata(io.trino.metadata.DisabledSystemSecurityMetadata) TreeAssertions.assertFormattedSql(io.trino.sql.testing.TreeAssertions.assertFormattedSql) PageSorter(io.trino.spi.PageSorter) LiteralFunction(io.trino.metadata.LiteralFunction) DescribeInputRewrite(io.trino.sql.rewrite.DescribeInputRewrite) ImmutableSet(com.google.common.collect.ImmutableSet) GroupProviderManager(io.trino.security.GroupProviderManager) NodeSystemTable(io.trino.connector.system.NodeSystemTable) CostComparator(io.trino.cost.CostComparator) Constraint.alwaysTrue(io.trino.spi.connector.Constraint.alwaysTrue) PlanOptimizers(io.trino.sql.planner.PlanOptimizers) ColumnPropertyManager(io.trino.metadata.ColumnPropertyManager) GlobalSystemConnectorFactory(io.trino.connector.system.GlobalSystemConnectorFactory) PlannerContext(io.trino.sql.PlannerContext) Analysis(io.trino.sql.analyzer.Analysis) GlobalFunctionCatalog(io.trino.metadata.GlobalFunctionCatalog) TableCommentSystemTable(io.trino.connector.system.TableCommentSystemTable) FileSingleStreamSpillerFactory(io.trino.spiller.FileSingleStreamSpillerFactory) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) ExchangeHandleResolver(io.trino.metadata.ExchangeHandleResolver) Function(java.util.function.Function) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) GROUPED_SCHEDULING(io.trino.spi.connector.ConnectorSplitManager.SplitSchedulingStrategy.GROUPED_SCHEDULING) ImmutableList(com.google.common.collect.ImmutableList) SystemSessionProperties(io.trino.SystemSessionProperties) TaskContext(io.trino.operator.TaskContext) DynamicFilterConfig(io.trino.execution.DynamicFilterConfig) IndexManager(io.trino.index.IndexManager) ExecutorService(java.util.concurrent.ExecutorService) PagesIndex(io.trino.operator.PagesIndex) TaskCountEstimator(io.trino.cost.TaskCountEstimator) SchemaPropertyManager(io.trino.metadata.SchemaPropertyManager) MetadataUtil(io.trino.metadata.MetadataUtil) TableExecuteContextManager(io.trino.execution.TableExecuteContextManager) GenericSpillerFactory(io.trino.spiller.GenericSpillerFactory) PageSourceManager(io.trino.split.PageSourceManager) FunctionManager(io.trino.metadata.FunctionManager) FeaturesConfig(io.trino.FeaturesConfig) CatalogManager(io.trino.metadata.CatalogManager) WarningCollector(io.trino.execution.warnings.WarningCollector) Plan(io.trino.sql.planner.Plan) TypeManager(io.trino.spi.type.TypeManager) QueryExplainerFactory(io.trino.sql.analyzer.QueryExplainerFactory) SplitAssignment(io.trino.execution.SplitAssignment) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) EMPTY(io.trino.spi.connector.DynamicFilter.EMPTY) TableProceduresPropertyManager(io.trino.metadata.TableProceduresPropertyManager) SchemaPropertiesSystemTable(io.trino.connector.system.SchemaPropertiesSystemTable) NoOpResourceGroupManager(io.trino.execution.resourcegroups.NoOpResourceGroupManager) NodeInfo(io.airlift.node.NodeInfo) TypeOperators(io.trino.spi.type.TypeOperators) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) OperatorContext(io.trino.operator.OperatorContext) PlanNode(io.trino.sql.planner.plan.PlanNode) CatalogName(io.trino.connector.CatalogName) NodeScheduler(io.trino.execution.scheduler.NodeScheduler) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) StatsRulesProvider(io.trino.cost.StatsCalculatorModule.StatsRulesProvider) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PageSinkManager(io.trino.split.PageSinkManager) PasswordAuthenticatorConfig(io.trino.server.security.PasswordAuthenticatorConfig) LogicalPlanner(io.trino.sql.planner.LogicalPlanner) Set(java.util.Set) TrinoOperatorFactories(io.trino.operator.TrinoOperatorFactories) QueryPreparer(io.trino.execution.QueryPreparer) IndexJoinLookupStats(io.trino.operator.index.IndexJoinLookupStats) UncheckedIOException(java.io.UncheckedIOException) TaskManagerConfig(io.trino.execution.TaskManagerConfig) EmbedVersion.testingVersionEmbedder(io.trino.version.EmbedVersion.testingVersionEmbedder) SpillerFactory(io.trino.spiller.SpillerFactory) GlobalSystemConnector(io.trino.connector.system.GlobalSystemConnector) PlanPrinter(io.trino.sql.planner.planprinter.PlanPrinter) PlanNodeSearcher.searchFrom(io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom) ExplainRewrite(io.trino.sql.rewrite.ExplainRewrite) ShowQueriesRewrite(io.trino.sql.rewrite.ShowQueriesRewrite) JoinCompiler(io.trino.sql.gen.JoinCompiler) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) GroupByHashPageIndexerFactory(io.trino.operator.GroupByHashPageIndexerFactory) ArrayList(java.util.ArrayList) TypeRegistry(io.trino.metadata.TypeRegistry) Closer(com.google.common.io.Closer) UNGROUPED_SCHEDULING(io.trino.spi.connector.ConnectorSplitManager.SplitSchedulingStrategy.UNGROUPED_SCHEDULING) SystemFunctionBundle(io.trino.metadata.SystemFunctionBundle) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) EventListenerConfig(io.trino.eventlistener.EventListenerConfig) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) BlockTypeOperators(io.trino.type.BlockTypeOperators) Language(org.intellij.lang.annotations.Language) HeaderAuthenticatorConfig(io.trino.server.security.HeaderAuthenticatorConfig) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) PasswordAuthenticatorManager(io.trino.server.security.PasswordAuthenticatorManager) Lock(java.util.concurrent.locks.Lock) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlanOptimizersFactory(io.trino.sql.planner.PlanOptimizersFactory) NodeMemoryConfig(io.trino.memory.NodeMemoryConfig) DriverFactory(io.trino.operator.DriverFactory) OPTIMIZED_AND_VALIDATED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED) SplitManager(io.trino.split.SplitManager) ParameterUtils.parameterExtractor(io.trino.sql.ParameterUtils.parameterExtractor) TransactionsSystemTable(io.trino.connector.system.TransactionsSystemTable) ErrorType(io.trino.spi.ErrorType) SqlParser(io.trino.sql.parser.SqlParser) StatsNormalizer(io.trino.cost.StatsNormalizer) CertificateAuthenticatorManager(io.trino.server.security.CertificateAuthenticatorManager) ImmutableMap(com.google.common.collect.ImmutableMap) TablePropertiesSystemTable(io.trino.connector.system.TablePropertiesSystemTable) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) PropertyMetadata(io.trino.spi.session.PropertyMetadata) OutputFactory(io.trino.operator.OutputFactory) ScalarStatsCalculator(io.trino.cost.ScalarStatsCalculator) ScheduledSplit(io.trino.execution.ScheduledSplit) UniformNodeSelectorFactory(io.trino.execution.scheduler.UniformNodeSelectorFactory) HeaderAuthenticatorManager(io.trino.server.security.HeaderAuthenticatorManager) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) QueryManagerConfig(io.trino.execution.QueryManagerConfig) List(java.util.List) DriverContext(io.trino.operator.DriverContext) Optional(java.util.Optional) OperatorFactories(io.trino.operator.OperatorFactories) PlanFragmenter(io.trino.sql.planner.PlanFragmenter) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) MemoryManagerConfig(io.trino.memory.MemoryManagerConfig) BlockEncodingManager(io.trino.metadata.BlockEncodingManager) Verify.verify(com.google.common.base.Verify.verify) QueryExplainer(io.trino.sql.analyzer.QueryExplainer) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) DescribeOutputRewrite(io.trino.sql.rewrite.DescribeOutputRewrite) Objects.requireNonNull(java.util.Objects.requireNonNull) PageConsumerOutputFactory(io.trino.testing.PageConsumerOperator.PageConsumerOutputFactory) GenericPartitioningSpillerFactory(io.trino.spiller.GenericPartitioningSpillerFactory) TableProceduresRegistry(io.trino.metadata.TableProceduresRegistry) QualifiedTablePrefix(io.trino.metadata.QualifiedTablePrefix) TimeUnit(java.util.concurrent.TimeUnit) PartitioningSpillerFactory(io.trino.spiller.PartitioningSpillerFactory) CatalogSystemTable(io.trino.connector.system.CatalogSystemTable) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) CostCalculator(io.trino.cost.CostCalculator) ProcedureRegistry(io.trino.metadata.ProcedureRegistry) CostCalculatorWithEstimatedExchanges(io.trino.cost.CostCalculatorWithEstimatedExchanges) Metadata(io.trino.metadata.Metadata) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) TaskContext(io.trino.operator.TaskContext) PageConsumerOutputFactory(io.trino.testing.PageConsumerOperator.PageConsumerOutputFactory) Driver(io.trino.operator.Driver) AtomicReference(java.util.concurrent.atomic.AtomicReference) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SubPlan(io.trino.sql.planner.SubPlan) LocalExecutionPlan(io.trino.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) Plan(io.trino.sql.planner.Plan) OperatorContext(io.trino.operator.OperatorContext)

Example 3 with OperatorContext

use of io.trino.operator.OperatorContext in project trino by trinodb.

the class TestMemoryRevokingScheduler method testScheduleMemoryRevoking.

@Test
public void testScheduleMemoryRevoking() throws Exception {
    QueryContext q1 = getOrCreateQueryContext(new QueryId("q1"));
    QueryContext q2 = getOrCreateQueryContext(new QueryId("q2"));
    SqlTask sqlTask1 = newSqlTask(q1.getQueryId());
    SqlTask sqlTask2 = newSqlTask(q2.getQueryId());
    TaskContext taskContext1 = getOrCreateTaskContext(sqlTask1);
    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 = getOrCreateTaskContext(sqlTask2);
    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(memoryPool, () -> tasks, executor, 1.0, 1.0);
    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.trino.sql.planner.plan.PlanNodeId) SqlTask.createSqlTask(io.trino.execution.SqlTask.createSqlTask) DriverContext(io.trino.operator.DriverContext) LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) TaskContext(io.trino.operator.TaskContext) PipelineContext(io.trino.operator.PipelineContext) QueryId(io.trino.spi.QueryId) OperatorContext(io.trino.operator.OperatorContext) QueryContext(io.trino.memory.QueryContext) Test(org.testng.annotations.Test)

Example 4 with OperatorContext

use of io.trino.operator.OperatorContext in project trino by trinodb.

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(new QueryId("query"));
    OperatorContext operatorContext = createContexts(sqlTask);
    allOperatorContexts = ImmutableSet.of(operatorContext);
    List<SqlTask> tasks = ImmutableList.of(sqlTask);
    MemoryRevokingScheduler scheduler = new MemoryRevokingScheduler(memoryPool, () -> tasks, executor, 1.0, 1.0);
    // no periodic check initiated
    scheduler.registerPoolListeners();
    // When
    operatorContext.localRevocableMemoryContext().setBytes(12);
    awaitAsynchronousCallbacksRun();
    // Then
    assertMemoryRevokingRequestedFor(operatorContext);
}
Also used : SqlTask.createSqlTask(io.trino.execution.SqlTask.createSqlTask) QueryId(io.trino.spi.QueryId) OperatorContext(io.trino.operator.OperatorContext) Test(org.testng.annotations.Test)

Example 5 with OperatorContext

use of io.trino.operator.OperatorContext in project trino by trinodb.

the class TestMemoryRevokingScheduler method createContexts.

private OperatorContext createContexts(SqlTask sqlTask) {
    TaskContext taskContext = getOrCreateTaskContext(sqlTask);
    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.trino.sql.planner.plan.PlanNodeId) DriverContext(io.trino.operator.DriverContext) TaskContext(io.trino.operator.TaskContext) PipelineContext(io.trino.operator.PipelineContext) OperatorContext(io.trino.operator.OperatorContext)

Aggregations

OperatorContext (io.trino.operator.OperatorContext)9 DriverContext (io.trino.operator.DriverContext)6 TaskContext (io.trino.operator.TaskContext)6 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)4 Test (org.testng.annotations.Test)4 ImmutableList (com.google.common.collect.ImmutableList)3 PipelineContext (io.trino.operator.PipelineContext)3 Page (io.trino.spi.Page)3 QueryId (io.trino.spi.QueryId)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Session (io.trino.Session)2 SqlTask.createSqlTask (io.trino.execution.SqlTask.createSqlTask)2 Metadata (io.trino.metadata.Metadata)2 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)2 Split (io.trino.metadata.Split)2 TableHandle (io.trino.metadata.TableHandle)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1