Search in sources :

Example 1 with InternalResourceGroup

use of io.trino.execution.resourcegroups.InternalResourceGroup in project trino by trinodb.

the class TestQueryStateInfo method testQueryStateInfo.

@Test
public void testQueryStateInfo() {
    InternalResourceGroup root = new InternalResourceGroup("root", (group, export) -> {
    }, directExecutor());
    root.setSoftMemoryLimitBytes(DataSize.of(1, MEGABYTE).toBytes());
    root.setMaxQueuedQueries(40);
    root.setHardConcurrencyLimit(0);
    root.setSchedulingPolicy(WEIGHTED);
    InternalResourceGroup rootA = root.getOrCreateSubGroup("a");
    rootA.setSoftMemoryLimitBytes(DataSize.of(1, MEGABYTE).toBytes());
    rootA.setMaxQueuedQueries(20);
    rootA.setHardConcurrencyLimit(0);
    InternalResourceGroup rootAX = rootA.getOrCreateSubGroup("x");
    rootAX.setSoftMemoryLimitBytes(DataSize.of(1, MEGABYTE).toBytes());
    rootAX.setMaxQueuedQueries(10);
    rootAX.setHardConcurrencyLimit(0);
    // Verify QueryStateInfo for query queued on resource group root.a.y
    QueryStateInfo query = createQueuedQueryStateInfo(new BasicQueryInfo(createQueryInfo("query_root_a_x", QUEUED, "SELECT 1")), Optional.of(rootAX.getId()), Optional.of(ImmutableList.of(rootAX.getInfo(), rootA.getInfo(), root.getInfo())));
    assertEquals(query.getQuery(), "SELECT 1");
    assertEquals(query.getQueryId().toString(), "query_root_a_x");
    assertEquals(query.getQueryState(), QUEUED);
    assertEquals(query.getProgress(), Optional.empty());
    List<ResourceGroupInfo> chainInfo = query.getPathToRoot().get();
    assertEquals(chainInfo.size(), 3);
    ResourceGroupInfo rootAInfo = chainInfo.get(1);
    ResourceGroupInfo expectedRootAInfo = rootA.getInfo();
    assertEquals(rootAInfo.getId(), expectedRootAInfo.getId());
    assertEquals(rootAInfo.getState(), expectedRootAInfo.getState());
    assertEquals(rootAInfo.getNumRunningQueries(), expectedRootAInfo.getNumRunningQueries());
    assertEquals(rootAInfo.getNumQueuedQueries(), expectedRootAInfo.getNumQueuedQueries());
    ResourceGroupInfo actualRootInfo = chainInfo.get(2);
    ResourceGroupInfo expectedRootInfo = root.getInfo();
    assertEquals(actualRootInfo.getId(), expectedRootInfo.getId());
    assertEquals(actualRootInfo.getState(), expectedRootInfo.getState());
    assertEquals(actualRootInfo.getNumRunningQueries(), expectedRootInfo.getNumRunningQueries());
    assertEquals(actualRootInfo.getNumQueuedQueries(), expectedRootInfo.getNumQueuedQueries());
}
Also used : InternalResourceGroup(io.trino.execution.resourcegroups.InternalResourceGroup) QueryStateInfo.createQueuedQueryStateInfo(io.trino.server.QueryStateInfo.createQueuedQueryStateInfo) Test(org.testng.annotations.Test)

Example 2 with InternalResourceGroup

use of io.trino.execution.resourcegroups.InternalResourceGroup 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 3 with InternalResourceGroup

use of io.trino.execution.resourcegroups.InternalResourceGroup in project trino by trinodb.

the class TestDbResourceGroupConfigurationManager method testReconfig.

@Test(timeOut = 60_000)
public void testReconfig() throws Exception {
    H2DaoProvider daoProvider = setup("test_reconfig");
    H2ResourceGroupsDao dao = daoProvider.get();
    dao.createResourceGroupsGlobalPropertiesTable();
    dao.createResourceGroupsTable();
    dao.createSelectorsTable();
    dao.insertResourceGroup(1, "global", "1MB", 1000, 100, 100, "weighted", null, true, "1h", "1d", null, ENVIRONMENT);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, 3, null, 5, null, null, null, 1L, ENVIRONMENT);
    dao.insertSelector(2, 1, null, null, null, null, null, null);
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager(listener -> {
    }, new DbResourceGroupConfig(), daoProvider.get(), ENVIRONMENT);
    manager.start();
    AtomicBoolean exported = new AtomicBoolean();
    InternalResourceGroup global = new InternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor());
    manager.configure(global, new SelectionContext<>(global.getId(), new ResourceGroupIdTemplate("global")));
    InternalResourceGroup globalSub = global.getOrCreateSubGroup("sub");
    manager.configure(globalSub, new SelectionContext<>(globalSub.getId(), new ResourceGroupIdTemplate("global.sub")));
    // Verify record exists
    assertEqualsResourceGroup(globalSub, "2MB", 4, 3, 3, FAIR, 5, false, Duration.ofMillis(Long.MAX_VALUE), Duration.ofMillis(Long.MAX_VALUE));
    dao.updateResourceGroup(2, "sub", "3MB", 2, 1, 1, "weighted", 6, true, "1h", "1d", 1L, ENVIRONMENT);
    do {
        MILLISECONDS.sleep(500);
    } while (globalSub.getJmxExport() == false);
    // Verify update
    assertEqualsResourceGroup(globalSub, "3MB", 2, 1, 1, WEIGHTED, 6, true, Duration.ofHours(1), Duration.ofDays(1));
    // Verify delete
    dao.deleteSelectors(2);
    dao.deleteResourceGroup(2);
    do {
        MILLISECONDS.sleep(500);
    } while (globalSub.getMaxQueuedQueries() != 0 || globalSub.getHardConcurrencyLimit() != 0);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalResourceGroup(io.trino.execution.resourcegroups.InternalResourceGroup) ResourceGroupIdTemplate(io.trino.plugin.resourcegroups.ResourceGroupIdTemplate) Test(org.testng.annotations.Test)

Example 4 with InternalResourceGroup

use of io.trino.execution.resourcegroups.InternalResourceGroup in project trino by trinodb.

the class TestDbResourceGroupConfigurationManager method testMissing.

@Test
public void testMissing() {
    H2DaoProvider daoProvider = setup("test_missing");
    H2ResourceGroupsDao dao = daoProvider.get();
    dao.createResourceGroupsGlobalPropertiesTable();
    dao.createResourceGroupsTable();
    dao.createSelectorsTable();
    dao.insertResourceGroup(1, "global", "1MB", 1000, 100, 100, "weighted", null, true, "1h", "1d", null, ENVIRONMENT);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, 3, null, 5, null, null, null, 1L, ENVIRONMENT);
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    dao.insertSelector(2, 1, null, null, null, null, null, null);
    DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager(listener -> {
    }, new DbResourceGroupConfig(), daoProvider.get(), ENVIRONMENT);
    InternalResourceGroup missing = new InternalResourceGroup("missing", (group, export) -> {
    }, directExecutor());
    assertThatThrownBy(() -> manager.configure(missing, new SelectionContext<>(missing.getId(), new ResourceGroupIdTemplate("missing")))).isInstanceOf(IllegalStateException.class).hasMessage("No matching configuration found for [missing] using [missing]");
}
Also used : InternalResourceGroup(io.trino.execution.resourcegroups.InternalResourceGroup) SelectionContext(io.trino.spi.resourcegroups.SelectionContext) ResourceGroupIdTemplate(io.trino.plugin.resourcegroups.ResourceGroupIdTemplate) Test(org.testng.annotations.Test)

Example 5 with InternalResourceGroup

use of io.trino.execution.resourcegroups.InternalResourceGroup in project trino by trinodb.

the class TestDbResourceGroupConfigurationManager method testConfiguration.

@Test
public void testConfiguration() {
    H2DaoProvider daoProvider = setup("test_configuration");
    H2ResourceGroupsDao dao = daoProvider.get();
    dao.createResourceGroupsGlobalPropertiesTable();
    dao.createResourceGroupsTable();
    dao.createSelectorsTable();
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    dao.insertResourceGroup(1, "global", "1MB", 1000, 100, 100, "weighted", null, true, "1h", "1d", null, ENVIRONMENT);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, 3, null, 5, null, null, null, 1L, ENVIRONMENT);
    dao.insertSelector(2, 1, null, null, null, null, null, null);
    DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager(listener -> {
    }, new DbResourceGroupConfig(), daoProvider.get(), ENVIRONMENT);
    AtomicBoolean exported = new AtomicBoolean();
    InternalResourceGroup global = new InternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor());
    manager.configure(global, new SelectionContext<>(global.getId(), new ResourceGroupIdTemplate("global")));
    assertEqualsResourceGroup(global, "1MB", 1000, 100, 100, WEIGHTED, DEFAULT_WEIGHT, true, Duration.ofHours(1), Duration.ofDays(1));
    exported.set(false);
    InternalResourceGroup sub = global.getOrCreateSubGroup("sub");
    manager.configure(sub, new SelectionContext<>(sub.getId(), new ResourceGroupIdTemplate("global.sub")));
    assertEqualsResourceGroup(sub, "2MB", 4, 3, 3, FAIR, 5, false, Duration.ofMillis(Long.MAX_VALUE), Duration.ofMillis(Long.MAX_VALUE));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalResourceGroup(io.trino.execution.resourcegroups.InternalResourceGroup) ResourceGroupIdTemplate(io.trino.plugin.resourcegroups.ResourceGroupIdTemplate) Test(org.testng.annotations.Test)

Aggregations

InternalResourceGroup (io.trino.execution.resourcegroups.InternalResourceGroup)5 Test (org.testng.annotations.Test)5 ResourceGroupIdTemplate (io.trino.plugin.resourcegroups.ResourceGroupIdTemplate)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 SelectionContext (io.trino.spi.resourcegroups.SelectionContext)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 DataSize (io.airlift.units.DataSize)1 DEFAULT_WEIGHT (io.trino.execution.resourcegroups.InternalResourceGroup.DEFAULT_WEIGHT)1 ResourceGroupSelector (io.trino.plugin.resourcegroups.ResourceGroupSelector)1 ResourceGroupSpec (io.trino.plugin.resourcegroups.ResourceGroupSpec)1 StaticSelector (io.trino.plugin.resourcegroups.StaticSelector)1 QueryStateInfo.createQueuedQueryStateInfo (io.trino.server.QueryStateInfo.createQueuedQueryStateInfo)1 TrinoException (io.trino.spi.TrinoException)1 ResourceGroupId (io.trino.spi.resourcegroups.ResourceGroupId)1 SchedulingPolicy (io.trino.spi.resourcegroups.SchedulingPolicy)1 FAIR (io.trino.spi.resourcegroups.SchedulingPolicy.FAIR)1 WEIGHTED (io.trino.spi.resourcegroups.SchedulingPolicy.WEIGHTED)1 SelectionCriteria (io.trino.spi.resourcegroups.SelectionCriteria)1 ResourceEstimates (io.trino.spi.session.ResourceEstimates)1