Search in sources :

Example 1 with DbManagerSpecProvider

use of com.facebook.presto.resourceGroups.db.DbManagerSpecProvider in project presto by prestodb.

the class TestReloadingResourceGroupConfigurationManager method testMissing.

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No matching configuration found for: missing")
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", "1h", "1MB", "1h", null, ENVIRONMENT);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, 3, null, 5, null, null, null, null, null, null, 1L, ENVIRONMENT);
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    dao.insertSelector(2, 1, null, null, null, null, null);
    DbManagerSpecProvider dbManagerSpecProvider = new DbManagerSpecProvider(daoProvider.get(), ENVIRONMENT, new ReloadingResourceGroupConfig());
    ReloadingResourceGroupConfigurationManager manager = new ReloadingResourceGroupConfigurationManager((poolId, listener) -> {
    }, new ReloadingResourceGroupConfig(), dbManagerSpecProvider);
    InternalResourceGroup missing = new InternalResourceGroup.RootInternalResourceGroup("missing", (group, export) -> {
    }, directExecutor(), ignored -> Optional.empty(), rg -> false);
    manager.configure(missing, new SelectionContext<>(missing.getId(), new VariableMap(ImmutableMap.of("USER", "user"))));
}
Also used : H2DaoProvider(com.facebook.presto.resourceGroups.db.H2DaoProvider) InternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup) VariableMap(com.facebook.presto.resourceGroups.VariableMap) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) DbManagerSpecProvider(com.facebook.presto.resourceGroups.db.DbManagerSpecProvider) Test(org.testng.annotations.Test)

Example 2 with DbManagerSpecProvider

use of com.facebook.presto.resourceGroups.db.DbManagerSpecProvider in project presto by prestodb.

the class TestReloadingResourceGroupConfigurationManager method testExactMatchSelector.

@Test
public void testExactMatchSelector() {
    H2DaoProvider daoProvider = setup("test_exact_match_selector");
    H2ResourceGroupsDao dao = daoProvider.get();
    dao.createResourceGroupsGlobalPropertiesTable();
    dao.createResourceGroupsTable();
    dao.createSelectorsTable();
    dao.createExactMatchSelectorsTable();
    dao.insertResourceGroup(1, "global", "1MB", 1000, 100, 100, "weighted", null, true, "1h", "1d", null, null, null, null, ENVIRONMENT);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, 3, null, 5, null, null, null, null, null, null, 1L, ENVIRONMENT);
    dao.insertSelector(2, 1, null, null, null, null, null);
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    ReloadingResourceGroupConfig config = new ReloadingResourceGroupConfig();
    config.setExactMatchSelectorEnabled(true);
    DbManagerSpecProvider dbManagerSpecProvider = new DbManagerSpecProvider(daoProvider.get(), ENVIRONMENT, config);
    ReloadingResourceGroupConfigurationManager manager = new ReloadingResourceGroupConfigurationManager((poolId, listener) -> {
    }, config, dbManagerSpecProvider);
    manager.load();
    assertEquals(manager.getSelectors().size(), 2);
    assertTrue(manager.getSelectors().get(0) instanceof DbSourceExactMatchSelector);
    config.setExactMatchSelectorEnabled(false);
    manager = new ReloadingResourceGroupConfigurationManager((poolId, listener) -> {
    }, config, dbManagerSpecProvider);
    manager.load();
    assertEquals(manager.getSelectors().size(), 1);
    assertFalse(manager.getSelectors().get(0) instanceof DbSourceExactMatchSelector);
}
Also used : DbManagerSpecProvider(com.facebook.presto.resourceGroups.db.DbManagerSpecProvider) DEFAULT_WEIGHT(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.DEFAULT_WEIGHT) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) MINUTES(java.util.concurrent.TimeUnit.MINUTES) VariableMap(com.facebook.presto.resourceGroups.VariableMap) PrestoException(com.facebook.presto.spi.PrestoException) Duration(io.airlift.units.Duration) H2DaoProvider(com.facebook.presto.resourceGroups.db.H2DaoProvider) ResourceEstimates(com.facebook.presto.spi.session.ResourceEstimates) ResourceGroupQueryLimits(com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DAYS(java.util.concurrent.TimeUnit.DAYS) NO_LIMITS(com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits.NO_LIMITS) InternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.fail(org.testng.Assert.fail) SchedulingPolicy(com.facebook.presto.spi.resourceGroups.SchedulingPolicy) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) DbResourceGroupConfig(com.facebook.presto.resourceGroups.db.DbResourceGroupConfig) WEIGHTED(com.facebook.presto.spi.resourceGroups.SchedulingPolicy.WEIGHTED) DbSourceExactMatchSelector(com.facebook.presto.resourceGroups.db.DbSourceExactMatchSelector) Optional(java.util.Optional) FAIR(com.facebook.presto.spi.resourceGroups.SchedulingPolicy.FAIR) HOURS(java.util.concurrent.TimeUnit.HOURS) Assert.assertTrue(org.testng.Assert.assertTrue) H2DaoProvider(com.facebook.presto.resourceGroups.db.H2DaoProvider) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) DbSourceExactMatchSelector(com.facebook.presto.resourceGroups.db.DbSourceExactMatchSelector) DbManagerSpecProvider(com.facebook.presto.resourceGroups.db.DbManagerSpecProvider) Test(org.testng.annotations.Test)

Example 3 with DbManagerSpecProvider

use of com.facebook.presto.resourceGroups.db.DbManagerSpecProvider in project presto by prestodb.

the class TestReloadingResourceGroupConfigurationManager method testInvalidConfiguration.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "No selectors are configured")
public void testInvalidConfiguration() {
    H2DaoProvider daoProvider = setup("selectors");
    H2ResourceGroupsDao dao = daoProvider.get();
    dao.createResourceGroupsTable();
    dao.createSelectorsTable();
    dao.insertResourceGroup(1, "global", "100%", 100, 100, 100, null, null, null, null, null, null, null, null, null, ENVIRONMENT);
    DbManagerSpecProvider dbManagerSpecProvider = new DbManagerSpecProvider(daoProvider.get(), ENVIRONMENT, new ReloadingResourceGroupConfig());
    ReloadingResourceGroupConfigurationManager manager = new ReloadingResourceGroupConfigurationManager((poolId, listener) -> {
    }, new ReloadingResourceGroupConfig().setMaxRefreshInterval(Duration.valueOf("1ms")), dbManagerSpecProvider);
    manager.getSelectors();
}
Also used : H2DaoProvider(com.facebook.presto.resourceGroups.db.H2DaoProvider) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) DbManagerSpecProvider(com.facebook.presto.resourceGroups.db.DbManagerSpecProvider) Test(org.testng.annotations.Test)

Example 4 with DbManagerSpecProvider

use of com.facebook.presto.resourceGroups.db.DbManagerSpecProvider in project presto by prestodb.

the class TestReloadingResourceGroupConfigurationManager 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", "1h", "1MB", "1h", null, ENVIRONMENT);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, 3, null, 5, null, null, null, null, null, null, 1L, ENVIRONMENT);
    dao.insertSelector(2, 1, null, null, null, null, null);
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    DbManagerSpecProvider dbManagerSpecProvider = new DbManagerSpecProvider(daoProvider.get(), ENVIRONMENT, new ReloadingResourceGroupConfig());
    ReloadingResourceGroupConfigurationManager manager = new ReloadingResourceGroupConfigurationManager((poolId, listener) -> {
    }, new ReloadingResourceGroupConfig(), dbManagerSpecProvider);
    manager.start();
    AtomicBoolean exported = new AtomicBoolean();
    InternalResourceGroup global = new InternalResourceGroup.RootInternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor(), ignored -> Optional.empty(), rg -> false);
    manager.configure(global, new SelectionContext<>(global.getId(), new VariableMap(ImmutableMap.of("USER", "user"))));
    InternalResourceGroup globalSub = global.getOrCreateSubGroup("sub", true);
    manager.configure(globalSub, new SelectionContext<>(globalSub.getId(), new VariableMap(ImmutableMap.of("USER", "user"))));
    // Verify record exists
    assertEqualsResourceGroup(globalSub, "2MB", 4, 3, 3, FAIR, 5, false, new Duration(Long.MAX_VALUE, MILLISECONDS), new Duration(Long.MAX_VALUE, MILLISECONDS), NO_LIMITS);
    dao.updateResourceGroup(2, "sub", "3MB", 2, 1, 1, "weighted", 6, true, "1h", "1d", "1h", "1MB", "30m", 1L, ENVIRONMENT);
    do {
        MILLISECONDS.sleep(500);
    } while (globalSub.getJmxExport() == false);
    // Verify update
    assertEqualsResourceGroup(globalSub, "3MB", 2, 1, 1, WEIGHTED, 6, true, new Duration(1, HOURS), new Duration(1, DAYS), new ResourceGroupQueryLimits(Optional.of(new Duration(1, HOURS)), Optional.of(new DataSize(1, MEGABYTE)), Optional.of(new Duration(30, MINUTES))));
    // Verify delete
    dao.deleteSelectors(2);
    dao.deleteResourceGroup(2);
    do {
        MILLISECONDS.sleep(500);
    } while (globalSub.getMaxQueuedQueries() != 0 || globalSub.getHardConcurrencyLimit() != 0);
}
Also used : Duration(io.airlift.units.Duration) DbManagerSpecProvider(com.facebook.presto.resourceGroups.db.DbManagerSpecProvider) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) H2DaoProvider(com.facebook.presto.resourceGroups.db.H2DaoProvider) InternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup) VariableMap(com.facebook.presto.resourceGroups.VariableMap) ResourceGroupQueryLimits(com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits) DataSize(io.airlift.units.DataSize) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) Test(org.testng.annotations.Test)

Example 5 with DbManagerSpecProvider

use of com.facebook.presto.resourceGroups.db.DbManagerSpecProvider in project presto by prestodb.

the class TestReloadingResourceGroupConfigurationManager 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", "1h", "1MB", "1h", null, ENVIRONMENT);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, 3, null, 5, null, null, null, null, null, null, 1L, ENVIRONMENT);
    dao.insertSelector(2, 1, null, null, null, null, null);
    DbManagerSpecProvider dbManagerSpecProvider = new DbManagerSpecProvider(daoProvider.get(), ENVIRONMENT, new ReloadingResourceGroupConfig());
    ReloadingResourceGroupConfigurationManager manager = new ReloadingResourceGroupConfigurationManager((poolId, listener) -> {
    }, new ReloadingResourceGroupConfig(), dbManagerSpecProvider);
    AtomicBoolean exported = new AtomicBoolean();
    InternalResourceGroup global = new InternalResourceGroup.RootInternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor(), ignored -> Optional.empty(), rg -> false);
    manager.configure(global, new SelectionContext<>(global.getId(), new VariableMap(ImmutableMap.of("USER", "user"))));
    assertEqualsResourceGroup(global, "1MB", 1000, 100, 100, WEIGHTED, DEFAULT_WEIGHT, true, new Duration(1, HOURS), new Duration(1, DAYS), new ResourceGroupQueryLimits(Optional.of(new Duration(1, HOURS)), Optional.of(new DataSize(1, MEGABYTE)), Optional.of(new Duration(1, HOURS))));
    exported.set(false);
    InternalResourceGroup sub = global.getOrCreateSubGroup("sub", true);
    manager.configure(sub, new SelectionContext<>(sub.getId(), new VariableMap(ImmutableMap.of("USER", "user"))));
    assertEqualsResourceGroup(sub, "2MB", 4, 3, 3, FAIR, 5, false, new Duration(Long.MAX_VALUE, MILLISECONDS), new Duration(Long.MAX_VALUE, MILLISECONDS), NO_LIMITS);
}
Also used : Duration(io.airlift.units.Duration) DbManagerSpecProvider(com.facebook.presto.resourceGroups.db.DbManagerSpecProvider) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) H2DaoProvider(com.facebook.presto.resourceGroups.db.H2DaoProvider) InternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup) VariableMap(com.facebook.presto.resourceGroups.VariableMap) ResourceGroupQueryLimits(com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits) DataSize(io.airlift.units.DataSize) H2ResourceGroupsDao(com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao) Test(org.testng.annotations.Test)

Aggregations

DbManagerSpecProvider (com.facebook.presto.resourceGroups.db.DbManagerSpecProvider)6 H2DaoProvider (com.facebook.presto.resourceGroups.db.H2DaoProvider)6 H2ResourceGroupsDao (com.facebook.presto.resourceGroups.db.H2ResourceGroupsDao)6 Test (org.testng.annotations.Test)6 InternalResourceGroup (com.facebook.presto.execution.resourceGroups.InternalResourceGroup)4 VariableMap (com.facebook.presto.resourceGroups.VariableMap)4 ResourceGroupQueryLimits (com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits)3 DataSize (io.airlift.units.DataSize)3 Duration (io.airlift.units.Duration)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 PrestoException (com.facebook.presto.spi.PrestoException)2 DEFAULT_WEIGHT (com.facebook.presto.execution.resourceGroups.InternalResourceGroup.DEFAULT_WEIGHT)1 DbResourceGroupConfig (com.facebook.presto.resourceGroups.db.DbResourceGroupConfig)1 DbSourceExactMatchSelector (com.facebook.presto.resourceGroups.db.DbSourceExactMatchSelector)1 NO_LIMITS (com.facebook.presto.spi.resourceGroups.ResourceGroupQueryLimits.NO_LIMITS)1 SchedulingPolicy (com.facebook.presto.spi.resourceGroups.SchedulingPolicy)1 FAIR (com.facebook.presto.spi.resourceGroups.SchedulingPolicy.FAIR)1 WEIGHTED (com.facebook.presto.spi.resourceGroups.SchedulingPolicy.WEIGHTED)1 SelectionContext (com.facebook.presto.spi.resourceGroups.SelectionContext)1 ResourceEstimates (com.facebook.presto.spi.session.ResourceEstimates)1