use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class QueryStateInfo method createQueryStateInfo.
public static QueryStateInfo createQueryStateInfo(QueryInfo queryInfo, Optional<ResourceGroupId> resourceGroupId, Optional<ResourceGroupInfo> rootResourceGroupInfo) {
List<ResourceGroupInfo> resourceGroups;
if (queryInfo.getState() != QUEUED || !resourceGroupId.isPresent() || !rootResourceGroupInfo.isPresent()) {
resourceGroups = ImmutableList.of();
} else {
ImmutableList.Builder<ResourceGroupInfo> builder = ImmutableList.builder();
ResourceGroupId id = resourceGroupId.get();
ResourceGroupInfo resourceGroupInfo = rootResourceGroupInfo.get();
while (true) {
builder.add(resourceGroupInfo.createSingleNodeInfo());
if (resourceGroupInfo.getSubGroups().isEmpty()) {
break;
}
Optional<ResourceGroupInfo> subGroupInfo = resourceGroupInfo.getSubGroup(id);
checkState(subGroupInfo.isPresent(), "No path from root resource group %s to resource group %s", rootResourceGroupInfo.get().getId(), id);
resourceGroupInfo = subGroupInfo.get();
}
resourceGroups = builder.build().reverse();
}
return new QueryStateInfo(queryInfo.getQueryId(), queryInfo.getState(), resourceGroupId, queryInfo.getQuery(), queryInfo.getSession().getUser(), queryInfo.getSession().getCatalog(), queryInfo.getSession().getSchema(), resourceGroups);
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestQueues method testTooManyQueries.
@Test(timeOut = 240_000)
public void testTooManyQueries() throws Exception {
String dbConfigUrl = getDbConfigUrl();
H2ResourceGroupsDao dao = getDao(dbConfigUrl);
try (DistributedQueryRunner queryRunner = createQueryRunner(dbConfigUrl, dao)) {
QueryId firstDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, firstDashboardQuery, RUNNING);
QueryId secondDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, secondDashboardQuery, QUEUED);
QueryId thirdDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, thirdDashboardQuery, FAILED);
// Allow one more query to run and resubmit third query
dao.updateResourceGroup(3, "user-${USER}", "1MB", 3, 4, null, null, null, null, null, 1L);
dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 2, null, null, null, null, null, 3L);
waitForQueryState(queryRunner, secondDashboardQuery, RUNNING);
thirdDashboardQuery = createQuery(queryRunner, newDashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
// Lower running queries in dashboard resource groups and wait until groups are reconfigured
dao.updateResourceGroup(5, "dashboard-${USER}", "1MB", 1, 1, null, null, null, null, null, 3L);
ResourceGroupManager manager = queryRunner.getCoordinator().getResourceGroupManager().get();
do {
MILLISECONDS.sleep(500);
} while (manager.getResourceGroupInfo(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("global"), "user-user"), "dashboard-user")).getMaxRunningQueries() != 1);
// Cancel query and verify that third query is still queued
cancelQuery(queryRunner, firstDashboardQuery);
waitForQueryState(queryRunner, firstDashboardQuery, FAILED);
MILLISECONDS.sleep(2000);
waitForQueryState(queryRunner, thirdDashboardQuery, QUEUED);
}
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestResourceGroupIntegration method testPathToRoot.
@Test
public void testPathToRoot() throws Exception {
try (DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build()) {
queryRunner.installPlugin(new ResourceGroupManagerPlugin());
InternalResourceGroupManager<?> manager = getResourceGroupManager(queryRunner);
manager.setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json")));
queryRunner.execute(testSessionBuilder().setCatalog("tpch").setSchema("tiny").setSource("dashboard-foo").build(), "SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
List<ResourceGroupInfo> path = manager.getPathToRoot(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("global"), "user-user"), "dashboard-user"));
assertEquals(path.size(), 3);
assertTrue(path.get(1).getSubGroups() != null);
assertEquals(path.get(2).getId(), new ResourceGroupId("global"));
assertEquals(path.get(2).getHardConcurrencyLimit(), 100);
assertEquals(path.get(2).getRunningQueries(), null);
}
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestDistributedQueuesDb method testDistributedQueue.
@Test(timeOut = 60_000)
public void testDistributedQueue() throws Exception {
QueryId firstAdhocQuery = createQuery(queryRunner, 1, adhocSession(), LONG_LASTING_QUERY);
QueryId secondAdhocQuery = createQuery(queryRunner, 1, adhocSession(), LONG_LASTING_QUERY);
QueryId thirdAdhocQuery = createQuery(queryRunner, 0, adhocSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, 1, firstAdhocQuery, RUNNING);
waitForQueryState(queryRunner, 1, secondAdhocQuery, RUNNING);
waitForQueryState(queryRunner, 0, thirdAdhocQuery, RUNNING);
Map<ResourceGroupId, ResourceGroupRuntimeInfo> resourceGroupRuntimeInfoSnapshot;
int globalRunningQueries = 0;
do {
MILLISECONDS.sleep(100);
globalRunningQueries = 0;
for (int coordinator = 0; coordinator < 2; coordinator++) {
resourceGroupRuntimeInfoSnapshot = queryRunner.getCoordinator(coordinator).getResourceGroupManager().get().getResourceGroupRuntimeInfosSnapshot();
ResourceGroupRuntimeInfo resourceGroupRuntimeInfo = resourceGroupRuntimeInfoSnapshot.get(new ResourceGroupId("global"));
if (resourceGroupRuntimeInfo != null) {
globalRunningQueries += resourceGroupRuntimeInfo.getDescendantRunningQueries();
}
}
} while (globalRunningQueries != 3);
QueryId firstDashboardQuery = createQuery(queryRunner, 0, dashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, 0, firstDashboardQuery, QUEUED);
cancelQuery(queryRunner, 0, thirdAdhocQuery);
waitForQueryState(queryRunner, 0, firstDashboardQuery, RUNNING);
}
use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.
the class TestDistributedQueuesDb method testMultiResourceGroupConcurrencyThreshold.
@Test(timeOut = 60_000)
public void testMultiResourceGroupConcurrencyThreshold() throws Exception {
QueryId firstAdhocQuery = createQuery(queryRunner, 1, adhocSession(), LONG_LASTING_QUERY);
QueryId secondAdhocQuery = createQuery(queryRunner, 1, adhocSession(), LONG_LASTING_QUERY);
QueryId thirdAdhocQuery = createQuery(queryRunner, 1, adhocSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, 1, firstAdhocQuery, RUNNING);
waitForQueryState(queryRunner, 1, secondAdhocQuery, RUNNING);
waitForQueryState(queryRunner, 1, thirdAdhocQuery, RUNNING);
Map<ResourceGroupId, ResourceGroupRuntimeInfo> resourceGroupRuntimeInfoSnapshot;
int globalRunningQueries = 0;
do {
MILLISECONDS.sleep(100);
resourceGroupRuntimeInfoSnapshot = queryRunner.getCoordinator(0).getResourceGroupManager().get().getResourceGroupRuntimeInfosSnapshot();
ResourceGroupRuntimeInfo resourceGroupRuntimeInfo = resourceGroupRuntimeInfoSnapshot.get(new ResourceGroupId("global"));
if (resourceGroupRuntimeInfo != null) {
globalRunningQueries = resourceGroupRuntimeInfo.getDescendantRunningQueries();
}
} while (globalRunningQueries != 3);
QueryId firstDashboardQuery = createQuery(queryRunner, 0, dashboardSession(), LONG_LASTING_QUERY);
waitForQueryState(queryRunner, 0, firstDashboardQuery, QUEUED);
cancelQuery(queryRunner, 1, firstAdhocQuery);
waitForQueryState(queryRunner, 0, firstDashboardQuery, RUNNING);
}
Aggregations