Search in sources :

Example 1 with InMemoryNodeManager

use of io.trino.metadata.InMemoryNodeManager in project trino by trinodb.

the class TestTableScanNodePartitioning method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    Session.SessionBuilder sessionBuilder = testSessionBuilder().setCatalog(MOCK_CATALOG).setSchema(TEST_SCHEMA);
    LocalQueryRunner queryRunner = LocalQueryRunner.builder(sessionBuilder.build()).withNodeCountForStats(10).build();
    queryRunner.createCatalog(MOCK_CATALOG, createMockFactory(), ImmutableMap.of());
    queryRunner.getNodePartitioningManager().addPartitioningProvider(new CatalogName(MOCK_CATALOG), new TestPartitioningProvider(new InMemoryNodeManager()));
    return queryRunner;
}
Also used : CatalogName(io.trino.connector.CatalogName) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session) ConnectorSession(io.trino.spi.connector.ConnectorSession) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager)

Example 2 with InMemoryNodeManager

use of io.trino.metadata.InMemoryNodeManager in project trino by trinodb.

the class TaskTestUtils method createTestingPlanner.

public static LocalExecutionPlanner createTestingPlanner() {
    PageSourceManager pageSourceManager = new PageSourceManager();
    pageSourceManager.addConnectorPageSourceProvider(CONNECTOR_ID, new TestingPageSourceProvider());
    // we don't start the finalizer so nothing will be collected, which is ok for a test
    FinalizerService finalizerService = new FinalizerService();
    BlockTypeOperators blockTypeOperators = new BlockTypeOperators(PLANNER_CONTEXT.getTypeOperators());
    NodeScheduler nodeScheduler = new NodeScheduler(new UniformNodeSelectorFactory(new InMemoryNodeManager(), new NodeSchedulerConfig().setIncludeCoordinator(true), new NodeTaskMap(finalizerService)));
    NodePartitioningManager nodePartitioningManager = new NodePartitioningManager(nodeScheduler, blockTypeOperators);
    PageFunctionCompiler pageFunctionCompiler = new PageFunctionCompiler(PLANNER_CONTEXT.getFunctionManager(), 0);
    return new LocalExecutionPlanner(PLANNER_CONTEXT, createTestingTypeAnalyzer(PLANNER_CONTEXT), Optional.empty(), pageSourceManager, new IndexManager(), nodePartitioningManager, new PageSinkManager(), new MockDirectExchangeClientSupplier(), new ExpressionCompiler(PLANNER_CONTEXT.getFunctionManager(), pageFunctionCompiler), pageFunctionCompiler, new JoinFilterFunctionCompiler(PLANNER_CONTEXT.getFunctionManager()), new IndexJoinLookupStats(), new TaskManagerConfig(), new GenericSpillerFactory((types, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }), (types, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }, (types, partitionFunction, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }, new PagesIndex.TestingFactory(false), new JoinCompiler(PLANNER_CONTEXT.getTypeOperators()), new TrinoOperatorFactories(), new OrderingCompiler(PLANNER_CONTEXT.getTypeOperators()), new DynamicFilterConfig(), blockTypeOperators, new TableExecuteContextManager(), new ExchangeManagerRegistry(new ExchangeHandleResolver()));
}
Also used : PlanFragment(io.trino.sql.planner.PlanFragment) JoinFilterFunctionCompiler(io.trino.sql.gen.JoinFilterFunctionCompiler) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) CatalogName(io.trino.connector.CatalogName) NodeScheduler(io.trino.execution.scheduler.NodeScheduler) FinalizerService(io.trino.util.FinalizerService) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) SINGLE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ImmutableMap(com.google.common.collect.ImmutableMap) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PageSinkManager(io.trino.split.PageSinkManager) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) TrinoOperatorFactories(io.trino.operator.TrinoOperatorFactories) UniformNodeSelectorFactory(io.trino.execution.scheduler.UniformNodeSelectorFactory) IndexJoinLookupStats(io.trino.operator.index.IndexJoinLookupStats) SplitMonitor(io.trino.event.SplitMonitor) MockDirectExchangeClientSupplier(io.trino.execution.TestSqlTaskManager.MockDirectExchangeClientSupplier) List(java.util.List) BIGINT(io.trino.spi.type.BigintType.BIGINT) Split(io.trino.metadata.Split) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Optional(java.util.Optional) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) JoinCompiler(io.trino.sql.gen.JoinCompiler) ExchangeHandleResolver(io.trino.metadata.ExchangeHandleResolver) Partitioning(io.trino.sql.planner.Partitioning) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) StatsAndCosts(io.trino.cost.StatsAndCosts) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) TestingSplit(io.trino.testing.TestingSplit) StageExecutionDescriptor.ungroupedExecution(io.trino.operator.StageExecutionDescriptor.ungroupedExecution) EventListenerConfig(io.trino.eventlistener.EventListenerConfig) IndexManager(io.trino.index.IndexManager) PagesIndex(io.trino.operator.PagesIndex) Symbol(io.trino.sql.planner.Symbol) BlockTypeOperators(io.trino.type.BlockTypeOperators) GenericSpillerFactory(io.trino.spiller.GenericSpillerFactory) PageSourceManager(io.trino.split.PageSourceManager) LocalExecutionPlanner(io.trino.sql.planner.LocalExecutionPlanner) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) EventListenerManager(io.trino.eventlistener.EventListenerManager) TEST_TABLE_HANDLE(io.trino.testing.TestingHandles.TEST_TABLE_HANDLE) OutputBuffers(io.trino.execution.buffer.OutputBuffers) SOURCE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) MockDirectExchangeClientSupplier(io.trino.execution.TestSqlTaskManager.MockDirectExchangeClientSupplier) TrinoOperatorFactories(io.trino.operator.TrinoOperatorFactories) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PagesIndex(io.trino.operator.PagesIndex) PageSourceManager(io.trino.split.PageSourceManager) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) ExchangeHandleResolver(io.trino.metadata.ExchangeHandleResolver) BlockTypeOperators(io.trino.type.BlockTypeOperators) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) NodeScheduler(io.trino.execution.scheduler.NodeScheduler) GenericSpillerFactory(io.trino.spiller.GenericSpillerFactory) PageSinkManager(io.trino.split.PageSinkManager) JoinCompiler(io.trino.sql.gen.JoinCompiler) LocalExecutionPlanner(io.trino.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(io.trino.operator.index.IndexJoinLookupStats) UniformNodeSelectorFactory(io.trino.execution.scheduler.UniformNodeSelectorFactory) JoinFilterFunctionCompiler(io.trino.sql.gen.JoinFilterFunctionCompiler) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) IndexManager(io.trino.index.IndexManager) FinalizerService(io.trino.util.FinalizerService) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler)

Example 3 with InMemoryNodeManager

use of io.trino.metadata.InMemoryNodeManager in project trino by trinodb.

the class TestFullNodeCapableNodeAllocator method testRemoveAssignedFullNode.

@Test(timeOut = TEST_TIMEOUT)
public void testRemoveAssignedFullNode() throws Exception {
    InMemoryNodeManager nodeManager = testingNodeManager(basicNodesMap(NODE_1, NODE_2));
    setupNodeAllocatorService(nodeManager, 1);
    try (NodeAllocator nodeAllocator = nodeAllocatorService.getNodeAllocator(Q1_SESSION)) {
        NodeAllocator.NodeLease sharedAcquire1 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(sharedAcquire1);
        NodeAllocator.NodeLease sharedAcquire2 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(sharedAcquire2);
        InternalNode nodeAcquired1 = sharedAcquire1.getNode().get().getNode();
        InternalNode nodeAcquired2 = sharedAcquire2.getNode().get().getNode();
        assertNotEquals(nodeAcquired1, nodeAcquired2);
        // try to acquire full node; should not happen
        NodeAllocator.NodeLease fullAcquire = nodeAllocator.acquire(FULL_NODE_REQUIREMENTS);
        assertNotAcquired(fullAcquire);
        Set<InternalNode> pendingFullNodes = nodeAllocatorService.getPendingFullNodes();
        InternalNode pendingFullNode = Iterables.getOnlyElement(pendingFullNodes);
        // remove assigned node and release shared allocation for it; full node acquire still should not be fulfilled
        nodeManager.removeNode(pendingFullNode);
        sharedAcquire1.release();
        assertNotAcquired(fullAcquire);
        // release remaining node in the cluster
        sharedAcquire2.release();
        // full node should be fulfilled now
        assertEventually(() -> {
            // we need to wait as pending acquires are processed asynchronously
            assertAcquired(fullAcquire, nodeAcquired2);
        });
    }
}
Also used : InternalNode(io.trino.metadata.InternalNode) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Test(org.testng.annotations.Test)

Example 4 with InMemoryNodeManager

use of io.trino.metadata.InMemoryNodeManager in project trino by trinodb.

the class TestFullNodeCapableNodeAllocator method testNoFullNodeAvailable.

@Test(timeOut = TEST_TIMEOUT)
public void testNoFullNodeAvailable() throws Exception {
    InMemoryNodeManager nodeManager = testingNodeManager(nodesMapBuilder().put(NODE_1, ImmutableList.of(CATALOG_2)).buildOrThrow());
    setupNodeAllocatorService(nodeManager, 100);
    try (NodeAllocator nodeAllocator = nodeAllocatorService.getNodeAllocator(Q1_SESSION)) {
        // request a full node with specific catalog (not present)
        assertThatThrownBy(() -> nodeAllocator.acquire(FULL_NODE_CATALOG_1_REQUIREMENTS)).hasMessage("No nodes available to run query");
        // add node with specific catalog
        addNode(nodeManager, NODE_2, CATALOG_1);
        // we should be able to acquire the node now
        NodeAllocator.NodeLease acquire1 = nodeAllocator.acquire(FULL_NODE_CATALOG_1_REQUIREMENTS);
        assertAcquired(acquire1, NODE_2);
        // acquiring one more should block (all nodes with catalog already used)
        NodeAllocator.NodeLease acquire2 = nodeAllocator.acquire(FULL_NODE_CATALOG_1_REQUIREMENTS);
        assertNotAcquired(acquire2);
        // remove node with catalog
        nodeManager.removeNode(NODE_2);
        // TODO: make FullNodeCapableNodeAllocatorService react on node removed automatically
        nodeAllocatorService.wakeupProcessPendingAcquires();
        // pending acquire2 should be completed now but with an exception
        assertEventually(() -> {
            assertFalse(acquire2.getNode().isCancelled());
            assertTrue(acquire2.getNode().isDone());
            assertThatThrownBy(() -> getFutureValue(acquire2.getNode())).hasMessage("No nodes available to run query");
        });
    }
}
Also used : InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Test(org.testng.annotations.Test)

Example 5 with InMemoryNodeManager

use of io.trino.metadata.InMemoryNodeManager in project trino by trinodb.

the class TestFullNodeCapableNodeAllocator method testAllocateFullSimple.

private void testAllocateFullSimple(NodeRequirements fullNodeRequirements) throws Exception {
    InMemoryNodeManager nodeManager = testingNodeManager(basicNodesMap(NODE_1, NODE_2));
    setupNodeAllocatorService(nodeManager, 3);
    try (NodeAllocator nodeAllocator = nodeAllocatorService.getNodeAllocator(Q1_SESSION)) {
        // allocate 2 full nodes should not block
        NodeAllocator.NodeLease acquire1 = nodeAllocator.acquire(fullNodeRequirements);
        assertAcquired(acquire1);
        NodeAllocator.NodeLease acquire2 = nodeAllocator.acquire(fullNodeRequirements);
        assertAcquired(acquire2);
        // trying to allocate third full node should block
        NodeAllocator.NodeLease acquire3 = nodeAllocator.acquire(fullNodeRequirements);
        assertNotAcquired(acquire3);
        // third acquisition should unblock if one of old ones is released
        acquire1.release();
        assertEventually(() -> {
            assertAcquired(acquire3);
            assertEquals(acquire3.getNode().get().getNode(), acquire1.getNode().get().getNode());
        });
        // both nodes are used exclusively so we should no be able to acquire shared node
        NodeAllocator.NodeLease acquire4 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertNotAcquired(acquire4);
        // shared acquisition should unblock if one of full ones is released
        acquire2.release();
        assertEventually(() -> {
            assertAcquired(acquire4);
            assertEquals(acquire4.getNode().get().getNode(), acquire2.getNode().get().getNode());
        });
        // shared acquisition should block full acquisition
        NodeAllocator.NodeLease acquire5 = nodeAllocator.acquire(fullNodeRequirements);
        assertNotAcquired(acquire5);
        // and when shared acquisition is gone full node should be acquired
        acquire4.release();
        assertEventually(() -> {
            assertAcquired(acquire5);
            assertEquals(acquire5.getNode().get().getNode(), acquire4.getNode().get().getNode());
        });
    }
}
Also used : InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager)

Aggregations

InMemoryNodeManager (io.trino.metadata.InMemoryNodeManager)28 Test (org.testng.annotations.Test)20 InternalNode (io.trino.metadata.InternalNode)7 NodeTaskMap (io.trino.execution.NodeTaskMap)6 NodeScheduler (io.trino.execution.scheduler.NodeScheduler)5 NodeSchedulerConfig (io.trino.execution.scheduler.NodeSchedulerConfig)5 UniformNodeSelectorFactory (io.trino.execution.scheduler.UniformNodeSelectorFactory)5 PlanFragment (io.trino.sql.planner.PlanFragment)5 CatalogName (io.trino.connector.CatalogName)4 MockRemoteTask (io.trino.execution.MockRemoteTaskFactory.MockRemoteTask)4 PartitionedSplitsInfo (io.trino.execution.PartitionedSplitsInfo)4 RemoteTask (io.trino.execution.RemoteTask)4 PipelinedStageExecution.createPipelinedStageExecution (io.trino.execution.scheduler.PipelinedStageExecution.createPipelinedStageExecution)4 SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler (io.trino.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler)4 TestingSplit (io.trino.testing.TestingSplit)4 FinalizerService (io.trino.util.FinalizerService)4 ImmutableList (com.google.common.collect.ImmutableList)3 NodePartitioningManager (io.trino.sql.planner.NodePartitioningManager)3 BlockTypeOperators (io.trino.type.BlockTypeOperators)3 ImmutableMap (com.google.common.collect.ImmutableMap)2