Search in sources :

Example 6 with ResourceGroupId

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

the class TestDeallocateTask method executeDeallocate.

private Set<String> executeDeallocate(String statementName, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControl = new AccessControlManager(transactionManager, emptyEventListenerManager(), new AccessControlConfig(), DefaultSystemAccessControl.NAME);
    accessControl.setSystemAccessControls(List.of(AllowAllSystemAccessControl.INSTANCE));
    QueryStateMachine stateMachine = QueryStateMachine.begin(Optional.empty(), sqlString, Optional.empty(), session, URI.create("fake://uri"), new ResourceGroupId("test"), false, transactionManager, accessControl, executor, metadata, WarningCollector.NOOP, Optional.empty());
    Deallocate deallocate = new Deallocate(new Identifier(statementName));
    new DeallocateTask().execute(deallocate, stateMachine, emptyList(), WarningCollector.NOOP);
    return stateMachine.getDeallocatedPreparedStatements();
}
Also used : AccessControlManager(io.trino.security.AccessControlManager) AccessControlConfig(io.trino.security.AccessControlConfig) Identifier(io.trino.sql.tree.Identifier) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) Deallocate(io.trino.sql.tree.Deallocate) TransactionManager(io.trino.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.trino.transaction.InMemoryTransactionManager.createTestTransactionManager)

Example 7 with ResourceGroupId

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

the class TestDbResourceGroupConfigurationManager method testEnvironments.

@Test
public void testEnvironments() {
    H2DaoProvider daoProvider = setup("test_configuration");
    H2ResourceGroupsDao dao = daoProvider.get();
    dao.createResourceGroupsGlobalPropertiesTable();
    dao.createResourceGroupsTable();
    dao.createSelectorsTable();
    String prodEnvironment = "prod";
    String devEnvironment = "dev";
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    // two resource groups are the same except the group for the prod environment has a larger softMemoryLimit
    dao.insertResourceGroup(1, "prod_global", "10MB", 1000, 100, 100, "weighted", null, true, "1h", "1d", null, prodEnvironment);
    dao.insertResourceGroup(2, "dev_global", "1MB", 1000, 100, 100, "weighted", null, true, "1h", "1d", null, devEnvironment);
    dao.insertSelector(1, 1, ".*prod_user.*", null, null, null, null, null);
    dao.insertSelector(2, 2, ".*dev_user.*", null, null, null, null, null);
    // check the prod configuration
    DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager(listener -> {
    }, new DbResourceGroupConfig(), daoProvider.get(), prodEnvironment);
    List<ResourceGroupSpec> groups = manager.getRootGroups();
    assertEquals(groups.size(), 1);
    InternalResourceGroup prodGlobal = new InternalResourceGroup("prod_global", (group, export) -> {
    }, directExecutor());
    manager.configure(prodGlobal, new SelectionContext<>(prodGlobal.getId(), new ResourceGroupIdTemplate("prod_global")));
    assertEqualsResourceGroup(prodGlobal, "10MB", 1000, 100, 100, WEIGHTED, DEFAULT_WEIGHT, true, Duration.ofHours(1), Duration.ofDays(1));
    assertEquals(manager.getSelectors().size(), 1);
    ResourceGroupSelector prodSelector = manager.getSelectors().get(0);
    ResourceGroupId prodResourceGroupId = prodSelector.match(new SelectionCriteria(true, "prod_user", ImmutableSet.of(), Optional.empty(), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty())).get().getResourceGroupId();
    assertEquals(prodResourceGroupId.toString(), "prod_global");
    // check the dev configuration
    manager = new DbResourceGroupConfigurationManager(listener -> {
    }, new DbResourceGroupConfig(), daoProvider.get(), devEnvironment);
    assertEquals(groups.size(), 1);
    InternalResourceGroup devGlobal = new InternalResourceGroup("dev_global", (group, export) -> {
    }, directExecutor());
    manager.configure(devGlobal, new SelectionContext<>(prodGlobal.getId(), new ResourceGroupIdTemplate("dev_global")));
    assertEqualsResourceGroup(devGlobal, "1MB", 1000, 100, 100, WEIGHTED, DEFAULT_WEIGHT, true, Duration.ofHours(1), Duration.ofDays(1));
    assertEquals(manager.getSelectors().size(), 1);
    ResourceGroupSelector devSelector = manager.getSelectors().get(0);
    ResourceGroupId devResourceGroupId = devSelector.match(new SelectionCriteria(true, "dev_user", ImmutableSet.of(), Optional.empty(), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty())).get().getResourceGroupId();
    assertEquals(devResourceGroupId.toString(), "dev_global");
}
Also used : SelectionContext(io.trino.spi.resourcegroups.SelectionContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SchedulingPolicy(io.trino.spi.resourcegroups.SchedulingPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TrinoExceptionAssert.assertTrinoExceptionThrownBy(io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy) ArrayList(java.util.ArrayList) UnableToExecuteStatementException(org.jdbi.v3.core.statement.UnableToExecuteStatementException) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ResourceEstimates(io.trino.spi.session.ResourceEstimates) Duration(java.time.Duration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) InternalResourceGroup(io.trino.execution.resourcegroups.InternalResourceGroup) WEIGHTED(io.trino.spi.resourcegroups.SchedulingPolicy.WEIGHTED) Assert.assertFalse(org.testng.Assert.assertFalse) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) ImmutableSet(com.google.common.collect.ImmutableSet) ResourceGroupSelector(io.trino.plugin.resourcegroups.ResourceGroupSelector) TrinoException(io.trino.spi.TrinoException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ResourceGroupIdTemplate(io.trino.plugin.resourcegroups.ResourceGroupIdTemplate) DEFAULT_WEIGHT(io.trino.execution.resourcegroups.InternalResourceGroup.DEFAULT_WEIGHT) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) FAIR(io.trino.spi.resourcegroups.SchedulingPolicy.FAIR) DataSize(io.airlift.units.DataSize) List(java.util.List) ResourceGroupSpec(io.trino.plugin.resourcegroups.ResourceGroupSpec) SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) StaticSelector(io.trino.plugin.resourcegroups.StaticSelector) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) ResourceGroupSelector(io.trino.plugin.resourcegroups.ResourceGroupSelector) ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) ResourceGroupSpec(io.trino.plugin.resourcegroups.ResourceGroupSpec) ResourceGroupIdTemplate(io.trino.plugin.resourcegroups.ResourceGroupIdTemplate) InternalResourceGroup(io.trino.execution.resourcegroups.InternalResourceGroup) SelectionCriteria(io.trino.spi.resourcegroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 8 with ResourceGroupId

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

the class TestFileResourceGroupConfigurationManager method assertMatch.

private static void assertMatch(FileResourceGroupConfigurationManager manager, SelectionCriteria criteria, String expectedResourceGroup) {
    ResourceGroupId resourceGroupId = match(manager, criteria).getResourceGroupId();
    assertEquals(resourceGroupId.toString(), expectedResourceGroup, format("Expected: '%s' resource group, found: %s", expectedResourceGroup, resourceGroupId));
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId)

Example 9 with ResourceGroupId

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

the class TestFileResourceGroupConfigurationManager method testLegacyConfiguration.

@Test
public void testLegacyConfiguration() {
    FileResourceGroupConfigurationManager manager = parse("resource_groups_config_legacy.json");
    ResourceGroupId globalId = new ResourceGroupId("global");
    ResourceGroup global = new TestingResourceGroup(globalId);
    manager.configure(global, new SelectionContext<>(globalId, new ResourceGroupIdTemplate("global")));
    assertEquals(global.getSoftMemoryLimitBytes(), DataSize.of(3, MEGABYTE).toBytes());
    assertEquals(global.getMaxQueuedQueries(), 99);
    assertEquals(global.getHardConcurrencyLimit(), 42);
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) ResourceGroup(io.trino.spi.resourcegroups.ResourceGroup) Test(org.testng.annotations.Test)

Example 10 with ResourceGroupId

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

the class TestFileResourceGroupConfigurationManager method testConfiguration.

@Test
public void testConfiguration() {
    FileResourceGroupConfigurationManager manager = parse("resource_groups_config.json");
    ResourceGroupId globalId = new ResourceGroupId("global");
    ResourceGroup global = new TestingResourceGroup(globalId);
    manager.configure(global, new SelectionContext<>(globalId, new ResourceGroupIdTemplate("global")));
    assertEquals(global.getSoftMemoryLimitBytes(), DataSize.of(1, MEGABYTE).toBytes());
    assertEquals(global.getSoftCpuLimit(), Duration.ofHours(1));
    assertEquals(global.getHardCpuLimit(), Duration.ofDays(1));
    assertEquals(global.getCpuQuotaGenerationMillisPerSecond(), 1000 * 24);
    assertEquals(global.getMaxQueuedQueries(), 1000);
    assertEquals(global.getHardConcurrencyLimit(), 100);
    assertEquals(global.getSchedulingPolicy(), WEIGHTED);
    assertEquals(global.getSchedulingWeight(), 0);
    assertTrue(global.getJmxExport());
    ResourceGroupId subId = new ResourceGroupId(globalId, "sub");
    ResourceGroup sub = new TestingResourceGroup(subId);
    manager.configure(sub, new SelectionContext<>(subId, new ResourceGroupIdTemplate("global.sub")));
    assertEquals(sub.getSoftMemoryLimitBytes(), DataSize.of(2, MEGABYTE).toBytes());
    assertEquals(sub.getHardConcurrencyLimit(), 3);
    assertEquals(sub.getMaxQueuedQueries(), 4);
    assertNull(sub.getSchedulingPolicy());
    assertEquals(sub.getSchedulingWeight(), 5);
    assertFalse(sub.getJmxExport());
}
Also used : ResourceGroupId(io.trino.spi.resourcegroups.ResourceGroupId) ResourceGroup(io.trino.spi.resourcegroups.ResourceGroup) Test(org.testng.annotations.Test)

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