Search in sources :

Example 1 with SelectionContext

use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.

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, "weighted", null, true, "1h", "1d", null);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, null, 5, null, null, null, 1L);
    dao.insertSelector(2, null, null);
    DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager((poolId, listener) -> {
    }, daoProvider.get());
    AtomicBoolean exported = new AtomicBoolean();
    InternalResourceGroup global = new InternalResourceGroup.RootInternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor());
    manager.configure(global, new SelectionContext(true, "user", Optional.empty(), 1));
    assertEqualsResourceGroup(global, "1MB", 1000, 100, WEIGHTED, DEFAULT_WEIGHT, true, new Duration(1, HOURS), new Duration(1, DAYS));
    exported.set(false);
    InternalResourceGroup sub = global.getOrCreateSubGroup("sub");
    manager.configure(sub, new SelectionContext(true, "user", Optional.empty(), 1));
    assertEqualsResourceGroup(sub, "2MB", 4, 3, FAIR, 5, false, new Duration(Long.MAX_VALUE, MILLISECONDS), new Duration(Long.MAX_VALUE, MILLISECONDS));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup) Duration(io.airlift.units.Duration) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext) Test(org.testng.annotations.Test)

Example 2 with SelectionContext

use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.

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, "weighted", null, true, "1h", "1d", null);
    dao.insertResourceGroup(2, "sub", "2MB", 4, 3, null, 5, null, null, null, 1L);
    dao.insertSelector(2, null, null);
    dao.insertResourceGroupsGlobalProperties("cpu_quota_period", "1h");
    DbResourceGroupConfigurationManager manager = new DbResourceGroupConfigurationManager((poolId, listener) -> {
    }, daoProvider.get());
    manager.start();
    AtomicBoolean exported = new AtomicBoolean();
    InternalResourceGroup global = new InternalResourceGroup.RootInternalResourceGroup("global", (group, export) -> exported.set(export), directExecutor());
    manager.configure(global, new SelectionContext(true, "user", Optional.empty(), 1));
    InternalResourceGroup globalSub = global.getOrCreateSubGroup("sub");
    manager.configure(globalSub, new SelectionContext(true, "user", Optional.empty(), 1));
    // Verify record exists
    assertEqualsResourceGroup(globalSub, "2MB", 4, 3, FAIR, 5, false, new Duration(Long.MAX_VALUE, MILLISECONDS), new Duration(Long.MAX_VALUE, MILLISECONDS));
    dao.updateResourceGroup(2, "sub", "3MB", 2, 1, "weighted", 6, true, "1h", "1d", 1L);
    do {
        MILLISECONDS.sleep(500);
    } while (globalSub.getJmxExport() == false);
    // Verify update
    assertEqualsResourceGroup(globalSub, "3MB", 2, 1, WEIGHTED, 6, true, new Duration(1, HOURS), new Duration(1, DAYS));
    // Verify delete
    dao.deleteSelectors(2);
    dao.deleteResourceGroup(2);
    do {
        MILLISECONDS.sleep(500);
    } while (globalSub.getMaxQueuedQueries() != 0 || globalSub.getMaxRunningQueries() != 0);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup) Duration(io.airlift.units.Duration) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext) Test(org.testng.annotations.Test)

Example 3 with SelectionContext

use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.

the class InternalResourceGroupManager method createGroupIfNecessary.

private synchronized void createGroupIfNecessary(ResourceGroupId id, Session session, Executor executor) {
    SelectionContext context = new SelectionContext(session.getIdentity().getPrincipal().isPresent(), session.getUser(), session.getSource(), getQueryPriority(session));
    if (!groups.containsKey(id)) {
        InternalResourceGroup group;
        if (id.getParent().isPresent()) {
            createGroupIfNecessary(id.getParent().get(), session, executor);
            InternalResourceGroup parent = groups.get(id.getParent().get());
            requireNonNull(parent, "parent is null");
            group = parent.getOrCreateSubGroup(id.getLastSegment());
        } else {
            RootInternalResourceGroup root = new RootInternalResourceGroup(id.getSegments().get(0), this::exportGroup, executor);
            group = root;
            rootGroups.add(root);
        }
        configurationManager.get().configure(group, context);
        checkState(groups.put(id, group) == null, "Unexpected existing resource group");
    }
}
Also used : RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) RootInternalResourceGroup(com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext)

Example 4 with SelectionContext

use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.

the class TestFileResourceGroupConfigurationManager method testConfiguration.

@Test
public void testConfiguration() {
    ResourceGroupConfigurationManager manager = parse("resource_groups_config.json");
    ResourceGroup global = new TestingResourceGroup(new ResourceGroupId("global"));
    manager.configure(global, new SelectionContext(true, "user", Optional.empty(), 1));
    assertEquals(global.getSoftMemoryLimit(), new DataSize(1, MEGABYTE));
    assertEquals(global.getSoftCpuLimit(), new Duration(1, HOURS));
    assertEquals(global.getHardCpuLimit(), new Duration(1, DAYS));
    assertEquals(global.getCpuQuotaGenerationMillisPerSecond(), 1000 * 24);
    assertEquals(global.getMaxQueuedQueries(), 1000);
    assertEquals(global.getMaxRunningQueries(), 100);
    assertEquals(global.getSchedulingPolicy(), WEIGHTED);
    assertEquals(global.getSchedulingWeight(), 0);
    assertEquals(global.getJmxExport(), true);
    ResourceGroup sub = new TestingResourceGroup(new ResourceGroupId(new ResourceGroupId("global"), "sub"));
    manager.configure(sub, new SelectionContext(true, "user", Optional.empty(), 1));
    assertEquals(sub.getSoftMemoryLimit(), new DataSize(2, MEGABYTE));
    assertEquals(sub.getMaxRunningQueries(), 3);
    assertEquals(sub.getMaxQueuedQueries(), 4);
    assertEquals(sub.getSchedulingPolicy(), null);
    assertEquals(sub.getSchedulingWeight(), 5);
    assertEquals(sub.getJmxExport(), false);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupConfigurationManager(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManager) DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext) ResourceGroup(com.facebook.presto.spi.resourceGroups.ResourceGroup) Test(org.testng.annotations.Test)

Example 5 with SelectionContext

use of com.facebook.presto.spi.resourceGroups.SelectionContext in project presto by prestodb.

the class TestFileResourceGroupConfigurationManager method testMissing.

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No matching configuration found for: missing")
public void testMissing() {
    ResourceGroupConfigurationManager manager = parse("resource_groups_config.json");
    ResourceGroup missing = new TestingResourceGroup(new ResourceGroupId("missing"));
    manager.configure(missing, new SelectionContext(true, "user", Optional.empty(), 1));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupConfigurationManager(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManager) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext) ResourceGroup(com.facebook.presto.spi.resourceGroups.ResourceGroup) Test(org.testng.annotations.Test)

Aggregations

SelectionContext (com.facebook.presto.spi.resourceGroups.SelectionContext)7 Test (org.testng.annotations.Test)6 InternalResourceGroup (com.facebook.presto.execution.resourceGroups.InternalResourceGroup)3 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)3 Duration (io.airlift.units.Duration)3 ResourceGroup (com.facebook.presto.spi.resourceGroups.ResourceGroup)2 ResourceGroupConfigurationManager (com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManager)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RootInternalResourceGroup (com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup)1 DataSize (io.airlift.units.DataSize)1