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();
}
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");
}
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));
}
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);
}
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());
}
Aggregations