Search in sources :

Example 16 with ResourceGroupId

use of io.trino.spi.resourcegroups.ResourceGroupId in project trino by trinodb.

the class TestQueuesDb method testQueryTypeBasedSelection.

@Test
public void testQueryTypeBasedSelection() throws InterruptedException {
    Session session = testSessionBuilder().setCatalog("tpch").setSchema("sf100000").build();
    QueryId queryId = createQuery(queryRunner, session, "EXPLAIN " + LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, queryId, ImmutableSet.of(RUNNING, FINISHED));
    Optional<ResourceGroupId> resourceGroupId = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getResourceGroupId();
    assertTrue(resourceGroupId.isPresent(), "Query should have a resource group");
    assertEquals(resourceGroupId.get(), createResourceGroupId("explain"));
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) TestQueues.createResourceGroupId(io.trino.execution.TestQueues.createResourceGroupId) QueryId(io.trino.spi.QueryId) H2TestUtil.dashboardSession(io.trino.execution.resourcegroups.db.H2TestUtil.dashboardSession) Session(io.trino.Session) H2TestUtil.adhocSession(io.trino.execution.resourcegroups.db.H2TestUtil.adhocSession) H2TestUtil.rejectingSession(io.trino.execution.resourcegroups.db.H2TestUtil.rejectingSession) Test(org.testng.annotations.Test)

Example 17 with ResourceGroupId

use of io.trino.spi.resourcegroups.ResourceGroupId in project trino by trinodb.

the class TestQueuesDb method testSelectorPriority.

@Test(timeOut = 60_000)
public void testSelectorPriority() throws Exception {
    InternalResourceGroupManager<?> manager = queryRunner.getCoordinator().getResourceGroupManager().get();
    QueryManager queryManager = queryRunner.getCoordinator().getQueryManager();
    DbResourceGroupConfigurationManager dbConfigurationManager = (DbResourceGroupConfigurationManager) manager.getConfigurationManager();
    QueryId firstQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, firstQuery, RUNNING);
    Optional<ResourceGroupId> resourceGroup = queryManager.getFullQueryInfo(firstQuery).getResourceGroupId();
    assertTrue(resourceGroup.isPresent());
    assertEquals(resourceGroup.get().toString(), "global.user-user.dashboard-user");
    // create a new resource group that rejects all queries submitted to it
    dao.insertResourceGroup(8, "reject-all-queries", "1MB", 0, 0, 0, null, null, null, null, null, 3L, TEST_ENVIRONMENT);
    // add a new selector that has a higher priority than the existing dashboard selector and that routes queries to the "reject-all-queries" resource group
    dao.insertSelector(8, 200, "user.*", null, "(?i).*dashboard.*", null, null, null);
    // reload the configuration
    dbConfigurationManager.load();
    QueryId secondQuery = createQuery(queryRunner, dashboardSession(), LONG_LASTING_QUERY);
    waitForQueryState(queryRunner, secondQuery, FAILED);
    DispatchManager dispatchManager = queryRunner.getCoordinator().getDispatchManager();
    BasicQueryInfo basicQueryInfo = dispatchManager.getQueryInfo(secondQuery);
    assertEquals(basicQueryInfo.getErrorCode(), QUERY_QUEUE_FULL.toErrorCode());
}
Also used : DbResourceGroupConfigurationManager(io.trino.plugin.resourcegroups.db.DbResourceGroupConfigurationManager) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) TestQueues.createResourceGroupId(io.trino.execution.TestQueues.createResourceGroupId) DispatchManager(io.trino.dispatcher.DispatchManager) QueryId(io.trino.spi.QueryId) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryManager(io.trino.execution.QueryManager) Test(org.testng.annotations.Test)

Example 18 with ResourceGroupId

use of io.trino.spi.resourcegroups.ResourceGroupId in project trino by trinodb.

the class TestResourceGroupIntegration method waitForGlobalResourceGroup.

public static void waitForGlobalResourceGroup(DistributedQueryRunner queryRunner) throws InterruptedException {
    long startTime = System.nanoTime();
    while (true) {
        SECONDS.sleep(1);
        ResourceGroupInfo global = getResourceGroupManager(queryRunner).tryGetResourceGroupInfo(new ResourceGroupId("global")).orElseThrow(() -> new IllegalStateException("Resource group not found"));
        if (global.getSoftMemoryLimit().toBytes() > 0) {
            break;
        }
        assertLessThan(nanosSince(startTime).roundTo(SECONDS), 60L);
    }
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) ResourceGroupInfo(io.trino.server.ResourceGroupInfo)

Example 19 with ResourceGroupId

use of io.trino.spi.resourcegroups.ResourceGroupId in project trino by trinodb.

the class TestResourceGroupIntegration method testPathToRoot.

@Test
public void testPathToRoot() throws Exception {
    try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
        queryRunner.installPlugin(new ResourceGroupManagerPlugin());
        InternalResourceGroupManager<?> manager = getResourceGroupManager(queryRunner);
        manager.setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
        queryRunner.execute(testSessionBuilder().setCatalog("tpch").setSchema("tiny").setSource("dashboard-foo").build(), "SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
        List<ResourceGroupInfo> path = manager.tryGetPathToRoot(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("global"), "user-user"), "dashboard-user")).orElseThrow(() -> new IllegalStateException("Resource group not found"));
        assertEquals(path.size(), 3);
        assertThat(path.get(1).getSubGroups()).isPresent();
        assertEquals(path.get(2).getId(), new ResourceGroupId("global"));
        assertEquals(path.get(2).getHardConcurrencyLimit(), 100);
        assertThat(path.get(2).getRunningQueries()).isNotPresent();
    }
}
Also used : DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) ResourceGroupManagerPlugin(io.trino.plugin.resourcegroups.ResourceGroupManagerPlugin) ResourceGroupInfo(io.trino.server.ResourceGroupInfo) Test(org.testng.annotations.Test)

Example 20 with ResourceGroupId

use of io.trino.spi.resourcegroups.ResourceGroupId in project trino by trinodb.

the class TestSetSessionTask method testSetSessionWithParameters.

private void testSetSessionWithParameters(String property, Expression expression, String expectedValue, List<Expression> parameters) {
    QualifiedName qualifiedPropName = QualifiedName.of(CATALOG_NAME, property);
    QueryStateMachine stateMachine = QueryStateMachine.begin(Optional.empty(), format("set %s = 'old_value'", qualifiedPropName), Optional.empty(), TEST_SESSION, URI.create("fake://uri"), new ResourceGroupId("test"), false, transactionManager, accessControl, executor, metadata, WarningCollector.NOOP, Optional.empty());
    getFutureValue(new SetSessionTask(plannerContext, accessControl, sessionPropertyManager).execute(new SetSession(qualifiedPropName, expression), stateMachine, parameters, WarningCollector.NOOP));
    Map<String, String> sessionProperties = stateMachine.getSetSessionProperties();
    assertEquals(sessionProperties, ImmutableMap.of(qualifiedPropName.toString(), expectedValue));
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) SetSession(io.trino.sql.tree.SetSession) QualifiedName(io.trino.sql.tree.QualifiedName)

Aggregations

ResourceGroupId (io.trino.spi.resourcegroups.ResourceGroupId)30 Test (org.testng.annotations.Test)17 SelectionCriteria (io.trino.spi.resourcegroups.SelectionCriteria)5 TestQueues.createResourceGroupId (io.trino.execution.TestQueues.createResourceGroupId)4 QueryId (io.trino.spi.QueryId)4 Pattern (java.util.regex.Pattern)4 Session (io.trino.Session)3 AccessControlConfig (io.trino.security.AccessControlConfig)3 AccessControlManager (io.trino.security.AccessControlManager)3 ResourceGroupInfo (io.trino.server.ResourceGroupInfo)3 SelectionContext (io.trino.spi.resourcegroups.SelectionContext)3 InMemoryTransactionManager.createTestTransactionManager (io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)3 TransactionManager (io.trino.transaction.TransactionManager)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 H2TestUtil.adhocSession (io.trino.execution.resourcegroups.db.H2TestUtil.adhocSession)2 H2TestUtil.dashboardSession (io.trino.execution.resourcegroups.db.H2TestUtil.dashboardSession)2 H2TestUtil.rejectingSession (io.trino.execution.resourcegroups.db.H2TestUtil.rejectingSession)2 ResourceGroup (io.trino.spi.resourcegroups.ResourceGroup)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2