Search in sources :

Example 6 with InMemoryNodeManager

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

the class TestFullNodeCapableNodeAllocator method testAllocateFullOpportunistic.

@Test(timeOut = TEST_TIMEOUT)
public void testAllocateFullOpportunistic() throws Exception {
    InMemoryNodeManager nodeManager = testingNodeManager(basicNodesMap(NODE_1, NODE_2));
    setupNodeAllocatorService(nodeManager, 2);
    try (NodeAllocator nodeAllocator = nodeAllocatorService.getNodeAllocator(Q1_SESSION)) {
        // allocate both nodes as shared
        NodeAllocator.NodeLease shared1 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(shared1);
        NodeAllocator.NodeLease shared2 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(shared2);
        // try to allocate 2 full nodes - will block as both nodes in cluster are used
        NodeAllocator.NodeLease full1 = nodeAllocator.acquire(FULL_NODE_REQUIREMENTS);
        assertNotAcquired(full1);
        NodeAllocator.NodeLease full2 = nodeAllocator.acquire(FULL_NODE_REQUIREMENTS);
        assertNotAcquired(full2);
        // add new node to the cluster
        addNode(nodeManager, NODE_3);
        // TODO: make FullNodeCapableNodeAllocatorService react on new node added automatically
        nodeAllocatorService.wakeupProcessPendingAcquires();
        // one of the full1/full2 should be not blocked now
        assertEventually(() -> assertTrue(full1.getNode().isDone() ^ full2.getNode().isDone(), "exactly one of full1/full2 should be unblocked"));
        NodeAllocator.NodeLease fullBlocked = full1.getNode().isDone() ? full2 : full1;
        NodeAllocator.NodeLease fullNotBlocked = full1.getNode().isDone() ? full1 : full2;
        // and when unblocked one releases node the other should grab it
        fullNotBlocked.release();
        nodeAllocatorService.wakeupProcessPendingAcquires();
        assertEventually(() -> assertAcquired(fullBlocked));
    }
}
Also used : InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Test(org.testng.annotations.Test)

Example 7 with InMemoryNodeManager

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

the class TestFullNodeCapableNodeAllocator method testAllocateFullWithQueryLimitAndCatalogRequirements.

@Test(timeOut = TEST_TIMEOUT)
public void testAllocateFullWithQueryLimitAndCatalogRequirements() throws Exception {
    InMemoryNodeManager nodeManager = testingNodeManager(nodesMapBuilder().put(NODE_1, ImmutableList.of(CATALOG_1)).put(NODE_2, ImmutableList.of(CATALOG_1)).put(NODE_3, ImmutableList.of(CATALOG_2)).put(NODE_4, ImmutableList.of(CATALOG_2)).buildOrThrow());
    setupNodeAllocatorService(nodeManager, 2);
    try (NodeAllocator nodeAllocator = nodeAllocatorService.getNodeAllocator(Q1_SESSION)) {
        // allocate 2 full nodes for Q1 should not block
        NodeAllocator.NodeLease acquire1 = nodeAllocator.acquire(FULL_NODE_CATALOG_1_REQUIREMENTS);
        assertAcquired(acquire1);
        NodeAllocator.NodeLease acquire2 = nodeAllocator.acquire(FULL_NODE_CATALOG_2_REQUIREMENTS);
        assertAcquired(acquire2);
        // another allocation for CATALOG_1 will block (per query limit is 2)
        NodeAllocator.NodeLease acquire3 = nodeAllocator.acquire(FULL_NODE_CATALOG_1_REQUIREMENTS);
        assertNotAcquired(acquire3);
        // releasing CATALOG_2 node for query will unblock pending lease for CATALOG_1
        acquire2.release();
        assertEventually(() -> assertAcquired(acquire3));
    }
}
Also used : InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Test(org.testng.annotations.Test)

Example 8 with InMemoryNodeManager

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

the class TestFullNodeCapableNodeAllocator method testAllocateSharedSimple.

@Test(timeOut = TEST_TIMEOUT)
public void testAllocateSharedSimple() throws Exception {
    InMemoryNodeManager nodeManager = testingNodeManager(basicNodesMap(NODE_1, NODE_2));
    setupNodeAllocatorService(nodeManager, 1);
    try (NodeAllocator nodeAllocator = nodeAllocatorService.getNodeAllocator(Q1_SESSION)) {
        // first two allocation should not block
        NodeAllocator.NodeLease acquire1 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(acquire1);
        NodeAllocator.NodeLease acquire2 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(acquire2);
        // and different nodes should be assigned for each
        assertThat(Set.of(acquire1.getNode().get().getNode(), acquire2.getNode().get().getNode())).containsExactlyInAnyOrder(NODE_1, NODE_2);
        // same for subsequent two allocation (each task requires 32GB and we have 2 nodes with 64GB each)
        NodeAllocator.NodeLease acquire3 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(acquire3);
        NodeAllocator.NodeLease acquire4 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertAcquired(acquire4);
        assertThat(Set.of(acquire3.getNode().get().getNode(), acquire4.getNode().get().getNode())).containsExactlyInAnyOrder(NODE_1, NODE_2);
        // 5th allocation should block
        NodeAllocator.NodeLease acquire5 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertNotAcquired(acquire5);
        // release acquire2 which uses
        acquire2.release();
        assertEventually(() -> {
            // we need to wait as pending acquires are processed asynchronously
            assertAcquired(acquire5);
            assertEquals(acquire5.getNode().get().getNode(), acquire2.getNode().get().getNode());
        });
        // try to acquire one more node (should block)
        NodeAllocator.NodeLease acquire6 = nodeAllocator.acquire(NO_REQUIREMENTS);
        assertNotAcquired(acquire6);
        // add new node
        addNode(nodeManager, NODE_3);
        // TODO: make FullNodeCapableNodeAllocatorService react on new node added automatically
        nodeAllocatorService.wakeupProcessPendingAcquires();
        // new node should be assigned
        assertEventually(() -> {
            assertAcquired(acquire6);
            assertEquals(acquire6.getNode().get().getNode(), NODE_3);
        });
    }
}
Also used : InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Test(org.testng.annotations.Test)

Example 9 with InMemoryNodeManager

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

the class TestFullNodeCapableNodeAllocator method testRemoveAcquiredFullNode.

@Test(timeOut = TEST_TIMEOUT)
public void testRemoveAcquiredFullNode() throws Exception {
    InMemoryNodeManager nodeManager = testingNodeManager(basicNodesMap(NODE_1));
    setupNodeAllocatorService(nodeManager, 1);
    try (NodeAllocator nodeAllocator = nodeAllocatorService.getNodeAllocator(Q1_SESSION)) {
        NodeAllocator.NodeLease acquire1 = nodeAllocator.acquire(FULL_NODE_REQUIREMENTS);
        assertAcquired(acquire1, NODE_1);
        // remove acquired node
        nodeManager.removeNode(NODE_1);
        // we should still be able to release lease for removed node
        acquire1.release();
    }
}
Also used : InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) Test(org.testng.annotations.Test)

Example 10 with InMemoryNodeManager

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

the class TestFullNodeCapableNodeAllocator method testingNodeManager.

private InMemoryNodeManager testingNodeManager(Map<InternalNode, List<CatalogName>> nodeMap) {
    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    for (Map.Entry<InternalNode, List<CatalogName>> entry : nodeMap.entrySet()) {
        InternalNode node = entry.getKey();
        List<CatalogName> catalogs = entry.getValue();
        for (CatalogName catalog : catalogs) {
            nodeManager.addNode(catalog, node);
        }
    }
    return nodeManager;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) CatalogName(io.trino.connector.CatalogName) InternalNode(io.trino.metadata.InternalNode) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) 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